Вход Регистрация
Файл: backup_fzrf 2/templates/Old/js/js_tois.js
Строк: 7154
<?php
try{ window.jsProfiler && jsProfiler.loaded(); }catch(e){}

/* jsProfiler */

if (window.jsProfiler && window.performance && browser.chrome) (function(){
  $(
window).load(function(){
    
setTimeout(function(){
      var 
jsProfiler.arrperformance.timing'timing/';
      
a['domainLookup'] = (t.domainLookupEnd t.domainLookupStart) || 0;
      
a['request'] = (t.responseStart t.requestStart) || 0;
      
a['response'] = (t.responseEnd t.responseStart) || 0;
      
a['domReady'] = (t.domContentLoadedEventEnd t.navigationStart) || 0;
      
a['load'] = ((t.loadEventEnd || t.loadEventStart) - t.navigationStart) || 0;
      
a['connect'] = (t.connectEnd t.connectStart) || 0;
    }, 
0);
  });
})();

/**
Nav Module.
version 2.0
02.10.2012
*/
if ($.browser.msie && $.browser.version 10) {

  
window.__state 0;

  
history.pushState history.replaceState = function(statetitlehref){
    
window.__state += 1;
    var 
nav2.get_location(href);
    
location.hash '#!' l.pathname l.search;
  };

  
history.replaceState = function(statetitlehref){
    
window.__state += 1;
    var 
nav2.get_location(href);
    
location.replace(nav2._location.pathname nav2._location.search '#!' l.pathname l.search);
  };

  
window.onhashchange = function(){
    if (
window.__state 0) {
      
window.__state -= 1;
      return;
    }
    
window.__state 0;
    
nav2.go(location.href, { statenull });
  };

}

// nav2

var nav2 = (function(nav2undefined){
  
nav2.supported window.history && history.pushState && history.replaceState && !navigator.userAgent.match(/((iPod|iPhone|iPad).+bOSs+[1-4]|WebApps/.+CFNetwork)/);

  
nav2.opts = {};
  
nav2.eventer = new Eventer({ eventPrefix'' });

  
nav2.subnav = function(opts){

    if (!
opts.checkopts.check = function(fromto){
      return 
nav2.in_map(opts.mapfrom.pathname) && nav2.in_map(opts.mapto.pathname);
    };

    
nav2.opts[opts.name] = opts;

  };

  
nav2.go = function(eleopts){
    var 
to nav2.get_location(el), name 'main'self nav2.opts[name];
    if (
      (!
window.inited) || // page inited
      
(typeof el == 'object' && el.target) || // open links with target attr
      
(&& checkEvent(e)) || // check event
      
(!nav2.supported) || // is supported
      
(nav2.long_request) || // long request
      
(nav2.location.protocol !== to.protocol || nav2.location.hostname !== to.hostname) || // ignore cross origin links
      
(nav2.location.pathname == to.pathname && nav2.location.search == to.search && to.hash) || // ignore hashchange
      
(!self.check(nav2.locationto)) || // check location
      
(!window.currentUser || !currentUser.userId// check current user
    
) {
      
// stat
      
if (nav2.long_requestnav2.stat('pageload_long_request_tmp');

      
// proceed
      
if (!&& to.href !== undefinedlocation.href to.href;
      return;
    }

    
// prevent default for links
    
if (&& e.state === undefinedpd(e);

    
// is locked
    
if (nav2.lock) return;

    if (((
&& e.state !== undefined) || (opts && opts.back)) && flashback.check(to.href)) {
      if(
opts && opts.popstate == true){
        
safe_call('nav2 contextNav back', function(){ contextNav.clear('this_url') });
      }
      
extDebugLog.push({type'flashback'datafalse});
      
nav2.flashback(to.hrefeopts);
    } else {
      
extDebugLog.push({type'ajax'datafalse});
      
nav2.ajax(to.hrefeoptsnav2.in_map(self.new_mapto.pathname));
    }

    return 
true;
  };

  
nav2.reload = function(){
    
nav2.go(nav2.location.pathname nav2.location.search);
  }

  
nav2.flashback = function(hrefe){
    var 
opts flashback.get(href);

    
// lock
    
nav2.lock true;

    
// beforeSend
    
nav2.beforeSend(hrefe);

    
setTimeout(function(){

      
// referer
      
nav2.referer null;

      
// state
      
if (!|| e.state === undefined) {
        
nav2.push(hrefopts.title);
      } else {
        
nav2.update(hrefopts.title);
      }

      
// callback
      
nav2.onComplete(opts.content.find('script').remove().end(), nulloptsopts.title);

      
// unlock
      
nav2.lock false;

      
// load
      
flashback.load(href);

    }, 
0);

  };

  
nav2.ajax = function(hrefeoptsinNewMap){
    var 
si setTimeout(function(){
      
nav2.stat('pageload_error_' + (nav2.__load_request 'stat' 'ajax') + '_tmp');
      
nav2.long_request true;
      
Faviconer.stopLoader();
    }, 
10000);
    
nav2.__load_request 0;

    
// lock
    
nav2.lock true;

    
// preloader
    
Faviconer.startLoader();
    
// $('#content-inner').css('opacity', .5);

    // beforeSend
    
nav2.beforeSend(hrefe);

    var 
send inNewMap _ajax.fspost _ajax.post;

    
// send
    
send(href, { _nav}, function(htmlstatusdatatitle){

      
// referer
      
if (!|| e.state === undefined) {
        
nav2.referer = { location: $.extend({}, nav2.location), titledocument.title };
      } else {
        
nav2.referer null;
      }

      
// state
      
if (!|| e.state === undefined) {
        
nav2.push(data.redirect_url || hreftitle);
      } else {
        
nav2.update(data.redirect_url || hreftitle);
      }

      
// callback
      
nav2.onComplete(htmlstatusdatatitle);

      
// unlock
      
nav2.lock false;
      
nav2.long_request false;

      
// pageload
      
clearTimeout(si);

      
// check current location
      
if (nav2.location.href != nav2.get_location(location.href)['href']) nav2.go(location.href, { statenull });

    }, 
truefalse, function(ab){ nav2.error('ajax ' ' (' a.status '): ' href); if (a.status != 0location.href href; }, function(){ nav2.__load_request 1; });

  };

  
nav2.beforeSend = function(hrefe){
    var 
name 'main'self nav2.opts[name];
    
self.beforeSend && safe_call('nav2 beforeSend', function(){ self.beforeSend(hrefe); });
  };

  
nav2.onComplete = function(htmlstatusdatatitle){
    var 
name 'main'self nav2.opts[name];

    
// gc
    
nav2.gc_exec();

    
// callback
    
self.onComplete && safe_call('nav2 onComplete', function(){ self.onComplete(htmlstatusdatatitle); });
  };

  
nav2.push = function(hreftitle){
    var 
to nav2.get_location(href);
    if (!
nav2.supported || nav2.location.href == to.href) return;

    
history.pushState(nulltitle || ''to.href);
    
nav2.update(to.hreftitle);
  };

  
nav2.replace = function(hreftitle){
    var 
to nav2.get_location(href);
    if (!
nav2.supported || nav2.location.href == to.href) return;

    
history.replaceState(nulltitle || document.titleto.href);
    
nav2.update(to.hreftitle);
  };

  
nav2.update = function(hreftitle){
    if (
titledocument.title htmlspecialchars_decode(title);
    
nav2.location nav2.get_location(href);
  };

  
nav2.in_map = function(mappathname){
    for (var 
0map.lengthl+= 1) if (typeof map[i] == 'string' pathname == map[i] : map[i].test(pathname)) return true;
    return 
false;
  };

  
// stat

  
nav2.stat = function(name){
    if (
window.currentUser && (currentUser.userId 100 4)) (new _jstat('Analytics')).add(name1).send();
  };

  
// gc

  
nav2.gc_cache = {};
  
nav2.gc_queue = [];

  
nav2.gc = function(fnname){
    if (
name) {
      if (
nav2.gc_cache[name] !== undefinednav2.gc_queue[nav2.gc_cache[name]] = null;
      
nav2.gc_cache[name] = nav2.gc_queue.length;
    }
    
nav2.gc_queue.push(fn);
  };

  
nav2.gc_exec = function(){
    for (var 
nav2.gc_queuea.length 1>= 0-= 1a[i] && safe_call('nav2 gc'a[i]);

    
nav2.gc_cache = {};
    
nav2.gc_queue = [];
  };

  
// location

  
nav2.get_location = (function(al){
    return function(
el){
      if (
typeof el == 'string') {
        
a.href el;
      } else if (
el && el.href) {
        
a.href el.href;
      } else return {};

      if (
a.hash.substr(02) == '#!'a.href a.hash.substring(2);

      var 
protocol a.protocol && a.protocol != ':' a.protocol l.protocol,
          
hostname a.hostname || l.hostname,
          
pathname a.pathname.replace(/^/?/, '/').replace(//?$/, '/'),
          
search a.search,
          
hash =  a.hash || (a.href.charAt(a.href.length 1) == '#' '#' '');

      return {
        
protocolprotocol,
        
hostnamehostname,
        
pathnamepathname,
        
searchsearch,
        
hashhash,
        
href:  protocol '//' hostname pathname search hash
      
};
    }
  })(
document.createElement('a'), { protocollocation.protocolhostnamelocation.hostname });

  
nav2.location nav2._location nav2.get_location(location.href);

  
// query params

  
nav2.getParam = function(name){
    return 
q2obj(nav2.location.search.substring(1))[name];
  };

  
nav2.setParam = function(namevaluepushToHistory){
    var 
q2obj(nav2.location.search.substring(1)), loc nav2.location;

    if (
typeof name == 'string') {
      if (
value === false) {
        
delete q[name];
      } else {
        
q[name] = value;
      }
    } else {
      $.
extend(qname);
    }

    
nav2.eventer.emit('setParam', {urlloc.pathname '?' obj2q(q) + loc.hash});
    
nav2[pushToHistory 'push' 'replace' ](loc.pathname '?' obj2q(q) + loc.hash);
  };

  
nav2.deleteParam = function(namepushToHistory){
    
nav2.setParam(namefalsepushToHistory);
  };

  
// error

  
nav2.error = function(msg){
    
debugLog('nav2 ' msg);
  };

  return 
nav2;

})({});

$(
window).bind('popstate', function(e){
  
nav2.go(location.hash.substr(02) == '#!' location.hash.substring(2) : location.hrefe['originalEvent'], {popstatetrue});
});

/* main nav */

nav2.subnav({
  
name'main',
  
parent'',
  
map: [
    
'/',
    /^/
user/(d+/)?((friends|blog|info)/)?$/,
    /^/
user/d+/albums/$/,
    /^/
user/d+/giftroom/$/,
    /^/
user/d+/album/d+/((photos|settings|comments)/)?(d+/)?$/,
    /^/
user/d+/board/d+/$/,
    /^/
d+/$/,
    /^/
u/[a-zd-]+/$/i,
    /^/
pacman/(apps|news)//,
    
'/album/new/',
    /^/
partner/offersapp/.*/i,
    /^/
friends//i,
    
/^/userinfo/room//i,
//  /^/app/[a-zd]+/$/i,
    
/^/interest//i,
    
'/usercontact/',
    
'/interests/services/',
    
'/interests/people/',
    
'/interests/favorite/',
    
'/people/',
    
'/people/index/',
    
'/people/main/',
    
'/people/friends/',
    
'/people/dating/',
    
'/people/icu/',
    /^/
people/interests/.*/i,
    
'/profile/',
    
'/meeting/',
    /^/
meeting/index/.*/i,
    /^/
meeting/apps/.*/i,
    
'/meeting/main/',
    
'/meeting/photo/rates/',
    
'/search/',
    
'/leader/',
    
'/community/',
    /^/
community/category/d+/i,
    /^/
community/(my|new|manage)/$/i,
    
'/community/new/',
    /^/public/.*/
i,
    /^/
games//i,
    
/^/meetup//i,
    
'/newyear/',
    /^/
holiday//i,
    
/^/support/feedback//i,
    
/^/support/feedbackv3//i,
    
'/vip/',
    
'/marketplace/sale/',
    
'/bomond/',
    /^/
bomond/index/.*/i,
    /^/
play/.*/i,
    
'/market/springfair/',
    
'/pacman/news/',
    
'/pacman/start/',
    
'/daily/news/',
    
'/daily/news/interest/',
    
'/daily/comments/',
    
'/team/',
    /^/
team/index/.*/i,
    /^/
team/may/.*/i,
    /^/
team/firtree/.*/i,
    
'/about/',
    /^/
about/.*/i,
    /^/
photocontest/.*/i,
    /^/
rating/.*/i,
    /^/
phototags/.*/i,
    /^/
sticker/.*/i,
    /^/
finance/index/.*/i,
    /^/
pets/.*/i,
    /^/
vip/.*/i,
    /^/
ask/.*/i,
    /^/
video2/.*/i,
    /^/
play/feed/(board/)?/i,
    /^/
usernews/feed//i
  
],
  
// if u wanna correct error handling
  
new_map: [
    /^/
user/(d+/)?((friends|blog|info)/)?$/,
    /^/
d+/$/,
    /^/
u/[a-zd-]+/$/i
  
],
  
check: function(fromto){ var nav2.opts.main.map; return ge('content-inner') && nav2.in_map(mfrom.pathname) && nav2.in_map(mto.pathname); },
  
beforeSend: function(hrefe){

    
// flashback
    
flashback.save(nav2.location.href);

    
// scroll
    
if (&& e.state !== undefinedscrollToY(0);

  },
  
onComplete: function(htmlstatusdata){

    
// streamer
    
if (window.streamerstreamer.unsubscribe(~257);

    
//topper
    
if (window.toppertopper.clear();

    
// scrollable
    
scrollable.reset();
    
scrollToY(0);

    
// preloader
    
Faviconer.stopLoader();
    
// $('#content-inner').css('opacity', 1);

    //content
    
$('#node-heap').empty();
    $(
'#content-inner').replaceWith('<div id="content-inner"></div>');
    $(
'#content-inner').html(html);

    
// scroll
    
data.scrollTop && scrollToY(data.scrollTop);

    
// header link
    
$('#header').children().removeClass('on');
    if (
data.active_header_link) $('#header a[rel='data.active_header_link +']').addClass('on');

    
// noty
    
if (data.notynoty.update(data.noty);

    
safe_call('nav2 contextNav'contextNav.refresh);

      
// google analytics
    
if (window._gaq && data.ga_page_link_gaq.push(['_trackPageview'data.ga_page_link]);

    
// last visit ico
    
if (data._last_service){
        if (!
interestsBase.services.visibleServices[data._last_service]) interestsBase.reloadList();
        else 
interestsBase.services.lastVisitIco(data._last_service);
    }

    
// king
    
if(window.king && typeof(data._trgt_sid) !== 'undefined'king.rotator.sid data._trgt_sid;
    if (
window.king && king.rotator.hasOwnProperty('timing') && fsNow() - king.rotator.timing 2000) {
      
king.rotator.timing fsNow();
      
king.rotator.multiRenew();
    }

    
// CPAE
    
window.CPAE && CPAE.check();

    
// LI counter
    
(new Image()).src "http://counter.yadro.ru/hit;fotostrana?r"+escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";"+Math.random();

  }
});

if (
window.isOurIp) {
    
nav2.opts.main.map.push('/contest/')
}

$(
document).click(function(e){
  var 
target e.target;
  
extDebugAddClick(target);
  if (
target.nodeName.toLowerCase() == 'a' || (target = $(target).closest('a')[0])) nav2.go(targete.originalEvent);
});

/**
Flashback Module.
version 2.6
05.04.2013
*/
var flashback = function(opts){
  
flashback.__opts = $.extend({}, opts);
};

(function(
fb){

  
fb.queue = [];
  
fb.queue_limit 5;

  
fb.save = function(href){

    if (!
flashback.__opts) return;

    for (var 
0opts flashback.__optsflashback.queuea.lengthl+= 1) if (a[i].href == href) {
      
a.splice(i1);
      break;
    }

    if (
fb.queue_limit == a.lengtha.shift();

    
opts.title document.title;
    
opts.href href;
    
opts.data = {};
    if (
scrollable.stack.length 1) {
        
// If something is overlaying the main content, we need to save content-wrap offset instead of scrollTop value
        
opts.scrollTop = -parseInt($('#container-wrap').css('top'));
    } else {
        
opts.scrollTop fs.scrollTop;
    }
    
opts.active_header_link = $('#header').children().filter('.on').attr('rel');
    
opts.content = $('#content-inner');

    
a.push(opts);

    
safe_call('flashback - save', function(){
      
opts.save && opts.save(opts.data);
    });

    
flashback.__opts null;

  };

  
fb.load = function(href){
    var 
opts fb.get(href);

    
safe_call('flashback - load', function(){
      
opts.load && opts.load(opts.data);
    });
  };

  
fb.indexOf = function(href){
    for (var 
0flashback.queuea.lengthl+= 1) if (a[i].href == href) return i;
    return -
1;
  };

  
fb.get = function(href){
    var 
idx fb.indexOf(href);
    return 
idx false fb.queue[idx];
  };

  
fb.check = function(href){
    return 
fb.indexOf(href) >= 0;
  };

})(
flashback);

/* noty module 2.0 */

var noty = (function(noty){

  
noty.notifi = {};
  
noty.time_limit 30000;

  
noty.update = function(notifi){

    if (
notifi) {
      
noty.last_update fsNow();
      for (var 
i in notifinoty.setCounter(inotifi[i]);
    } else {
      if (
fsNow() - noty.last_update noty.time_limit) {
        
clearTimeout(noty.si);
        
noty.si setTimeout(function(){ noty.update(); }, noty.time_limit - (fsNow() - noty.last_update));
      } else {
        
clearTimeout(noty.si);
        $.
getJSON('/pacman/ajax/getCounters/', function(data){
          if (!
data || !data.ret || !data.noty) return;
          
noty.update(data.noty);
        });
      }
    }

  };

  
noty.getCounter = function(name){
    var 
parseInt(noty.notifi[name]);
    return (
isNaN(c) ? parseInt($('.noty-' name).html()) : c) || 0;
  };

  
noty.setCounter = function(namecountopts){
    var 
parseInt(count) || 0;
    
noty.notifi[name] = = (c);

    $(
'.noty-' name).html(? (100 '99+') : 0)[('add' 'remove') + 'Class']('on');
    if (
opts && opts.global) lc('noty', { action'setCounter'namenamecountcount });
  };

  
noty.addToCounter = function(namecountopts){

    var 
parseInt(count) || 0prefix name.split('_')[0];
    if (!
c) return;

    if (
name != prefixnoty.addToCounter(prefixc);
    
noty.setCounter(namenoty.getCounter(name) + c);

    if (
opts && opts.global) lc('noty', { action'addToCounter'namenamecountcount });
  };

  
noty.onreceive = function(data){
    if (!
data || !data.action || !data.name || !noty[data.action]) return;
    
noty[data.action](data.namedata.count);
  };

  return 
noty;

})({});

/* title module 1.3 */

var titles = new function () {
    var 
self this;

    
self.onreceive = function (data) {
        if (
data && data.action && self[data.action]) self[data.action](data.data);
    };

    
self.rotate = function (titlefavicon) {
        var 
data = {
            
titletitle,
            
faviconvoid 0 == favicon  'default' favicon
        
};

        
self._lc('titles', { action'_rotate'datadata });
    };

    
self.reset = function () {
        
self._lc('titles', { action'_reset'datatrue });
    };

    
self._lc = function (callbackdata) {
        if (
lc.supported && !streamer.is_serverlc(callbackdata);
        
self[data.action](data.data);
    };

    
self._rotate = function (data) {
        if (!
self._titleself._title document.title;
        if (!
self._faviconself._favicon 'default';

        
self._newTitle data.title;
        
self._newFavicon data.favicon;

        
self._rotator();
    };

    
self._rotator = function () {
        if (!
self._rotating) {
            
self._rotating true;

            if (
self._newTitle && self._title && self._favicon && self._newFavicon) {
                
document.title = (self._title == document.title self._newTitle self._title);
                
self._favicon = (self._favicon == 'default' self._newFavicon 'default');
                
Faviconer.setFavIcon(self._favicon);
            }

            
clearTimeout(self._timeout);
            
self._timeout st(function () {
                
self._rotating false;
                
self._rotator();
            }, 
1001);
        }
    };

    
self._reset = function () {
        if (!
self._resetting) {
            
self._resetting true;

            
st(function () {
                if (
self._titledocument.title self._title;
                if (
self._timeoutclearTimeout(self._timeout);

                
self._rotating false;
                
self._favicon 'default';
                
Faviconer.setFavIcon(self._favicon);

                
st(function () {
                    
self._resetting false;
                }, 
1001);
            }, 
1001);
        }
    };
};

/* sounds module 1.1 */

var sounds = new function(){

  var 
sounds this;

  
sounds.enable = function(force){
    if (!
forcelc('sounds', { action'enable'datatrue });
    
sounds.enabled true;
  };

  
sounds.disable = function(force){
    if (!
forcelc('sounds', { action'disable'datatrue });
    
sounds.enabled false;
  };

  
sounds.onreceive = function(data){
    if (
data && data.action && sounds[data.action]) sounds[data.action](data.data);
  };

  
sounds.play = function(opts){
    if (!
lc.supported || streamer.is_server) {
      
sounds._play(opts);
    } else {
      
lc('sounds', { action'_play'dataopts });
    }
  };

  
sounds._play = function(opts){
    if ((
typeof lc != 'undefined' && lc.supported && !streamer.is_server) || !sounds.inited || !sounds.enabled || fsNow() - (sounds.time || 0) < 5000) return;
    
sounds.time fsNow();
    try {
      
ge('soundsSWF').play('noty');
    } catch(
e) { setTimeout(function(){if(ge('soundsSWF').play) {ge('soundsSWF').play('noty');} }, 200); }
  };

  $(
window).load(function(){
    $(
'#system_service').append('<div id="soundsSWF"></div>');
    
swfobject.embedSWFwindow.staticDomain '/swf/sounds.swf?2''soundsSWF''10''10''10.0.0'staticDomain '/swf/expressInstall.swf', {}, { menu'false'wmode'window'allowScriptAccess'always' }, {}, function(e){ if (&& e.successsounds.inited truesounds._play(); } );
  });

};

/* streamer handler */

if (window.streamerstreamer.subscribe('main', function(typedata){
  if (
type == 'pacman') {
    if (
data.apps) {
      for (var 
app_id in data.apps) {
        
noty.addToCounter('pacman_' app_iddata.apps[app_id]);
      }
    } else {
      
noty.addToCounter('pacman_' data.app_iddata.app_count);
    }
  }

  if (
type == 'newfriends'noty.addToCounter('friends'1);
  if (
type == 'friendsaccept' || type == 'friendsdecline'noty.addToCounter('friends', -1);
  if (
type == 'news' || type == 'newguests' || type == 'newlikes') {
      
noty.update();
  }

  
// usercontact
  
if (type == 'newmsg') {
      if (!
window.usercontact || !usercontact.socket.connected) {
        
noty.addToCounter('mess_u' data.author_id1);
        
streamer.is_server && sounds.play();
      }
  }
  if (
type == 'usercontact_chat') {
    if (!
window.usercontact || !usercontact.socket.connected) {
      if (
data && data.event == 'read'noty.addToCounter('mess_u' data.to, -data.count);
    }
  }

  if (
type == 'url_parser') {
    if (
window.fsPin && fsPin.currentParseTaskId == data.task) {
        
fsPin._parseCompleteCallback(data);
    }
    if(
typeof messageFormEventer !== 'undefined'){
        
messageFormEventer.emit('parseComplete'data);
    }
  }
  if (
type == 'adventures') {
      if(
window.isOurIpconsole.log(data);
  }
});

/* scrollable block */

var scrollable = function(opts){
  
scrollable.opts[opts.name] = opts;
  if (!
scrollable.stack.lengthscrollable.stack.push(opts.name);
};

(function(
scrollable){

    
scrollable.opts = {};
    
scrollable.stack = [];

    
scrollable.push = function(name){
        var 
stack scrollable.stackopts scrollable.optsbelow opts[stack[stack.length 1]], push opts[name];
        if(
push.isUnique){
            for(var 
i in stack){
                if(
stack[i] == name){
                    
below.onbelow.apply(below, []);
                    
stack.splice(i1);
                    
stack.push(name);
                    
push.onover();
                    return;
                }
            }
        }
        
below.onbelow.apply(below, []);
        
scrollToY(0);
        
push.onpush && push.onpush.apply(push, []);
        
stack.push(name);
    };

    
scrollable.pop = function(uid){
        var 
stack scrollable.stack,
            
opts scrollable.optspopoveri;
        if(
uid && typeof opts[uid] !== 'undefined'){
            
pop opts[uid];
            for(
i=0i<stack.lengthi++){
                if(
stack[i] == uid){
                    if(
stack.length-1){
                        
stack stack.splice(i1);
                        
pop.onpop && pop.onpop.apply(pop, []);
                        return 
true;
                    }
                }
            }
        }

        
pop opts[stack[stack.length 1]];
        
over opts[stack[stack.length - (stack.length 1)]];
        
pop.onpop && pop.onpop.apply(pop, []);
        
scrollToY(0);
        if (
stack.length 1stack.pop();
        
over.onover.apply(over, []);
    };

  
scrollable.reset = function(){
    for (var 
0scrollable.stack.length 1l+= 1scrollable.pop();
  };

  
window.ffScrollableFlashHack = $.browser.mozilla && parseInt($.browser.version) < 13// нужен ли костыль для флеша в FF младше 13-й версии
  
scrollable({
    
name'container-wrap',
    
onpop: function(){},
    
onpush: function(){},
    
onbelow: function(){
      var 
appNeedHide typeof appHideRequired !== 'undefined' && appHideRequired && typeof hideApp == 'function';
      if (!
ffScrollableFlashHack || !appNeedHide) {
        $(
'#' this.name).addClass('fixed').css('top', -fs.scrollTop);
      }
      
topper.destroy();
      if(
appNeedHide)
        
hideApp();
    },
    
onover: function(){
        var 
= $('#' this.name),
          
top t.css('top');
      
topper.init();
      var 
appNeedHide typeof appHideRequired !== 'undefined' && appHideRequired && typeof hideApp == 'function';
      if (!
ffScrollableFlashHack || !appNeedHide) {
        
t.removeClass('fixed').css('top'0);
      }
      if(
appNeedHide)
        
showApp();
      
scrollToY(-parseInt(top));
    }
  });

})(
scrollable);

/* friendship */

var friendship = (function(friendship){

  
friendship.get = function(urlidcallbackopts) {
    var 
params = {
      
friendIdid,
      
'ftoken-all'window.fsft
    
};
    $.
extend(paramsopts)

    $.
getJSON(urlparams, function(response) {
      if (
response && response.error && response.error == 'ignor') {
        
iPopup.confirm(response.html, $.extend(true, [{
          
title'Отмена',
          
defaultEntertrue,
          
myclass''
        
}, {
          
title'Убрать и продолжить',
          
myclass'btn-blue',
          
callback: function() {
            
delFromBlacklist(idnull, function() {
              $(
'#profile-blacklist-add').removeClass('d-n');
              $(
'#profile-blacklist-del').addClass('d-n');

              
friendship.get(urlidcallbackopts);
            });
          }
        }]), {
onclose: function() {
          
response.html '';
          
callback && callback(response);
        }});
        return;
      }

      
callback && callback(response);
    });
  };

  
friendship.request = function(idcallbackopts) {
    
friendship.get('/usercontact/backend/friendshipRequest/'idcallbackopts);
  };

  
friendship.cancel = function(idcallbackopts) {
    
friendship.get('/usercontact/backend/friendshipCancel/'idcallbackopts);
  };

  
friendship.revoke = function(idcallbackopts) {
    
friendship.get('/usercontact/backend/friendshipRequestRevoke/'idcallbackopts);
  };

  
friendship.confirm = function(idcallbackopts) {
    
friendship.get('/usercontact/backend/friendshipRequestConfirm/'idcallbackopts);
  };

  
friendship.refuse = function(idcallbackopts) {
    
friendship.get('/usercontact/backend/friendshipRequestRefuse/'idcallbackopts);
  };

  return 
friendship;

})({});

var 
interestsBase = {
    
ajaxProcessedfalse,
    
services: {
        
visibleServices: {},
        
ajaxParams: function (targetIdparams) {
            return $.
extend({}, { isAjax1appIdtargetId }, params);
        },
        
settingsWasOpened : function(params) {
            $.
get('/interests/services/settingsMenuWasOpened/'this.ajaxParams(0params));
        },
        
hideService: function(eltargetIdparams) {
            if (
interestsBase.ajaxProcessed) {
                return;
            }
            
interestsBase.ajaxProcessed true;

            $.
get('/interests/services/hideServiceFromList/'this.ajaxParams(targetIdparams), function(res){
                
interestsBase.ajaxProcessed false;

                if (
res.ret != 1) {
                    
fs.notify(res.message);
                    return;
                }

                
el = $(el).parents('.interest-item');
                
el.addClass('h');
                
el.remove();

                
//TODO:Скрывать элемент из основного (центрального) списка

                
interestsBase.reloadList();
            }, 
'JSON');
        },
        
toggleFavorite: function(eltargetIdparams) {
            if ($(
el).hasClass('favorite')) {
                
this.removeFromFavorite(eltargetIdparams);
            } else {
                
this.addToFavorite(eltargetIdparams);
            }
        },
        
addToFavorite: function(eltargetIdparams) {
            if (
interestsBase.ajaxProcessed) {
                return;
            }
            
interestsBase.ajaxProcessed true;

            $.
get('/interests/services/addToFavorite/'this.ajaxParams(targetIdparams), function(res){
                
interestsBase.ajaxProcessed false;

                if (
res.ret != 1) {
                    
fs.notify(res.message);
                    return;
                }

                
el = $(el);
                
el.html('Убрать из избранного');
                
el.addClass('favorite');

                
//TODO:Добавить элемент в избранное основного (центрального) списка

                // Перегрузить лист
                
interestsBase.reloadList();
            }, 
'JSON');
        },
        
removeFromFavorite: function(eltargetIdparams) {
            if (
interestsBase.ajaxProcessed) {
                return;
            }
            
interestsBase.ajaxProcessed true;

            $.
get('/interests/services/removeFromFavorite/'this.ajaxParams(targetIdparams), function(res){
                
interestsBase.ajaxProcessed false;

                if (
res.ret != 1) {
                    
fs.notify(res.message);
                    return;
                }

                
el = $(el);
                
el.html('Добавить в избранное');
                
el.removeClass('favorite');

                
//TODO:Удалить элемент из избранное основного (центрального) списка

                // Перегрузить лист
                
interestsBase.reloadList();
            }, 
'JSON');
        },
        
settingsNotAvailable: function () {
            
iPopup.alert('Временно недоступно.');
        },
        
hidePromo: function(appUid){
            $.
get('/interests/services/hidepromo/'this.ajaxParams(appUid), function(){
                $(
'#interests-promo').slideUp();
            });
        },
        
lastVisitIco: function(serviceStr){
            var list = $(
'#side-service');
            var 
ico = $('.interest-item .item-lastvisit-icon', list);
            if (!
ico.length){
                return 
interestsBase.reloadList();
            }
            var 
item = $('#interest-item-' serviceStr, list);
            if ($(
'.item-fav-icon'item).length){
                
ico.remove();
            } else {
                $(
'a'item).prepend(ico);
            }
        }
    },
    
people: {
        
settingsWasOpened: function() {
            $.
get('/interests/people/settingsmenuwasopened/', {isAjax1});
        },

        
addToFavorite: function(eltargetIdsource) {
            if (
interestsBase.ajaxProcessed) {
                return;
            }
            
interestsBase.ajaxProcessed true;

            
el = $(el);
            var 
parent el.parents('.interest-item');

            
el.addClass('h');
            
parent.find('.people-fav-del').removeClass('h');

            
addToFavorite(targetIdel, function(resitem) {
                
item = $(item);
                if (!
res || res.ret != 1) {
                    
// что-то не так - возвращаем обратно
                    
item.removeClass('h');
                    
parent.find('.people-fav-del').addClass('h');
                }
                
interestsBase.ajaxProcessed false;
            }, 
source);
        },
        
removeFromFavorite: function(eltargetIdsource) {
            if (
interestsBase.ajaxProcessed) {
                return;
            }
            
interestsBase.ajaxProcessed true;

            
el = $(el);
            var 
parent el.parents('.interest-item');

            
el.addClass('h');
            
parent.find('.people-fav-add').removeClass('h');

            
delFromFavorite(targetIdel, function(resitem) {
                
item = $(item);
                if (!
res || res.ret != 1) {
                    
// что-то не так - возвращаем обратно иконку и текст
                    
item.removeClass('h');
                    
parent.find('.people-fav-add').addClass('h');
                }
                
interestsBase.ajaxProcessed false;
            }, 
source);
        },
        
hideUser: function(eltargetId) {
            if (
interestsBase.ajaxProcessed) {
                return;
            }
            
interestsBase.ajaxProcessed true;

            
el = $(el);

            var 
parent el.parents('.interest-item');
            var 
ajaxParams = {
                
isAjax1,
                
targetIdtargetId,
                
fromLeftBlock1
            
};

            
parent.addClass('h');

            $.
get('/interests/people/hideuserfromlist/'ajaxParams, function(res){
                
interestsBase.ajaxProcessed false;
                if (!
res || res.ret != 1) {
                    
// что-то не так - возвращаем обратно иконку и текст
                    
parent.removeClass('h');
                } else {
                    
parent.remove();
                    
interestsBase.reloadList();
                }
            }, 
'JSON');
        },
        
manageHiddenPeople: function (opts) {
            return 
peopleManagePopup($.extend({
                
title'Выберите людей',
                
myclass'list-manage-popup people-manage-popup interest-people-manage-popup font-large',
                
listTitles: ['Все интересные люди''Скрытые люди'],
                
emptyMessages: ['Список пуст.''Вы можете выбрать людей, которых хотите скрыть. Они больше не будут выводиться в блоке и на странице Интересные мне люди.'],
                
loadAjaxUrl'/UsersManager/InterestsPeople/getPopup/',
                
saveAjaxUrl'/UsersManager/InterestsPeople/savePopup/',
                
onSaveSuccess: function (res) {
                    if (
this.isChanged()) {
                        if (
window.interestPeople && interestPeople.isViewingPage) {
                            
interestPeople.appendToList(interestPeople.listViewtrue);
                        }
                        
interestsBase.reloadList();
                    }

                    
listManagePopup.prototype.onSaveSuccess.call(thisres);
                },
                
saveAjaxParams: function () {
                    return $.
extend({
                        
refthis.ref
                    
}, listManagePopup.prototype.saveAjaxParams.apply(thisarguments));
                },
                
loadAjaxParams: function () {
                    return $.
extend({
                        
refthis.ref
                    
}, listManagePopup.prototype.loadAjaxParams.apply(thisarguments));
                }
            }, 
opts));
        }
    },
    
reloadList: function() {
        if (
interestsBase.ajaxProcessed) {
            return;
        }
        
interestsBase.ajaxProcessed true;
        $.
get('/interests/index/reloadLeftBlock/', {isAjax1}, function(res){
            
interestsBase.ajaxProcessed false;
            if (
res && res.ret == 1) {
                var 
peopleBlock = $('#side-people');
                var 
servicesBlock = $('#side-service');
                var 
scrollBlock = $('#side-scroll');
                if (
peopleBlock.size() > 0) {
                    
servicesBlock.remove();
                    if (
scrollBlock.size() > 0) {
                      
scrollBlock.remove();
                    }
                    
peopleBlock.replaceWith(res.html);
                } else if (
servicesBlock.size() > 0) {
                    
peopleBlock.remove();
                    if (
scrollBlock.size() > 0) {
                      
scrollBlock.remove();
                    }
                    
servicesBlock.replaceWith(res.html);
                }
            }
        }, 
'JSON');
    }
};

/* search module 2.0 */

var fsSearch = function(idopts){
  var 
self this;
  
self.wrap = $('#' id);
  
self.input self.wrap.find('input');
  
self.search_val self.input.val();
  $.
extend(selfopts);

  
self.input.bind('keydown', function(event){ self.onkeydown(event) });
};

(function(
searchproto){

  
proto.onkeydown = function(event){
    var 
self this;
    if (
event.keyCode == 27) {
      
self.input.blur();
      
self.cancel();
      return;
    }
    
clearTimeout(self.ti);
    
self.ti setTimeout(function(){ self.update(); }, 10);
  };

  
proto.val = function(value){
    if (
value === undefined) return trim(this.input.val());
    
this.input.val(value);
  };

  
proto.update = function(force){
    var 
self thisval self.val();

    if (
val) {
      
self.wrap.addClass('process').addClass('filled');
    } else {
      
self.cancel();
      return;
    }

    if (!
force) {
      if (
self.search_temp_val != val) {
        
self.search_temp_val val;
        
clearTimeout(self.ti);
        
self.ti setTimeout(function(){ self.update(); }, 500);
      } else {
        
self.search_temp_val '';
        
self.update(true);
      }
      return;
    }

    if (
self.search_val == val) {
      
self.wrap.removeClass('process');
    } else {
      
self.search_val val;
      
self.onsearch && self.onsearch(val);
    }

  };

  
proto.cancel = function(){
    var 
self this;
    
self.search_val '';
    
self.val('');
    
self.wrap.removeClass('filled').removeClass('process');
    
clearTimeout(self.ti);

    
self.oncancel && self.oncancel();
  };

})(
fsSearchfsSearch.prototype);

/* ddb */

var ddb = (function(ddb){
    var 
ddbTimerOpen 0,
        
ddbTimerElClose = {};
    
ddb.onclick = function(elevent){
        $(
el).toggleClass('open-menu');
    };
    
ddb.onmouseleave = function(eleventopts){
        
opts = $.extend({
          
timeout300
        
}, opts);
        
clearTimeout(ddbTimerOpen);
        var 
ddbcid =  Math.floor(Math.random() * 1000000);
        $(
el).data('ddbcid'ddbcid);

        
ddbTimerElClose[ddbcid] = st(function() {
            $(
el).removeClass('open-menu');
        }, 
opts.timeout);
    };
    
ddb.onmouseenter = function(elevent){
        var 
ddbcid = $(el).data('ddbcid') || 0;
        if (
ddbTimerElClose[ddbcid]) {
          
clearTimeout(ddbTimerElClose[ddbcid]);
        }
    };
    
ddb.openOnHover = function(eleventtimeout){
        var 
ddbcid = $(el).data('ddbcid') || 0;
        if (
ddbTimerElClose[ddbcid]) {
          
clearTimeout(ddbTimerElClose[ddbcid]);
        }
        var 
ddbTimerOpen setTimeout(function(){
            $(
el).addClass('open-menu');
        }, 
timeout);
    };
    return 
ddb;
})({});

function 
Scroller(params){
    var 
onScroll = {},
        
scrollTo = {},
        
offset 200,
        
me = {};
    var 
init = function(paramsscope){
        
me scope;
        
me.uuid = ++Scroller.uuid;

        if(
params.selector){
            
me.elem = $(params.selector);
            
me.scrollTop = function(){ return me.elem.scrollTop(); };
            
me.height = function(){ return me.elem.height(); };
        } else {
            
me.elem = $(window);
            
me.scrollTop = function(){ return fs.scrollTop };
            
me.height = function() { return fs.windowH; };
            
// if ie
        
}

        if(
params.offset)
            
offset params.offset;

        if(
params.scrollTo){
            
scrollTo = $(params.scrollTo);
            
scrollTo.myScroll = function(){ return scrollTo.offset().top };
        } else {
            if(
params.selector)
                
scrollTo.myScroll = function(){ return me.elem[0].scrollHeight;};
            else
                
scrollTo.myScroll = function(){ return document.documentElement.scrollHeight};
        }

        if(
params.onScroll) {
            
onScroll = function() {
                if( 
scrollTo.myScroll() - (me.scrollTop() + me.height())  < offset )
                    
params.onScroll(me);
            };
            
me.elem.bind('scroll.scroller'+me.uuid, function(){
                if(!
window.lockScrollerme.onScrollTimer setTimeout(onScroll0); // hack для того, чтобы в Хроме бралось актуальное значение scrollTop
            
});
            $(
onScroll);
        } else {
            return 
false;
        }

        
nav2.gc(function(){ me.destroy(); });
        return 
me;
    };

    return 
init(paramsthis);
}

(function(
Scrollerproto){
    
Scroller.uuid 0;

    
proto.destroy = function(){
        
clearTimeout(this.onScrollTimer);
        
this.elem.unbind('scroll.scroller'+this.uuid);
    };
})(
ScrollerScroller.prototype);

var 
showPhotoInitLock false;
function 
showPhoto(eleventcallback){
    if(
checkEvent(event)){
        return;
    } else {
        
cancelEvent(event);
    }
    var 
th = $(el);
    if(!
showPhotoInitLock) {
        
showPhotoInitLock true;
        
_ajax.get('/userphoto/ajax/showFsimp/', {}, function(htmlstatusdata){
            if (
data.state == 1) {
                
showUploadMainPhotoPopup();
                
showPhotoInitLock false;
            } else {
                $(
'body').append(data.html);
                
fsimp.imgInit();
                
fsimp.imgShow(thcallback);
            }
        });
        return 
false;
    } else if (
typeof fsimp !== 'undefined') {
        
fsimp.imgShow(thcallback);
    }
}

var 
AnyTooltipStack = [];
var 
AnyTooltipGc = function(){
    if(
AnyTooltipStack.length)
        $.
each(AnyTooltipStack, function(){
            var 
this[0].tooltip;
            if (
tt.destroy();
        });
};
function 
AnyTooltip(elementconfig){
    var 
me = {};
    var 
init = function(elementparams){
        
me.content_is_func false;
        
me.mywidth false;
        
me.animate_open false;
        
me.animate_close false;
        
me.myclass false;
        
me.on_open_callback false;
        
me.on_close_callback false;
        
me.wrapper false;
        
me.show_timer 0;
        
me.show_delay 300;
        
me.show_duration 200;
        
me.show_distance 30;
        
me.hide_timer 0;
        
me.hide_delay 300;
        
me.hide_duration 200;
        
me.hide_distance 30;
        
me.no_close false;
        
me.is_visible false;
        
me.already_hidden false// hack этот флаг устанавливается в true в самом начале выполнения delayedTooltipHide, и снова возвращается в false в delayedTooltipShow.
                                   // Если флаг установлен в true, то showTooltip не станет показывать тултип, но если контент тултипа возвращается функцией, то она все равно будет выполнена.
                                   // Это сделано для того, чтобы тултип не стал показываться в случае, если функция, возвращающая контент, использует асинхронный запрос, и он уже послан, но пользователь убрал курсор с искомого элемента.
        
me.node_heap '#node-heap';

        
/* load params */
        
if(element)
            
me.element = $(element);
        else return 
false;

        if( 
params.content ){
            if(
params.content.html){
                
me.content params.content.html;
            } else if(
params.content.func){
                
me.content_is_func true;
                
me.content params.content.func;
            } else return 
false;
        } else return 
false;

        if( 
params.style ){
            if(
params.style.width)
                
me.mywidth params.style.width;
            if(
params.style.animate_open)
                
me.animate_open params.style.animate_open;
            if(
params.style.animate_close)
                
me.animate_close params.style.animate_close;
            if(
params.style.myclass)
                
me.myclass params.style.myclass;
            if(
params.style.show_delay)
                
me.show_delay Math.floorparams.style.show_delay );
            if(
params.style.hide_delay)
                
me.hide_delay Math.floorparams.style.hide_delay );
            if(
typeof params.style.show_duration !== 'undefined')
                
me.show_duration Math.floorparams.style.show_duration );
            if(
params.style.show_distance)
                
me.show_distance Math.floorparams.style.show_distance );
            if(
params.style.hide_duration)
                
me.hide_duration Math.floorparams.style.hide_duration );
            if(
typeof params.style.hide_distance !== 'undefined')
                
me.hide_distance Math.floorparams.style.hide_distance );
            if(
params.style.no_close)
                
me.no_close params.style.no_close;
            if(
params.style.node_heap)
                
me.node_heap params.style.node_heap;

        }

        if( 
params.callbacks ){
            if(
params.callbacks.on_open)
                
me.on_open_callback params.callbacks.on_open;
            if(
params.callbacks.on_close)
                
me.on_close_callback params.callbacks.on_close;
        }

        
me.show =  delayedTooltipShow;
        
me.hide =  delayedTooltipHide;
        
me.destroy destroyTooltip;

        
me.html = function(html){
            
me.wrapper.html(html);
            
me.wrapper.append('<div class="arrow"></div>');
            
me.arrow me.wrapper.find('.arrow');
            
showTooltip();
        };

        
element.tooltip me;

        return 
me;
    };

    var 
destroyTooltip = function(){
        if(
me.wrapper)
            
me.wrapper.remove();
        
element.tooltip undefined;
        
me.already_hidden true;
        
me.is_visible false;
        
clearTimeoutme.hide_timer );
        
clearTimeoutme.show_timer );
    };

    var 
initWrapper = function(){
        
me.wrapper = $('<div class="iTooltip"></div>');

        if(
me.myclass)
            
me.wrapper.addClass(me.myclass);

        if(
me.mywidth)
            
me.wrapper.css('width'me.mywidth);

        if(
me.content_is_func){
            
me.content(me);
            return 
'need_callback';
        } else
            
me.wrapper.html(me.content);

        if(
me.wrapper.children().length 1)
            return 
false;
        
me.wrapper.append('<div class="arrow"></div>');
        
me.arrow me.wrapper.find('.arrow');
    };

    var 
delayedTooltipShow = function(){
        
me.already_hidden false;
        
clearTimeout(me.show_timer);
        
clearTimeout(me.hide_timer);
        
me.show_timer setTimeout(function(){ showTooltip(); }, me.show_delay);
        
AnyTooltipStack.push(me.element);
        
nav2.gc(AnyTooltipGc'AnyTooltipGc');
    };
    var 
showTooltip = function(){
        if(!
me.wrapper){
            if(
initWrapper() == 'need_callback')
                return 
true;
        }

        if (
me.already_hidden) {
            return 
false;
        }

        if(!
me.is_visible){
            
clearTimeout(me.hide_timer);
            
me.is_visible true;
            $(
me.node_heap).append(me.wrapper);
            if(!
me.no_close){
                
me.wrapper.bind('mouseenter'cancelTooltipHide);
                
me.wrapper.bind('mouseleave'delayedTooltipHide);
            }

            if(
me.animate_open){
                
me.animate_open(me);
            } else {
                var 
elementX me.element.offset().left me.element.outerWidth()/2,
                    
elementY me.element.offset().top,
                    
finalX elementX me.wrapper.outerWidth()/ 10,
                    
finalY elementY me.wrapper.outerHeight(true),
                    
tooltipHeight me.wrapper.outerHeight(true),
                    
wrapperWidth me.wrapper.outerWidth(true);

                if (
finalX wrapperWidth fs.windowW) {
                    
finalX -= finalX wrapperWidth fs.windowW 10;
                    
me.arrow.css('left'elementX finalX);
                } else {
                    
me.arrow.css('left''');
                }

                if(
elementYfs.scrollTop tooltipHeight){
                    var 
elementH me.element.outerHeight(false);
                    
me.arrow.addClass('onTop');
                    
me.wrapper.css({leftfinalXtopfinalY tooltipHeight elementH 15 me.show_distanceopacity0}).stop()
                        .
animate({topfinalY tooltipHeight elementH 15opacity1}, me.show_duration, function(){
                            if(
me.on_open_callback)
                                
me.on_open_callback(me);
                        });
                } else {
                    
me.arrow.removeClass('onTop');
                    
me.wrapper.css({leftfinalXtopfinalY 10 me.show_distanceopacity0}).stop()
                        .
animate({topfinalY 10opacity1}, me.show_duration, function(){
                            if(
me.on_open_callback)
                                
me.on_open_callback(me);
                        });
                }
            }
            return 
true;
        } else {
            return 
true;
        }
    };
    var 
delayedTooltipHide = function(noDelay){
        
me.already_hidden true;
        
clearTimeout(me.show_timer);
        
clearTimeout(me.hide_timer);
        if(
typeof noDelay != 'object' && noDelay)me.hide_timer setTimeout(hideTooltip,0);
        else 
me.hide_timer setTimeout(hideTooltipme.hide_delay);
    };
    var 
hideTooltip = function(){
        if(
me.is_visible){
            if(
me.animate_close){
                
me.animate_close(me);
            } else {
                var 
elementY me.element.offset().top,
                    
wrapperY me.wrapper.offset().top,
                    
finalY = (wrapperY elementY '+=' '-=') + me.hide_distance 'px';
                
me.wrapper.stop().animate({topfinalYopacity0}, me.hide_duration, function(){
                    if(
me.on_close_callback)
                        
me.on_close_callback(me);
                    
me.wrapper.remove();
                    
me.is_visible false;
                });
            }
        }
    };
    var 
cancelTooltipHide = function(){
        
clearTimeout(me.hide_timer);
    };

    return 
init(elementconfig);
}
AnyTooltip.show = function(elementparams){
    if(!
element.tooltip){
        
AnyTooltip(elementparams);
    }
    
element.tooltip.show();
};
AnyTooltip.hide = function(element){
    if (
typeof element.tooltip !== 'undefined') {
        
element.tooltip.hide();
        return 
true;
    } else {
        return 
false;
    }
};

var 
userTooltip = {
    
cache: {},
    
show : function(elementuidparams){
        if (
uid == currentUser.userId) return;
        
params = $.extend(params,{uiduid});
        
AnyTooltip.show(element, {
            
content: {
                
func: function(tooltip){
                    if(
typeof userTooltip.cache[uid] == 'undefined'){
                        var 
response = $.get('/tooltip/ajax/getTooltipUser/'params, function(response){
                            
userTooltip.cache[uid] = response.ret == response.html '';
                            if (
userTooltip.cache[uid].length) {
                                
tooltip.html(userTooltip.cache[uid]);
                            } else {
                                
tooltip.destroy();
                            }

                        }, 
'JSON');
                    } else if (
userTooltip.cache[uid].length) {
                        
tooltip.html(userTooltip.cache[uid]);
                    } else {
                        
tooltip.destroy();
                    }
                }
            },
            
style: {
                
width270,
                
myclass'user-tooltip',
                
show_delay200
            
}
        });
    },
    
hide: function(element){
        
AnyTooltip.hide(element);
    }
};

var 
infoTooltip = {
    
show: function (elementcontentwidthopts) {
        
AnyTooltip.show(element, $.extend(true, {
            
content: {
                
html'<div class="info-tooltip-content">'+content+'</div>'
            
},
            
style: {
                
myclass'info-tooltip',
                
width: ( typeof width !== 'undefined' ) ? width false,
                
show_delay200,
                
show_distance15,
                
hide_distance15,
                
animate_open: function (me) {
                    var 
elementX me.element.offset().left me.element.outerWidth()/2,
                        
elementY me.element.offset().top,
                        
finalX elementX me.wrapper.outerWidth()/2,
                        
finalY elementY me.wrapper.outerHeight(true),
                        
tooltipHeight me.wrapper.outerHeight(true),
                        
wrapperWidth me.wrapper.outerWidth(true),
                        
bodyWidth = $(document.body).width();

                    if (
finalX wrapperWidth bodyWidth) {
                        
finalX bodyWidth wrapperWidth-10;
                        
me.wrapper.css("width",me.wrapper.width());
                        
me.arrow.css('left'elementX finalX);
                    } else if (
finalX 0) {
                        
finalX 10;
                        
me.arrow.css('left'elementX finalX);
                    } else {
                        
me.arrow.css('left''');
                        
me.wrapper.css("width",me.wrapper.width());
                    }

                    if(
elementYfs.scrollTop tooltipHeight){
                        var 
elementH me.element.outerHeight(false);
                        
me.arrow.addClass('onTop');
                        
me.wrapper.css({leftfinalXtopfinalY tooltipHeight elementH 15 me.show_distanceopacity0}).stop()
                            .
animate({topfinalY tooltipHeight elementH 15opacity1}, me.show_duration, function(){
                                if(
me.on_open_callback)
                                    
me.on_open_callback(me);
                            });
                    } else {
                        
me.arrow.removeClass('onTop');
                        
me.wrapper.css({leftfinalXtopfinalY 10 me.show_distanceopacity0}).stop()
                            .
animate({topfinalY 10opacity1}, me.show_duration, function(){
                                if(
me.on_open_callback)
                                    
me.on_open_callback(me);
                            });
                    }
                }
            }
        }, 
opts));
    },
    
hide: function (element) {
        
AnyTooltip.hide(element);
    },
    
destroy: function(){AnyTooltipGc();}
};

var 
helpTooltip = {
    
show: function (elementcontentfixXfixYshowDown) {
        
AnyTooltip.show(element, {
            
content: {
                
html'<div class="info-tooltip-content">'+content+'</div>'
            
},
            
style: {
                
myclass'info-tooltip',
                
show_delay350,
                
show_distance15,
                
hide_distance15,
                
animate_open: function (me) {
                    var 
elementX me.element.offset().left me.element.outerWidth()/2,
                        
elementY me.element.offset().top,
                        
finalX elementX me.wrapper.outerWidth()/+ ((typeof fixX !== 'undefined') ? parseInt(fixX) : 0),
                        
finalY elementY me.wrapper.outerHeight(true) + ((typeof fixY !== 'undefined') ? parseInt(fixY): 0),
                        
tooltipHeight me.wrapper.outerHeight(true),
                        
wrapperWidth me.wrapper.outerWidth(true);
                    
showDown = (typeof(showDown) !== 'undefined') ? showDown false;
                    if ((
finalX wrapperWidth fs.windowW)) {
                        
finalX -= finalX wrapperWidth fs.windowW 10;
                        
me.arrow.css('left'elementX finalX);
                    } else if (
finalX 0) {
                        
finalX 10;
                        
me.arrow.css('left'elementX finalX);
                    } else {
                        
me.arrow.css('left''');
                    }

                    if(
elementYfs.scrollTop tooltipHeight || showDown){
                        var 
elementH me.element.outerHeight(false);
                        
me.arrow.addClass('onTop');
                        
me.wrapper.css({leftfinalXtopfinalY tooltipHeight elementH 15 me.show_distanceopacity0}).stop()
                            .
animate({topfinalY tooltipHeight elementH 15opacity1}, me.show_duration, function(){
                                if(
me.on_open_callback)
                                    
me.on_open_callback(me);
                            });
                    } else {
                        
me.arrow.removeClass('onTop');
                        
me.wrapper.css({leftfinalXtopfinalY 10 me.show_distanceopacity0}).stop()
                            .
animate({topfinalY 10opacity1}, me.show_duration, function(){
                                if(
me.on_open_callback)
                                    
me.on_open_callback(me);
                            });
                    }
                }
            }
        });
    },
    
hide: function (element) {
        
AnyTooltip.hide(element);
    }
};

var 
recordTooltip = {
  
cache: {},
  
show : function(elementrecordIdparams){
    
params = $.extend(params,{recordIdrecordIdajaxtrue});
    
AnyTooltip.show(element, {
      
content: {
        
func: function(tooltip){
          var 
localContent = $('#notify-content-'+recordId);
          if (
localContent.length) {
            
tooltip.html(localContent.html());
          } else {
            if(!
recordTooltip.cache[recordId]){
              var 
response = $.get('/newsfeed/ajax/gettooltip/'params, function(response){
                
recordTooltip.cache[recordId] = response.ret == response.html fsLang.get('newsfeed_deleted_record');
                
tooltip.html(recordTooltip.cache[recordId]);
              }, 
'JSON');
            } else {
              
tooltip.html(recordTooltip.cache[recordId]);
            }
          }
        }
      },
      
style: {
        
width340,
        
myclass'superTooltip',
        
show_delay200
      
}
    });
  },
  
hide: function(element){
    
AnyTooltip.hide(element);
  }
};

var 
iPopupOnEscClose = function(event){
    if(
event.keyCode == 27)
        
iPopup.close();
};

function 
AnyPopup(unameconfig){
    var 
content_is_func false,
        
animate_open false,
        
is_visible false,
        
content false,
        
me = {};

    var 
init = function(unameparams){
        
me.mywidth 800;
        
me.on_open_callback false;
        
me.on_close_callback false;
        
me.wrapper false;
        
me.top_offset false;
        
me.uname uname;
        
me.closeAttr 'onclick="'+me.uname+'.close();"';
        
me.overlayClose 'onclick="var target = event.target || event.srcElement, currentTarget = event.currentTarget || this; if (target == currentTarget) { '+me.uname+'.close(); }"';
        
me.noOverlay '';
        
me.myclass false;
        
me.noFormatting false;
        
me.uid '';

        
/* load params */
        
if( params.content ){
            if(
params.content.html)
                
content params.content.html;
            else if(
params.content.func){
                
content_is_func true;
                
content params.content.func;
            }
            else return 
false;
        } else return 
false;

        if(
typeof params.eventer !== 'undefined'){
            
me.eventer params.eventer;
        }

        if( 
params.style ){
            if(
params.style.width)
                
me.mywidth params.style.width;
            if(
params.style.myclass)
                
me.myclass params.style.myclass;
            if(
params.style.top_offset)
                
me.top_offset Math.floorparams.style.top_offset );
        }

        if(
params.onopen)
            
me.on_open_callback params.onopen;
        if(
params.onclose)
            
me.on_close_callback params.onclose;

        if(
params.title)
            
me.title params.title;
        if(
params.footer)
            
me.footer params.footer;
        if(
params.noOverlayClose)
            
me.overlayClose '';
        if(
params.noOverlay)
            
me.noOverlay ' noOverlay';
        if(
params.noFormatting)
            
me.noFormatting true;

        if(
params.uid)
            
me.uid params.uid;

        
me.html = function(html){
            
me.inner.html(html);
            
openPopup();
        };
        
me.open openPopup;
        
me.close closePopup;
        
me.align alignPopup;
        
me.isVisible = function(){
            return 
is_visible;
        };

        
scrollable({
            
nameme.uname+me.uid,
            
onpop: function(){},
            
onpush: function(){},
            
onbelow: function(){
                
me.wrapper.addClass('fixed'+((me.noOverlay)?'':' noOverlay')).css({top: -fs.scrollTop'z-index'1001});
                
me.popupBody.css({'z-index'1000});
                $(
window).unbind('keydown.'+me.uname+me.uidiPopupOnEscClose);
            },
            
onover: function(){
                
me.wrapper.removeClass('fixed'+((me.noOverlay)?'':' noOverlay'));
                var 
top me.wrapper.css('top');
                
me.wrapper.css({top0'z-index'1009});
                
me.popupBody.css({'z-index'1010});
                
scrollToY(-parseInt(top));
                $(
window).bind('keydown.'+me.uname+me.uidiPopupOnEscClose);
            }
        });

        return 
me;
    };

    var 
initWrapper = function(){
        
me.wrapper = $('<div class="iPopup-overlay'+me.noOverlay+'" id="'+me.uname+me.uid+'" ' +me.overlayClose +'><div class="iPopup">'+
            
'<div class="popup-content">'+
            
'</div>'+
            
'</div></div>');

        
me.popupBody me.wrapper.find('.iPopup');
        if(
me.title){
            
me.popupBody.prepend($('<div class="popup-header nclear">'+
                    
'<h2>'+me.title+'</h2>'+
                    
'<i class="icn icn-light-gray icn-cross" '+me.closeAttr+'></i>'+
                
'</div>'));
        }
        if(
me.footer){
            
me.popupBody.append($('<div class="popup-footer nclear">'+
                    
me.footer+
                
'</div>'));
        }
        if(!
me.noFormatting)
            
me.inner me.wrapper.find('.popup-content');
        else
            
me.inner me.wrapper.find('.iPopup');

        if(
me.myclass)
            
me.wrapper.addClass(me.myclass);

        if(
me.mywidth)
            
me.popupBody.css('width'me.mywidth);

        if(
content_is_func){
            if(
content(me)) {
                return 
'need_callback';
            } else {
                
closePopup();
                return 
false;
            }
        } else {
            
me.inner.html(content);
        }

        if(
me.inner.children().length 1)
            return 
false;

    };

    var 
openPopup = function(){
        if(!
me.wrapper){
            if(
initWrapper() == 'need_callback')
                return 
true;
        }

        if(!
is_visible){
            
is_visible true;
            $(
'#node-heap').append(me.wrapper);
            
scrollable.push(me.uname+me.uid);

            $(
window).bind('keydown.'+me.uname+me.uidiPopupOnEscClose);
            
nav2.gc(function(){ $(window).unbind('keydown'iPopupOnEscClose); }, 'closePopup');

            var 
finalY 50;
            if(
me.top_offset)
                
finalY me.top_offset;
            else if ( 
fs.windowH me.popupBody.outerHeight() > 50 )
                
finalY = (fs.windowH me.popupBody.outerHeight())/2;

            
me.popupBody.css({'margin-top'finalY});
            if(
me.on_open_callback)
                
me.on_open_callback(me);

            return 
true;
        } else {
            return 
true;
        }
    };

    var 
alignPopup = function(){
        var 
finalY 50;
        if(
me.top_offset)
            
finalY me.top_offset;
        else if ( 
fs.windowH me.popupBody.outerHeight() > 50 )
            
finalY = (fs.windowH me.popupBody.outerHeight())/2;

        
me.popupBody.css({'margin-top'finalY});
    };

    var 
closePopup = function(){
        if(
is_visible){
            $(
window).unbind('keydown.'+me.uname+me.uidiPopupOnEscClose);
            if(
me.on_close_callback)
                
me.on_close_callback(me);
            if(
me.wrapper)
                
me.wrapper.remove();
            
scrollable.pop(me.uname+me.uid);
            
is_visible false;
            
me.eventer.emit('closed', {uidme.uidnameme.uname});
        }
    };

    return 
init(unameconfig);
}

var 
iPopup = {
    
eventer: new Eventer({eventPrefix'iPopup_'}),
    
popupfalse,
    
popupStack: [],
    
config: {},
    
init: function(){
        
iPopup.eventer.on('closed', function(eventdata){
            if(
typeof data.uid !== 'undefined'){
                var 
prevPopup iPopup.popup;
                if(
iPopup.popup.uid === data.uid){
                    
prevPopup iPopup.popup
                    
if(iPopup.popupStack.length 0){
                        
iPopup.popup iPopup.popupStack[iPopup.popupStack.length 1];
                        
iPopup.popupStack.pop();
                        $.
extend(iPopup.config, { uidiPopup.popupStack.length });
                    } else {
                        
iPopup.popup false;
                    }
                } else {
                    var 
stack iPopup.popupStack;
                    for(var 
stack.length-1i>=0i--){
                        if(
stack[i].uid === data.uid){
                            
stack.splice(i1);
                            $.
extend(iPopup.config, { uidiPopup.popupStack.length });
                            break;
                        }
                    }
                }
            } else {
                return 
false;
            }
        });
    },
    
open: function(textparams){
        if(
typeof text === 'undefined' || text == false)
            return 
false;
        
iPopup.config = $.extend({
            
content: { htmltext },
            
eventeriPopup.eventer
        
}, params);
        if(
iPopup.popup && iPopup.popup.isVisible() && !params.uid){
            
iPopup.popupStack.push(iPopup.popup);
            $.
extend(iPopup.config, { uidiPopup.popupStack.length });
        }
        
iPopup.popup AnyPopup('iPopup'iPopup.config);
        
iPopup.popup.open();
        
nav2.gc(iPopup.closeAll'closeAllPopups');
        return 
iPopup.popup;
    },
    
close: function(){
        if(
typeof iPopup.popup.close === 'function'){
            
iPopup.popup.close();
        }
    },
    
closeAll: function(){
        while ( 
iPopup.popup !== false )
            
iPopup.close();
    },
    
align: function(textpopupConfig){
        
iPopup.popup.align();
    },
    
error: function(textpopupConfig){
        var 
errorConfig = $.extend(true, {
            
title:'Ошибка!',
            
style:{width500myclass'font-large'}
        }, 
popupConfig);
        return 
iPopup.open(texterrorConfig);
    },
    
alert: function(textpopupConfig){
        var 
alertConfig = $.extend(true, {
            
title:'Внимание!',
            
style:{width500myclass'font-large'}
        }, 
popupConfig);
        return 
iPopup.open(textalertConfig);
    },
    
confirm: function (textbuttonConfigpopupConfig) {
        
buttonConfig = $.extend(true, [{
            
title'Да',
            
myclass'ibtn-blue',
            
defaultEntertrue
        
}, {
            
title'Нет'
        
}], buttonConfig);

        var 
footer '',
            
currConfig,
            
defaultEnterIdx null;
        for (var 
0buttonConfig.lengthli++) {
            
currConfig buttonConfig[i];
            
footer += '<div class="ibtn unselectable '+(currConfig.myclass currConfig.myclass '')+'">'+currConfig.title+'</div>';
            if (
currConfig.defaultEnter) {
                
defaultEnterIdx i;
            }
        }

        var 
keyDownFn = function (event) {
            if (
event.which == 13) { // Enter
                
sp(event);
                
pd(event);
                
iPopup.popup.popupBody.find('.popup-footer .ibtn').eq(defaultEnterIdx).click();
            }
        };
        if (
defaultEnterIdx !== null) {
            $(
window).bind('keydown'keyDownFn);
            
nav2.gc(function(){ $(window).unbind('keydown'keyDownFn); });
        }

        var 
confirmConfig = $.extend(true, {
            
title:'Подтверждение',
            
footerfooter,
            
style:{width500myclass'font-large'}
        }, 
popupConfig);
        
confirmConfig.onopen = function (me) {
            
me.popupBody.find('.popup-footer .ibtn').each(function (indexitem) {
                
item.onclick = function () {
                    var 
currConfig buttonConfig[index];
                    if (
currConfig.callback) {
                        
currConfig.callback(me);
                    }
                    if (!
currConfig.preventClose) {
                        
iPopup.close();
                    }
                };
            });

            if (
popupConfig && popupConfig.onopenpopupConfig.onopen(me);
        };
        
confirmConfig.onclose = function (me) {
            $(
window).unbind('keydown'keyDownFn);

            if (
popupConfig && popupConfig.onclosepopupConfig.onclose(me);
        };
        return 
iPopup.open(textconfirmConfig);
    },
    
anyOpened: function(){ return iPopup.popup true false; }
};
iPopup.init();

var 
sendMessagePopup = function(useridparams){
    
_ajax.get('/friends/ajax/openPopupSendOneMesseng/', {iduseridparam:params}, function(hsd){
        if (!
d.errors) {
            if(
d.error == 0) {
                if (
d.popularContact) {
                    
iPopup.open (d.html, { title'Отправить сообщение'style: {width600}, noFormattingtrue });
                } else {
                    if (
d.redirectToContactAdvQuest) {
                        
nav2.go('/usercontact/?qoid=' userid '&adventuresQuest=' d.redirectToContactAdvQuest);
                    }

                     if (
d.redirectToContact 0) {
                        
nav2.go('/usercontact/?qoid=' userid);
                    } else {
                        
iPopup.opend.html, {
                            
title'Отправить сообщение',
                            
style: {width575myclass'font-large'} ,
                            
onclose: function(){
                                if(
typeof SendMessagePopupTimer !== 'undefined')
                                    
clearInterval(SendMessagePopupTimer);
                                if(
typeof usercontact === 'object' && typeof usercontact.assistant === 'object'
                                  
&& typeof usercontact.assistant.gc === 'function'){
                                    
usercontact.assistant.gc();
                                }
                            }
                        });
                    }
                }
            } else {
                
iPopup.open'<h3>Упс, что-то сломалось</h3>', { title'Ошибка'style: {width575myclass'font-large'} } );
            }
        } else {
            if (
d.errors.what == 'photo') {
                
userpic.showUploadPopupNewFs2(23, function(){location.reload(true);});
            } else if (
d.errors.what == 'notapprovedphoto') {
                
fs.notify('Увы, но вы не можете отправлять сообщения другим пользователям,<br/>пока вашу аватарку не проверят модераторы (это занимает около 2 минут).', {duration2000});
            } else if (
d.errors.what == 'privacy') {
              
fs.notify('Увы, но вы не можете отправить сообщение этому пользователю,<br/>потому что он ограничил входящие сообщения настройками приватности.', {duration2000});
            } else if (
d.errors.what == 'ignor') {
              
iPopup.confirm(d.errors.text, $.extend(true, [{
                
title'Отмена',
                
defaultEntertrue,
                
myclass''
              
}, {
                
title'Убрать и продолжить',
                
myclass'ibtn-blue',
                
callback: function() {
                  
delFromBlacklist(useridnull, function(){
                    $(
'#profile-blacklist-add').removeClass('d-n');
                    $(
'#profile-blacklist-del').addClass('d-n');
                    
sendMessagePopup(useridparams);
                  });
                }
              }]));

            } else {
                
showMailPhoneReminderPopup(9);
            }
            return 
false;
        }
    });
};

var 
showGuestPopup = function (hashtitleparams) {
    if (
params.groupDef) {
        return 
pacman.showSympathyPopup(params.groupDeftitle);
    }
    return 
notifyPopup.show('guest'hashtitleparams);
};

var 
showPeoplePopup = function (idstitleparams) {
    return 
notifyPopup.show('people'idstitleparams);
};

var 
showSympathyPopup = function (idstitleparams) {
    if (
params.groupDef) {
        return 
pacman.showSympathyPopup(params.groupDeftitle);
    }
    return 
notifyPopup.show('sympathy'idstitleparams);
};

var 
notifyPopup = {
    
// Параметры нотификаций: иконки, ширина
    
notifications: {
        
people   : { width544iconfalse },
        
guest    : { width888icontrue  },
        
sympathy : { width888icontrue  },
        
photocontest:{ width552iconfalse}
    },
    
show: function (popupTypenotifyDatatitleparamsonclose) {
        if (
typeof notifyPopup.notifications[popupType] == 'undefined') {
            return 
false;
        }
        
// Настройки текущей нотификации
        
var cNotify notifyPopup.notifications[popupType];
        var 
ungroup '';
        if (
popupType == "sympathy" && params && params.hasOwnProperty('canGrouped') && params.canGrouped) {
            if (
params.hasOwnProperty('notifyId') && params.hasOwnProperty('groupId')) {
                
ungroup '<a class="symphaty-footer-ungroup" onclick="pacman.changeGroup(this, ' params.notifyId ', ' params.groupId ', 1); sp(event);">Показывать в моих новостях все просмотры моих фото</a>';
            }
        }

        $.
post('/pacman/ajax/getNotifyPopup/', { ajax1popupTypepopupTypenotifyDatanotifyDataparamparamspage}, function (response) {
            if(
response.ret == 1) {
                var 
notifyScroll;

                
iPopup.open('<ul class="' popupType '-list nclear">' response.html '</ul>'+(response.hasNext '<a class="show-more-link">Показать еще</a>' ''), {
                    
title: (cNotify.icon '<div class="' popupType '-popup-header-icon"><i class="icn icn-white ' + ((response.icon  != 'undefined') ? response.icon 'icn-' popupType) + '"></i></div>' '') + '' title,
                    
footerungroup+'<div class="ibtn ibtn-blue ' popupType '-btn-close" onclick="iPopup.close();">Закрыть</div>',
                    
style: {
                        
myclasspopupType '-popup',
                        
widthcNotify.width
                    
},
                    
onopen: function (me) {
                        if (
response.hasNext) {
                            
// Некоторые локальные переменные
                            
var loadLock false,
                                
notifyPage 2,
                                
$listContainer me.popupBody.find('.' popupType '-list'),
                                
$loader me.popupBody.find('.show-more-link'),
                                
loadPage = function (scroll) {
                                    if(!
loadLock) {
                                        
loadLock true;
                                        $.
post('/pacman/ajax/getNotifyPopup/', { ajax1popupTypepopupTypenotifyDatanotifyDataparamparamspagenotifyPage }, function(response){
                                            if(
response.ret == 1){
                                                
$listContainer.append(response.html);
                                                
notifyPage++;
                                                
loadLock false;
                                            }
                                            if (
response.ret != || !response.hasNext) {
                                                
scroll.destroy();
                                                
$loader.remove();
                                            }
                                        }, 
'json');
                                    }
                                };

                            
notifyScroll = new Scroller({
                                
scrollTo'.' popupType '-popup .show-more-link',
                                
onScrollloadPage
                            
});

                            
$loader.click(function () {
                                
loadPage(notifyScroll);
                            });
                        }
                    },
                    
onclose: function () {

                        if (
typeof onclose != "undefined") {
                            
onclose();
                        }

                        if (
notifyScroll) {
                            
notifyScroll.destroy();
                        }
                    }
                });
            }
        }, 
'json');
    }
};


/*var showAppSettingsPopup = function (appId, queryStr) {
    appSettingsPopup.show(appId, queryStr);
};*/

var appSettingsPopup = {
    
// Открыт поап из интересных сервисов?
    
fromServicesfalse,
    
queryStr'',
    
appId'',
    
params: {},

    
show: function (appIdqueryStrfromSrvparams) {
        
// Из интересных сервисов
        
appSettingsPopup.queryStr = (typeof queryStr == 'undefined') ? '' queryStr;
        
appSettingsPopup.fromServices = (typeof fromSrv == 'undefined') ? false true;
        
appSettingsPopup.params = (typeof params == 'undefined') ? {} : params;
        
appSettingsPopup.appId appId;
        
// Открыть
        
$.get('/app/'+appId+'/settings'+appSettingsPopup.queryStr, {}, function (resp) {
            if (!
resp) {
                return;
            }
            
iPopup.open(resp.content, {
                
titleresp.title || 'Настройки сервиса',
                
style: { myclass'app-settings-popup'width550 },
                
footer'<div class="ibtn ibtn-blue app-save-button unselectable" onclick="appSettingsPopup.saveApp(); iPopup.close();">Сохранить</div><div class="ibtn ibtn-border app-close-button unselectable">Закрыть</div><a class="secondary-link app-remove-button">Удалить сервис</a>',
                
onopen: function (popup) {
                    
popup.popupBody.find('.app-close-button').click(function () {
                        
iPopup.close();
                    });
                    
popup.popupBody.find('.app-remove-button').click(function () {
                        
iPopup.confirm('Вы уверены, что хотите удалить сервис? Все Ваши достижения в нём также будут удалены!', [{
                            
callback: function () {
                                
appSettingsPopup.removeApp();
                            }
                        }]);
                    });
                }
            });
        }, 
'json');
    },
    
saveApp: function() {
        if (!
appSettingsPopup.fromServices) {
            $(
'#appSettingsForm').submit();
        } else {
            var 
postData = $('#appSettingsForm').serialize() + '&isAjax=1&justSave=1'
            
// Отправим
            
$.post('/app/'+appSettingsPopup.appId+'/rights'+appSettingsPopup.queryStrpostData, function(resp) {
                if (!
resp || !resp.ret) {
                    
fs.notify(resp.message);
                    return;
                }
            });
        }
    },
    
removeApp: function() {
        
//TODO:Для интересных сервисов вынести отдельно
        
if (appSettingsPopup.fromServices){
            $.
post('/app/'+appSettingsPopup.appId+'/remove', { ajax:truefromServices:true }, function(){
                var 
params appSettingsPopup.params;
                if (
params) {
                    if (
'elem' in params && 'srvAppId' in params && 'srvAppType' in params) {
                        if (
typeof interestService != 'undefined') {
                            
//interestService.hideService(params.elem, params.srvAppId, { appType: params.srvAppType });
                            // TODO: копипаст удалённого блока из interestService.hideService()
                            
var elem = $(params.elem).parents('.int-app');
                            
elem.removeClass('int-app tr-bg-color-03 nclear').addClass('int-dummy-app-block dashed-block tr-opacity-03');
                            
elem[0].beforeRemoving elem.html();
                            
elem.html('<div class="dashed-block-border"><div class="dashed-block-inner"><span class="dashed-block-big-text trebuchet">Успешно удалено</span><a>Восстановить</a></div></div>');
                            
elem.find('a').bind('click', function(){
                                
interestService.unHideService(thisparams.srvAppId, { appTypeparams.srvAppType});
                            });
                            
// end of копипаст
                        
}
                        if (
typeof interestsBase != 'undefined') {
                            
interestsBase.reloadList();
                        }
                    }
                }
                
iPopup.close();
                
fs.notify('Сервис удалён');
            });
        } else {
            
window.location '/app/'+appSettingsPopup.appId+'/remove';
        }
    }
};

function 
SelectText(element) {
  var 
text = $(element)[0];
  if ($.
browser.msie) {
    var 
range document.body.createTextRange();
    
range.moveToElementText(text);
    
range.select();
  } else {
    var 
selection window.getSelection();
    var 
range document.createRange();
    
range.selectNodeContents(text);
    
selection.removeAllRanges();
    
selection.addRange(range);
  }
}

function 
contentEditableBlock(elementconfig){
    var 
contentEditableBlock = {},
        
contentEditableBlockText = {},
        
contentEditableBlockPencil false,
        
contentEditableBlockTimer 0,
        
beforeEditingText false,
        
contentEditableBlockSaveBtn false,
        
contentEditableBlockTimeout 0,
        
defaultText 'Пусто',
        
mottos false,
        
curkey 0,
        
randomMottoBtn false;

    var 
init = function(elementparamsscope){
        
me scope;
        if(
element)
            
contentEditableBlock = $(element);
        else
            return 
false;
        
contentEditableBlockText contentEditableBlock.text();
        if(
params.pencil){
            
contentEditableBlockPencil = $(params.pencil);
            
contentEditableBlockPencil.bind('click.contentEditable'editBlock);
        }
        if(
params.mottos){
            
mottos params.mottos;
            if(
params.randomBtn){
                
randomMottoBtn = $(params.randomBtn);
                
randomMottoBtn.bind('click.contentEditable', function(){
                    
curkey curkey mottos.length curkey+0;
                    
contentEditableBlock.text(mottos[curkey]);
                    
onFocusFunction();
                });
            }
        }
        if(
params.defaultText)
            
defaultText params.defaultText;

        
contentEditableBlock
            
.bind('focus.contentEditable'onFocusFunction)
            .
bind('blur.contentEditable'onBlurFunction)
            .
bind('keydown.contentEditable'onKeydownFunction)
            .
bind('paste.contentEditable', function() {
                
prepasteFunction();
                
setTimeout(postpasteFunction2);
            })
            .
bind('prepaste.contentEditable'prepasteFunction)
            .
bind('postpaste.contentEditable'postpasteFunction);

        
me.edit editBlock;
        
element.contentEditableBlock me;
        return 
me;
    };

    var 
editBlock = function() {
        if(!
contentEditableBlock.hasClass('active')){
            
contentEditableBlock.attr('contenteditable''true');
            
contentEditableBlock.after('<a id="save-status-btn" class="ibtn ibtn-blue">Сохранить</a>');
            
contentEditableBlockSaveBtn = $('#save-status-btn');
            
contentEditableBlockSaveBtn.bind('click'updateStatus);
            
randomMottoBtn.show();
            
contentEditableBlockPencil.hide();
            
contentEditableBlock.trigger('focus');
            
SelectText(contentEditableBlock);
        }
    };

    var 
updateStatus = function(){
        var 
valA = {};
        
valA['ajax'] = 1;
        
valA['user-motto'] = $.trim(contentEditableBlock.text().replace(/(rn|n|r)/gm,""));
        
valA['section'] = 'motto';
        
beforeEditingText contentEditableBlock.text();
        
onBlurFunction(event, [true]);

        $.
post('/userinfo/Ajax/saveuserinfo/'valA, function(res){
            if(
res.status == 'ok'){
                
contentEditableBlock.text(res.message);
                if(
res.messageDel == 1){
                    
fs.notify('Статус удален');
                } else {
                    if(
res.isNew == 1)
                        
fs.notify('Статус изменен');
                }
            }
        });
    };

    var 
onFocusFunction = function() {
        
clearTimeout(contentEditableBlockTimeout);
        if(!
contentEditableBlock.hasClass('active')) {
            if (!
beforeEditingText){
                
contentEditableBlockText contentEditableBlock.text();
                
beforeEditingText contentEditableBlockText;
            } else 
contentEditableBlock.text(contentEditableBlockText);

            
contentEditableBlock.addClass('active');
            
contentEditableBlock.parent().addClass('active'); // rewrite
            
if(contentEditableBlockText == defaultText)
                
contentEditableBlock.text('');
        }
    };
    var 
onBlurFunction = function(ereset) {
        
clearTimeout(contentEditableBlockTimeout);
        
contentEditableBlockTimeout setTimeout( function(){
            
contentEditableBlock.removeClass('active');
            
contentEditableBlock.parent().removeClass('active'); // rewrite
            
contentEditableBlock.attr('contenteditable''false');
            
contentEditableBlockText contentEditableBlock.text();
            
contentEditableBlockSaveBtn.remove();
            
randomMottoBtn.hide();
            
contentEditableBlockPencil.show();
            if(
reset){
                
beforeEditingText false;
            } else {
                
contentEditableBlock.text(beforeEditingText);
            }
        }, 
150);
    };
    var 
onKeydownFunction = function(event) {
        
// ESC=27, Enter=13
        
if (event.keyCode == 27) {
            
contentEditableBlock.text(contentEditableBlockText);
            
onBlurFunction();
        } else if (
event.keyCode == 13) {
            
updateStatus();
        } else if(
contentEditableBlock.text().length >= 250 && $.inArray(event.keyCode, [8,16,17,18,33,34,35,36,37,38,39,40,46]) == -1){
            return 
false;
        }
    };
    var 
prepasteFunction = function() {
        
contentEditableBlockText contentEditableBlock.text();
        return 
true;
    };
    var 
postpasteFunction = function() {
        if(
contentEditableBlock.children().length 0){
            
contentEditableBlockText contentEditableBlock.text();
            
contentEditableBlock.children().remove();
            
contentEditableBlock.text(contentEditableBlockText);
        }
        return 
true;
    };
    
this.destroy = function(){
        
contentEditableBlock.unbind('.contentEditable');
        
randomMottoBtn.unbind('.contentEditable');
        
contentEditableBlockPencil.unbind('.contentEditable');
    };

    return 
init(elementconfigthis);
}
contentEditableBlock.edit = function(elementeventparams){
    if(!
element.contentEditableBlock)
        
contentEditableBlock(elementparams);
    
element.contentEditableBlock.edit();
};

/* scrollbar */
function Scrollbar(eloptions) {

  var 
self this;

  
options self.options options || {};

  
self.wrap = $(ge(el));

  
self.inner self.wrap.children().css({ overflow: ('hidden') });

  
self.el self.inner[0];
  
self.content self.inner.children();

  
self.scrollHeight self.inner.height();
  
self.scrollbar = $('<div class="scrollbar-wrap"></div>').css({ right0heightself.scrollHeight });
  
self.scrollbar_inner = $('<div class="scrollbar-inner"></div>').appendTo(this.scrollbar);
  
self.topShadowDiv = $('<div class="scrollbar-top"></div>');
  
self.bottomShadowDiv = $('<div class="scrollbar-bottom"></div>');

  
self.wrap.append(self.scrollbar).append(self.topShadowDiv).append(self.bottomShadowDiv);

  
self.mouseMove self._mouseMove.bind(self);
  
self.mouseUp self._mouseUp.bind(self);

  function 
down(event) {
    if (
self.moveY || checkEvent(event)) return;
    $(
document).bind('mousemove'self.mouseMove).bind('mouseup'self.mouseUp);
    
self.moveY fs.mouseY - (parseInt(self.scrollbar_inner.css('marginTop')) || 0);

    
window.document.body.style.cursor 'pointer';
    
self.scrollbar_inner.addClass('scrollbar-drag');
    
cancelEvent(event);
  }

  var 
wheel this.wheel.bind(this);

  
self.inner.bind('mousewheel DOMMouseScroll'wheel);
  
self.scrollbar_inner.bind('mousedown'down);

  
// touch
  
var touchstart = function(event) {
    
event event.originalEvent;
    
self.touchY  event.touches[0].pageY;
  };
  var 
touchmove = function(event) {
    
event event.originalEvent;
    var 
touchY event.touches[0].pageY;
    
self.touchDiff self.touchY touchY;
    
self.el.scrollTop += self.touchDiff;
    
self.touchY touchY;
    if (
self.el.scrollTop && self.shown !== false) {
      
self.update(true);
      
cancelEvent(event);
    }
  };
  var 
touchend = function() {
    
self.animateInt setInterval(function(){
      
self.touchDiff self.touchDiff 0.9;
      if (
self.touchDiff && self.touchDiff > -1) {
        
clearInterval(self.animateInt);
      } else {
        
self.el.scrollTop += self.touchDiff;
        
self.update(true);
      }
    }, 
0);
  };
  
self.inner.bind('touchstart'touchstart);
  
self.inner.bind('touchmove'touchmove);
  
self.inner.bind('touchend'touchend);

  
this.inited true;
  
this.update(true);
}

Scrollbar.prototype._mouseMove = function(event) {
  
this.el.scrollTop Math.floor((this.contHeight() - this.scrollHeight) * Math.min(1, (fs.mouseY this.moveY) / (this.scrollHeight this.innerHeight)));
  
this.update(true);
  return 
false;
}

Scrollbar.prototype._mouseUp = function(event) {
  
this.moveY false;
  $(
document).unbind('mousemove'self.mouseMove).unbind('mouseup'self.mouseUp);
  
window.document.body.style.cursor 'default';
  
this.scrollbar_inner.removeClass('scrollbar-drag');
  return 
false;
}

Scrollbar.prototype.wheel = function(event) {
  if (
this.disabled) {
    return;
  }
  
event event.originalEvent;
  var 
delta 0;
  if (
event.wheelDeltaY || event.wheelDelta) {
    
delta = (event.wheelDeltaY || event.wheelDelta) / 2;
  } else if (
event.detail) {
    
delta = -event.detail 10
  
}
  var 
stWas this.el.scrollTop;

  
this.el.scrollTop -= delta;

  if (
stWas != this.el.scrollTop && this.shown !== false) {
    if (
this.options.onWheelthis.options.onWheel();
    
this.update(true);
    
this.scrollbar_inner.addClass('scrollbar-hovered');
    
clearTimeout(this.moveTimeoput);
    
this.moveTimeoput setTimeout((function() {
      
this.scrollbar_inner.removeClass('scrollbar-hovered');
    }).
bind(this), 300);
  }
  if (
this.shown) {
    return 
false;
  }
}

Scrollbar.prototype.hide = function() {
  
this.topShadowDiv.hide();
  
this.bottomShadowDiv.hide();
  
this.scrollbar.hide();
  
this.hidden true;
}
Scrollbar.prototype.show = function() {
  
this.topShadowDiv.show();
  
this.bottomShadowDiv.show();
  
this.scrollbar.show();
  
this.hidden false;
}
Scrollbar.prototype.disable = function() {
  
this.hide();
  
this.scrollToY(0);
  
this.disabled true;
}
Scrollbar.prototype.enable = function() {
  
this.show();
  
this.update();
  
this.disabled false;
}

Scrollbar.prototype.scrollToY = function(top) {
  
this.el.scrollTop parseInt(top);
  
this.update(falsetrue);
}

Scrollbar.prototype.contHeight = function() {
  var 
self this;
  if (!
self.contentHeight) {
    
self.contentHeight 0;
    
self.content.each(function(){
      
self.contentHeight += $(this).height();
    });
  }
  return 
self.contentHeight;
}

Scrollbar.prototype.val = function(value) {
  if (
value) {
    
this.el.scrollTop value;
    
this.update(truetrue);
  }
  return 
this.el.scrollTop;
}

Scrollbar.prototype.update = function(noChangeupdateScroll) {
  if (!
this.inited || this.hidden) {
    return;
  }
  if (!
noChange) {
    
this.contentHeight false;
    if (
this.moveY) {
      return 
true;
    }
  }
  if (
updateScroll) {
    
this.scrollHeight this.inner.height();
    
this.scrollbar.css('height'this.scrollHeight);
  }
  var 
height this.contHeight();
  if (
height <= this.scrollHeight) {
    
this.scrollbar_inner.hide();
    
this.bottomShadowDiv.hide();
    
this.topShadowDiv.hide();
    
this.topShadow this.bottomShadow false;
    
this.shown false;
    return;
  } else if (!
this.shown) {
    
this.scrollbar_inner.show();
    
this.shown true;
  }

  var 
topScroll this.val();

  var 
progress this.lastProgress Math.min(1topScroll / (height this.scrollHeight));

  if (
progress != (this.topShadow true false)) {
    
this.topShadowDiv[(this.topShadow 'hide' 'show')]();
    
this.topShadow = !this.topShadow;
  }
  if (
progress != (this.bottomShadow true false)) {
    
this.bottomShadowDiv[(this.bottomShadow 'hide' 'show')]();
    
this.bottomShadow = !this.bottomShadow;
  }

  
this.innerHeight Math.max(40Math.floor(this.scrollHeight this.scrollHeight height));
  
this.scrollbar_inner.css({ heightthis.innerHeightmarginTopMath.floor((this.scrollHeight this.innerHeight) * progress) });

  if (
this.options.more && height this.el.scrollTop this.scrollHeight * (this.options.offset || 2)) {
    
this.options.more();
  }
};

/*  */

var checkbox = function(elevent){
  
el = $(el);
  var 
input = $('input'el);
  if (
input.is(':disabled')) return sp(event);
  
el.toggleClass('checked');
  
input.attr('checked'el.hasClass('checked'));
};

var 
radiobox = function(elevent){
  var 
$el = $(el),
      
input = $('input'$el);

  if (
input.is(':disabled')) return sp(event);

  $(
'input[name="' input.attr("name") + '"]').parent().removeClass('checked').find('input').removeAttr("checked");
  
input.attr('checked'true).parent().addClass('checked');
};

// Search
var flySearch = function(opts) {
    var 
self this;
    
self.intervalId 0;
    
self.minLenght 2;
    
self.beforeAjax null;
    
self.onSuccess null;
    
self.onCancel null;
    
self.onError null;

    
self.construct = function() {
        if(!
opts.element) {
            
console.log('Add selector on element to options');
            return;
        }
        if(!
opts.ajaxUrl) {
            
console.log('Add URL on ajaxUrl to options');
            return;
        }

        $.
extend(selfopts);
        
self.wrapper = $(self.element);

        if(
self.wrapper.length == || !self.wrapper.is('input')) {
            
console.log("Wrapper not found or is not input field, check selector in options");
            return;
        }
        if ($.
trim(self.wrapper.val()).length == && !self.wrapper.hasClass('empty')) {
            
self.wrapper.addClass('empty');
        }
    };

    
self.search = function(params) {
        
clearTimeout(self.intervalId);
        var 
text = $.trim(self.wrapper.val());
        if (
text.length self.minLenght) {
            if (
text.length == && !self.wrapper.hasClass('empty')) {
                if (
typeof self.onCancel == 'function') {
                    
self.onCancel();
                }
                
self.wrapper.addClass('empty');
            }
            return;
        }
        
self.wrapper.removeClass('empty');
        
self.intervalId setTimeout(function(){
            var 
ajaxParams = {
                
ajax1,
                
querytext
            
};
            if (
self.ajaxParams) {
                $.
extend(ajaxParamsself.ajaxParams);
            }
            if (
params) {
                $.
extend(ajaxParamsparams);
            }
            if (
typeof self.beforeAjax == 'function') {
                
self.beforeAjax();
            }
            
self.onSearch(ajaxParams);
        }, 
350);
    };

    
self.onSearch = function (params) {
        $.
get(self.ajaxUrlparams, function(res) {
            if (
res && res.ret == 1) {
                if (
typeof self.onSuccess == 'function') {
                    
self.onSuccess(res);
                }
            } else {
                if (
typeof self.onError == 'function') {
                    
self.onError();
                }
                if (
typeof self.onCancel == 'function') {
                    
self.onCancel();
                }
            }
        }, 
'json');
    };

    
self.construct();
};

/**
 fsSelect Module.
 version 1.3
 26.12.2012
 */
var fsSelect = function(opts){
  var 
self this;
  
self.ajaxLock false;
  
self.disabled false;
  
self.bufferText "";

  
self.construct = function(){
    if(!
opts.element) {console.log("Add selector on element to options"); return;}
    if(!
opts.array || opts.array.length == 0) {console.log("Array must have minimum 1 element"); return;}

    $.
extend(selfopts);
    
fsSelect.cache[self.element] = self;
    
self.wrapper = $(self.element);
    if(
self.wrapper.length == 0) {console.log("Wrapper not found, check selector in options"); return;}

    
self.inputValue = $("<input>", {'type''hidden''name'self.name'tabindex': -1});
    
self.header = $("<div>", {'class''form-select-header tr-bg-color-03'}).append('<i class="form-select-down"></i>');
    
self.inputFinder = $("<input>", {
      
'class''form-select-input',
      
'placeholder'self.placeholder self.placeholder ''
    
});
    if(
self.readonlyself.inputFinder.attr('readonly''readonly').addClass('readonly unselectable');
    if(
self.tabIndex) {
        
self.fakeTab = $('<div>', {'tabindex'self.tabIndex'style''height:0;width:0;'}).prependTo(self.wrapper);
        
self.fakeTab.focus(self.showFinder).blur(function(){ if( self.wrapper.hasClass('opened') ){ fsSelect.hideFinder('close'); } });
    }
    
self.header.prepend(self.inputFinder);
    
self.wrapper.append(self.header).append(self.inputValue);
    
self.update();

    
/* events */
    
self.inputFinder.bind('keyup', function(event){return _search(event);});
    
self.inputFinder.bind('keydown', function(event){return _keyEvent(event);});
    
self.inputFinder.bind('focus', function(){self.showFinder();});
    
self.inputFinder.click(function(event){

      if(
self.readonly){
        if( 
self.wrapper.hasClass('opened') ){ fsSelect.hideFinder('close'); }
        else { 
self.showFinder(); }
      } else {
        
self.showFinder(); sp(event);
      }

    });
    
self.header.click(function(event){
      if(
self.wrapper.hasClass('opened')){ fsSelect.hideFinder('close'); }
      else { 
self.showFinder(); }
    });
  };

  
self.change = function(numfromHide){
    var 
buffer self.inputValue.val();
    if(
self.array[num][3]) return;

    for(var 
i in self.array){self.array[i][2] = 0;}
    
self.array[num][2] = 1;
    
self.update();

    if(
self.wrapper.hasClass('opened') && !fromHidefsSelect.hideFinder('close'true);
    if(
typeof(self.onchange) == 'function' && buffer != self.inputValue.val()) self.onchange(self.array[num], self);
  };

  
self.disable = function(){self.disabled trueself.wrapper.addClass('form-select-disabled');self.inputFinder.attr('disabled''true');};
  
self.undisable = function(){self.disabled falseself.wrapper.removeClass('form-select-disabled');self.inputFinder.removeAttr('disabled');};

  
self.update = function(){
    
self.selectedNum null;

    for(var 
i in self.array){ if(self.array[i][2]) self.selectedNum i; }

    if(
self.selectedNum || self.selectedNum == 0) {
      
self.inputFinder.val(self.array[self.selectedNum][1]);
      
self.inputValue.val(self.array[self.selectedNum][0]);
    } else {
      
self.inputFinder.val("");
      
self.inputValue.val("");
    }
  };

  
self.ajaxOn = function(){return self.ajax_url;};
  
self.ajaxData = [];
  
self.ajax = function(){
    if(
self.ajaxLock){return;}

    
self.bufferText self.inputFinder.val();

    var 
params = {queryself.bufferText};

    if(
typeof(self.beforeajax) == 'function'params self.beforeajax(paramsself) ? self.beforeajax(paramsself) : params;

    
self.ajaxLock true;

    
_ajax.post(self.ajax_urlparams, function(htmlstatusdata){
      
self.ajaxLock false;
      if(
typeof(self.onajax) == 'function'data self.onajax(dataself);

      
self.ajaxData data;

      
html self.render(datatrueself.bufferTexttrue);
      
self.finderBox.html(html);

      if(
self.bufferText != self.inputFinder.val()){
        
self.ajax();
      }
    })
  };

  
self.ajaxChange = function(num){
    var 
addFlag true;
    for(var 
i in self.array){
      if(
self.array[i][0] == self.ajaxData[num][0]){
        
self.change(i);
        
addFlag false;
      }
    }
    if(
addFlag){
      
self.array.push([self.ajaxData[num][0], self.ajaxData[num][1], self.ajaxData[num][2], self.ajaxData[num][3]]);
      
self.change(self.array.length 1);
    }
  };

  
self.showFinder = function(){
    if(
fsSelect.current == self.element) {return;}
    if(
self.disabled) {return;}
    else {
      $(
document)
        .
unbind('click'fsSelect.hideFinder)
        .
bind('click'fsSelect.hideFinder);
      var 
offsetPosition self.wrapper.offset(),
        
headerHeight self.header.outerHeight(),
        
headerWidth self.header.outerWidth();

      
fsSelect.current self.element;
      
self.wrapper.addClass('opened');
      
self.finderBox = $("#form-selector-box");
      if(
self.finderBox.length == 0self.finderBox = $('<div>', {'id' :'form-selector-box''onclick' "sp(event)"}).appendTo("#node-heap");

      
self.finderBox.css({
        
'left' offsetPosition.left,
        
'top' offsetPosition.top headerHeight 1,
        
'width' headerWidth 2,
        
'display''block',
        
'z-index': (self.selectIndex self.selectIndex 2)
      }).
html("");

      
self.finderBox.attr('class', (self.myclass self.myclass ''));

      var 
html self.render(self.array);
      
self.finderBox.html(html);
    }
  };

  
self.val = function(){return this.inputValue.val(); }

  
self.render = function(dataisSearchtextisAjaxRender){
    var 
"";
    var 
reSearch = new RegExp('(' text ')''i')
    for(var 
i in data){
      if(!
data[i][3] && ( (isSearch && (reSearch).test(data[i][1])) || !isSearch ) ){
        
r+='<div class="form-selector-item ' +
          ( 
data[i][2] && !isSearch "selected" "") +
          ( 
data[i][3] ? "disabled" "") +
          
'" onclick="fsSelect.cache['' + self.element + ''].' + (isAjaxRender 'ajaxChange' 'change' )+ '(' ');">'+
          (
isAjaxRender ? (isSearch data[i][4].replace(reSearch"<span class='finded'>$1</span>"): data[i][4]) : (isSearch data[i][1].replace(reSearch"<span class='finded'>$1</span>"): data[i][1])) +
          
'</div>';
      }
    }
    if(
r.length == 0) {
      
r='<div class="form-selector-result">Ничего не найдено</div>';
    } else{
      
r=(self.finderTitle '<div class="form-selector-result">' self.finderTitle '</div>' '') + r;
    }
    return 
r;
  };
  
self.destroy = function(){
      
self.inputFinder.off();
      
self.header.off();
      
self.wrapper.empty();
      if(
fsSelect.cache[self.element]){
          
fsSelect.cache[self.element] = null;
          
delete fsSelect.cache[self.element];
      }
  };
  
self.clear = function () {
    
self.inputFinder.val("");
    
self.inputValue.val("");
    
self.array = [];
  };

  var 
_search = function(event){
    var 
inputEl self.inputFinder,
      
inputElVal inputEl.val(), notSearchKeys = [92737383940];
    if(
indexOf(notSearchKeys,event.keyCode) != -1) return;

    if(
inputElVal.length == 0) {
      
self.finderBox.html(self.render(self.array));
    } else {
      if(
self.ajaxOn()){
        
self.ajax();
      } else {
        
self.finderBox.html(self.render(self.array, trueinputElVal));
      }
    }
  };

  var 
_keyEvent = function(event){
    var 
kc event.keyCode;
    if(
kc == 27){
      
fsSelect.hideFinder('close');
    } else if(
kc == 9){
      
fsSelect.hideFinder('close');
    } else if(
kc == 13){
      var 
selectedElement self.finderBox.find('.selected');
      if(
selectedElement){ selectedElement.click();}
      else{
fsSelect.hideFinder('close');}
      return 
false;
    } else if(
kc == 38){
      var 
selectedElement self.finderBox.find('.selected');
      if(
selectedElement){
        
selectedElement.removeClass('selected');
        var 
prev selectedElement.prev();
        if(
prev && prev.hasClass('form-selector-item')){
          
prev.addClass('selected');
          if(
self.finderBox.find('.selected')[0].offsetTop self.finderBox[0].scrollTop) {
            
self.finderBox[0].scrollTop self.finderBox.find('.selected')[0].offsetTop;
          }
        } else {
          
self.finderBox.find('.form-selector-item:last').addClass('selected');
          
self.finderBox[0].scrollTop self.finderBox.height();
        }
      }
      return 
false;
    } else if(
kc == 40){
      var 
selectedElement self.finderBox.find('.selected');
      if(
selectedElement){

        
selectedElement.removeClass('selected');

        var 
next selectedElement.next();
        if(
next && next.hasClass('form-selector-item')){
          
next.addClass('selected');

          if(
self.finderBox.find('.selected')[0].offsetTop self.finderBox.find('.selected').outerHeight() > self.finderBox.height() + self.finderBox[0].scrollTop) {
            
self.finderBox[0].scrollTop = (self.finderBox.find('.selected')[0].offsetTop self.finderBox.height()+ self.finderBox.find('.selected').outerHeight());
          }
        } else {
          
self.finderBox.find('.form-selector-item:first').addClass('selected');
          
self.finderBox[0].scrollTop 0;
        }
      }
      return 
false;
    }
    
sp(event);
  };

  
self.construct();
};

fsSelect.cache = {};
fsSelect.current null;
fsSelect.hideFinder = function(eventforce){
  if((
typeof(event) != 'string' && $(event.target).closest('.form-select-wrap').length == 0) || event == 'close'){
    $(
document).unbind('click'fsSelect.hideFinder);
    var 
currentSelect fsSelect.cache[fsSelect.current], flagFinded false;
    if(!
force){
      if(
currentSelect.ajaxData.length){
          for(var 
i in currentSelect.ajaxData){
              var 
_val currentSelect.inputFinder.val();
              if((new 
RegExp(currentSelect.ajaxData[i][1], 'i')).test(_val) && !currentSelect.ajaxData[i][3] && currentSelect.ajaxData[i][1].length == _val.length){
                  
currentSelect.array.push(currentSelect.ajaxData[i]);
                  
currentSelect.change(currentSelect.array.length 1true);
                  
flagFinded true;
              }
          }
      } else {
          for(var 
i in currentSelect.array){
              if(
currentSelect.array[i][1] == currentSelect.inputFinder.val()){
                  
currentSelect.change(itrue);
                  
flagFinded true;
              }
          }
      }
    }

    if(!
flagFinded){currentSelect.update();}
    
currentSelect.inputFinder.blur();
    
currentSelect.finderBox.html("").hide();
    $(
'.form-select-wrap').removeClass('opened');
    
fsSelect.current null;
  }
};

var 
userLogoutFunction = function(){
    var 
link '/user/logout/',
        
header 'Вы уверены, что хотите выйти?',
        
confirm 'Если вы нажмёте &laquo;Да&raquo;, то в следующий раз вам придётся заново вводить логин и пароль.';

        
iPopup.confirm(confirm, [{
            
callback: function(){
                
contextNav.clear();
                
location.href link;
            }
        }],
            { 
titleheader }
        );
    return 
false;
};

var 
showConfirmEmailPopup = function(contentcallback) {
    if (
typeof content != "undefined" && content) {
        
iPopup.open(content, {'title''Подтвердите ваш e-mail'style: {'width'450myclass'font-large'} , noOverlayClose:trueonopen: function(){ emp.init(); $('#user_email').focus();},
            
onclose: function(){ if(typeof callback != 'undefined'callback(); }});
    } else {
        $.
post('/userinfo/ajax/confirmEmailPopup/', {ajax1}, function (data) {
            
iPopup.open(data, {'title''Подтвердите ваш e-mail'style: {'width'450myclass'font-large'} , noOverlayClose:trueonopen: function(){ emp.init(); $('#user_email').focus();},
                
onclose: function(){ if(typeof callback != 'undefined'callback();}});
        });
    }
};

var 
showConfirmPhonePopup = function(contentcallback) {
    if ((
typeof content != "undefined") && content) {
        
iPopup.open(content, {'title''Подтвердите телефон'style: {'width'630myclass'phone-reminder-popup'} , noOverlayClose:trueonopen: function(){ return true; },
            
onclose: function(){ if(typeof callback != 'undefined'callback();}});
    } else {
        $.
post('/userinfo/ajax/confirmPhonePopup/', {ajax1}, function (data) {
            
iPopup.open(data, {'title''Подтвердите телефон'style: {'width'630myclass'phone-reminder-popup'} , noOverlayClose:trueonopen: function(){ return true; },
                
onclose: function(){ if(typeof callback != 'undefined'callback();}});
        });
    }
};

var 
showUploadMainPhotoPopup = function() {
    
userpic.showUploadPopupNewFs2(24, function() {location.reload(true);});
};

var 
showMailPhoneReminderPopup = function(purposecallback){
    $.
post('/profile/reminder/reminder/', { ajaxtruepurposepurpose }, function (res) {
        if(
res.type == 'phone')
            
showConfirmPhonePopup(res.html);
        else if (
res.type == 'email')
            
showConfirmEmailPopup(res.html);
    });
};

var 
selectAgePopup = {
    
isIncClosetrue,
    
save: function () {
        var 
data = {
            
'section''user_birthday',
            
'source''selectAgePopup',
            
'birth-day': $('#userinfo-user-birthday input[name=birth-day]').val(),
            
'birth-month': $('#userinfo-user-birthmonth input[name=birth-month]').val(),
            
'birth-year': $('#userinfo-user-birthyear input[name=birth-year]').val(),
            
'privacy-filter': $('.birthday-year-privacy .dropdown-item-title a').data('filter')
        };

        if (
data['birth-day'] == '0' || data['birth-month'] == '0' || data['birth-year'] == '0') {
            
fs.notify('Укажите корректную дату рождения.');
        } else {
            $.
post('/userinfo/ajax/saveuserinfo'data);
            if (!(
typeof(currentUser.userAge) == 'undefined')) {
                var 
= new Date(),
                    
cd = new Date();
                
d.setFullYear(data["birth-year"], data["birth-month"]-1data["birth-day"]);
                
currentUser.userAge Math.floor((cd.getTime()-d.getTime()) / 31556926000);
            }
            
this.isIncClose false;
            
iPopup.close();
        }
    },
    
open: function () {
        $.
post('/userinfo/ajax/selectAgePopup/', function (data) {
            
iPopup.open(data.html, {
                
title'Когда у вас День Рождения?',
                
style: {
                    
width580,
                    
myclass'select-age-popup-wrapper'
                
},
                
onopen: function() { return true; },
                
onclose: function() {
                    if (!
selectAgePopup.isIncClose) {
                        return 
true;
                    }
                    var 
mainStat = new _jstat('Main');
                    
mainStat.add('select_age_popup_close'1);
                    
mainStat.send();
                    return 
true;
                },
                
footer'<div style="text-align: center"><span style="margin: 0; float: none;" class="ibtn ibtn-blue ibtn-big" onclick="selectAgePopup.save()">Жду поздравлений!</span></div>'
            
});
        });
    }
};

/**
 * Namespace for VIP-related functions
 */
var fs2vip = {
    
// Vip2 popup for buing
    
popupVipBuying: function(serviceTypebonusonCancelFncforUserIdonBuyVipFncrefAppId) {
        if (
isVip2Available) {
            
_ajax.post('/vip2/ajax/getConfig/', {}, function(htmlstatusdata) {
                
staticManager.add(data.modules.buying.jsdata.modules.buying.css, function () {
                    
vip.modules.buying.init({billingdata.billinguserdata.user}, onBuyVipFnc, {serviceTypeserviceType});
                    
vip.modules.buying.popup.open({
                        
render: {
                            
buying: {},
                            
compare: {
                                
modClass'h',
                                
servicesdata.services
                            
},
                            
period: {
                                
modClass'h'
                            
}
                        }
                    });
                });

                $.
get('/vip2/ajax/incr/', {field'popup_summ_show'eRfnav2.getParam('eRf')});
            });
            return;
        }

        if (!
window.currentUser || !window.currentUser.userId) {
            
fs.notify (fsLang.get('login_need'));
            return;
        }
        if (!
bonusbonus 0;
        if (!
forUserIdforUserId 0;
        
onSimpleBuyVipFnc onBuyVipFnc;

        var 
onbeforeunloadBinded false;
        var 
vipPBuyClickedOnly false;
        var 
entrance 0;
        if (
window.entranceMeetingFS12 !== undefined) {
            
entrance fsNow() - window.entranceMeetingFS12 <= 30000 0;
        }

        if (
serviceType == || serviceType == || serviceType == || serviceType == 32 || serviceType == 40 || serviceType == 49 || serviceType == 52 || serviceType == 14) {
            var 
closeSaveClicked false;
            if (
window.nav2) {
                
nav2.gc(function(){
                    $(
document).unbind('click.meetingSaveClicked');
                    if (
typeof onbeforeunloadBinded != 'undefined' && onbeforeunloadBinded) {
                        
window.onbeforeunload null;
                    }
                });
            }
        }

        
_ajax.post('/vip/ajax/popupbuy/', {'ajax':trueentranceentranceserviceType:serviceTypebonusBuy:bonusforUserId:forUserIdrefAppId:refAppId}, function (data){
            
iPopup.open(data, {titlefsLang.get('vip_account'), style: {width760myclass'vip-popup-buyingwrap'}, noOverlayClosetrue,
                
onopen: function () {
                    if (
serviceType == || serviceType == || serviceType == || serviceType == 32 || serviceType == 40 || serviceType == 49 || serviceType == 52 || serviceType == 14) {
                        $(
'#iPopup .icn-close').attr('onclick''event.stopPropagation(); iPopup.close();');
                        $(
document).bind('click.meetingSaveClicked', function (e) {
                            
vipPBuyClickedOnly false;
                            if( $(
e.target).parents('.vip-p-card-1, .vip-p-card-2, .vip-p-card-3').length ) {
                                $.
get('/vip/ajax/saveclosedmeeting/?type=buy');
                                
vipPBuyClickedOnly true;
                            }

                            if( $(
e.target).hasClass('vip-p-corner') || $(e.target).parents('.vip-p-corner').length ) {
                                $.
get('/vip/ajax/saveclosedmeeting/?type=36month');
                                
vipPBuyClickedOnly true;
                            }

                            if( $(
e.target).hasClass('btn-free-vip') || $(e.target).parents('.btn-free-vip').length ) {
                                $.
get('/vip/ajax/saveclosedmeeting/?type=freevip');
                                
vipPBuyClickedOnly true;
                            }

                            
closeSaveClicked true;
                        });
                        if (
window.onbeforeunload !== null) {
                            
window.onbeforeunload = function(){ $('<img>').attr('src''/vip/ajax/saveclosedmeeting/?type=browser'); };
                            
onbeforeunloadBinded false;
                        }
                    }
                },
                
onclose: function (){
                if (
typeof vipClub !== 'undefined') {
                    
vipClub.sendStat('close');
                }
                if ($.
isFunction (onCancelFnc)) onCancelFnc();
                if (
serviceType == || serviceType == || serviceType == || serviceType == 32 || serviceType == 40 || serviceType == 49 || serviceType == 52 || serviceType == 14) {
                    if (
typeof closeSaveClicked != 'undefined') {
                        if (
closeSaveClicked === false) {
                            $.
get('/vip/ajax/saveclosedmeeting/?type=popup');
                        }
                        if (
vipPBuyClickedOnly) {
                            $.
get('/vip/ajax/saveclosedmeeting/?type=closebuy');
                        }
                        $(
document).unbind('click.meetingSaveClicked');
                        
window.onbeforeunload null;
                    }
                }
            }});
        });
    },
    
popupVip2Buying: function (datacallbackcanSelectPeriod) {
        
_ajax.post('/vip2/ajax/getConfig/', {}, function(htmlstatusresp) {
            
staticManager.add(resp.modules.buying.jsresp.modules.buying.css, function () {
                
vip.modules.buying.init({billingresp.billinguserresp.user}, callbackdata);

                
//если юзер вип (не бесплатный), показываем попап с апгрейдом
                
if (currentUser.userVipLevel && currentUser.userVipLevel != (data && data.vipType)) {
                    
vip.modules.buying.upgrade.showProfitPopup((data && data.vipType) ? data.vipType currentUser.userVipLevel, !!(data && data.vipType), canSelectPeriod);
                    return;
                }

                
//если юзер не вип (или бесплатный), показываем попап с покупкой
                
vip.modules.buying.popup.open({
                    
render: {
                        
buying: {
                            
modClass: (data && data.hideScreen && data.hideScreen.indexOf('buying') != -1) ? 'h' ''
                        
},
                        
compare: {
                            
modClass: (data && data.hideScreen && data.hideScreen.indexOf('compare') != -1) ? 'h' '',
                            
servicesresp.services
                        
},
                        
period: {
                            
modClass: (data && data.hideScreen && data.hideScreen.indexOf('period') != -1) ? 'h' ''
                        
}
                    }
                });
            });

            var 
fields 'popup_summ_show';
            if (
data && data.vipType && currentUser.userVipLevel && currentUser.userVipLevel != data.vipType) {
                var 
ps data.purchaseSource data.purchaseSource 0;
                
fields = ['popup_summ_show''upgrade_shows_' data.vipType '_' ps];
            }
            $.
get('/vip2/ajax/incr/', {fieldfieldseRfnav2.getParam('eRf')});
        });
    },
    
// Vip popup subscribe
    
vipPopupSubscribe: function (paysnotify) {
        var 
widthPopup notify 600 950;
        $.
post("/vip/ajax/popupsteps", {ajax1payspaysnotify:notify}, function(data){
            
iPopup.open(data, {title"Подписка на VIP-статус"style: {widthwidthPopup}})
        })
    },
    
popupVipInvisiblePromo: function () {
        
_ajax.get('/vip/ajax/popuptryinvisible/', {}, function(html){
            
iPopup.open(html, {title'Режим «Невидимка»'style: {width550}});
        });
    },
    
setVipInvisibleStatus: function (status) {
        $.
post('/vip/ajax/paramguest/', {'ajax'truestatusstatus}, function() {
            
iPopup.close();
        });
    },

    
vipEndTodayPopup: function(){
        
_ajax.get('/vip2/ajax/vipEndToday/', {}, function (htmlstatusdata) {
            
popup iPopup.open(html, {
                
titledata.title,
                
//footer: '<span class="ibtn ibtn-blue discount-ibtn" onclick="iPopup.close();">Хорошо</span>',
                
style: {
                    
myclassdata.css_class,
                    
width560
                
}
            });
        });
    },
    
/**
     * Попап покупки випа из других сервисов (при тыке на функционал, требующий випа)
     *
     * Краткий вариант вызова:
     * fs2vip.buyPopup(featureId, opts);
     *
     * Расширенный вызов:
     * fs2vip.buyPopup({
     *     featureId: featureId,
     *     vipLevel: vipLevel,
     *     vipPeriod: vipPeriod,
     *     purchaseSource: purchaseSource,
     *     serviceType: serviceType,
     *     ... // любые кастомные поля, которые будут как-то по-особому обрабатываться на бекенде
     * }, opts);
     *
     * Все параметры опциональны.
     *
     * opts: {
     *     callback: function () {} // коллбек, вызываемый по завершению покупки випа
     * }
     */
    
buyPopup: {
        
popupnull,
        
selectsnull,
        
level0,
        
period0,
        
optsnull,
        
datanull,
        
open: function (dataoptsparams) {
            var 
_this this;
            if (
typeof data != 'object') {
                
data = {
                    
featureIddata
                
}
            }
            
this.opts opts || {};
            
this.params params || {};

            
_ajax.get('/vip2/ajax/buyPopup/', $.extend({ eRfnav2.getParam('eRf') }, data), function (htmlstatusdata) {
                $.
extend(_this.paramsdata.fsBuyParams);
                
_this.popup iPopup.open(html, {
                    
titledata.title,
                    
style: {
                        
myclassdata.css_class,
                        
width630
                    
},
                    
onopen: function (popup) {
                        if (
data.vipConfig && data.vipConfig.length 1) {
                            
_this.createSelects(datapopup);
                        }
                        $.
extend(_this.datadata);

                        
nav2.gc(function () {
                            for (var 
select in _this.selects) {
                                
_this.selects[select].destroy();
                            }
                            
_this.selects null;
                        }, 
'vipBuyPopup');
                    },
                    
onclose: function () {
                        
_this.popup null;
                        
_this.opts null;
                    }
                });
            });
        },
        
init: function (data) {
            var 
_this this;
            
this.data data;
            if (
this.data.reload && !this.opts.callback) {
                
this.opts.callback = function () {
                    
document.location typeof _this.data.reload == 'string' _this.data.reload document.location;
                };
            }
        },
        
createSelects: function (datapopup) {
            if (!
data || !data.vipConfig) return;

            var 
_this this;

            
this.selects = {};
            for (var 
level_i 0level_l data.vipConfig.lengthlevelselectArraylevel_i level_l; ++level_i) {
                
level data.vipConfig[level_i];
                
selectArray = [];
                for (var 
period_i 0period_l level.periods.lengthperiodisSelectedperiod_i period_l; ++period_i) {
                    
period level.periods[period_i];
                    
isSelected period_i == && period.period data.vipSelectedPeriod || period.period == data.vipSelectedPeriod;
                    
selectArray.push([period.periodperiod.title ' - ' period.price ' ФМ'isSelected0]);
                }
                if ($(
'#vip-buy-level-' level.level '-period').length) {
                    
this.selects[level.level] = new fsSelect({
                        
element'#vip-buy-level-' level.level '-period',
                        
name"vip-period",
                        
readonlytrue,
                        array: 
selectArray,
                        
selectIndexMath.floor(popup.wrapper.css('z-index'))+1
                    
});
                }
            }
        },
        
nextStep: function () {
            if (
this.popupthis.popup.inner.find('.vip-buy-step.active').removeClass('active').next().addClass('active');
        },
        
getPeriod: function (level) {
            if (
this.data.vipConfig.length 1) { // У нас несколько випов на выбор
                
return this.selects[level].val();
            } else {
                return 
this.data.period;
            }
        },
        
setPeriod: function (period) {
            
this.data.period period;
        },
        
buyClick: function (levelperiodparams) {
            
// инициализируем модуль покупки непосредственно перед самой покупкой, чтобы быть уверенными, что никакой другой попап не успел переинитить его.
            
vip.modules.buying.init(nullthis.opts.callback, {
                
purchaseSourcethis.data.purchaseSource,
                
serviceTypethis.data.serviceType
            
});

            
level level || this.data.level;
            
period period || this.data.period;

            
vip.modules.buying.buy($.extend({}, this.paramsparams, {
                
typelevel,
                
subtypeperiod
            
}));
        }
    },
    
showComparePopup: function() {
        
_ajax.get('/vip2/ajax/comparePopup/', {}, function (htmlstatusdata) {
            
vip.modules.buying.init(data);
            
vip.modules.buying.popup.open({
                
render: {
                    
buying: {
                        
modClass'h'
                    
},
                    
compare: {
                        
modClass'vip-m-only-compare',
                        
servicesdata.services
                    
},
                    
period: {
                        
modClass'h'
                    
}
                }
            });
        }, 
'json');
    },
    
freeVipPopup: function () {
        
_ajax.post('/invites/vip/vipactpopup/', {ajax1toOwnPopup1serviceType1},
            function (
htmlstatusresp) {
                if (
typeof(html) != "undefined" && html) {
                    
iPopup.open(html,
                        {
                            
title'VIP-статус бесплатно',
                            
style: {width550myclass'meeting-p-blue'},
                            
onopen: function () {
                                
vipForInvitesPopup.socBtnsInit();
                                
actInvite.init();
                                
actInvite.checkAllChecks();
                            },
                            
onclose: function () {
                                
actInvite.pSt(actInvite.closeType);
                            }
                        }
                    );
                }
            }
        );
    }
};
// Aliases for deprecated calls.
var popupVipBuying = function () {
    
// Not deprecated yet because old calls are not replaced by new ones
    
fs2vip.popupVipBuying.apply(fs2viparguments);
};
var 
popupVip2Buying = function () {
    if(
typeof customJsLog === 'function'){ customJsLog('popupVip2Buying deprecated call'); }
    
fs2vip.popupVip2Buying.apply(fs2viparguments);
};
var 
vipPopupSubscribe = function () {
    if(
typeof customJsLog === 'function'){ customJsLog('vipPopupSubscribe deprecated call'); }
    
fs2vip.vipPopupSubscribe.apply(fs2viparguments);
};
var 
popupVipInvisiblePromo = function () {
    if(
typeof customJsLog === 'function'){ customJsLog('popupVipInvisiblePromo deprecated call'); }
    
fs2vip.popupVipInvisiblePromo.apply(fs2viparguments);
};
var 
setVipInvisibleStatus = function () {
    if(
typeof customJsLog === 'function'){ customJsLog('setVipInvisibleStatus deprecated call'); }
    
fs2vip.setVipInvisibleStatus.apply(fs2viparguments);
};

/**
 * user age popup
 */

var userageFs2 = {
    
oknull,
    
cancelnull,
    
showSetAgePopup: function(reasonIdcallbackOkcallbackCancel){
        
userage.ok callbackOk;
        $.
post("/userinfo/ajax/setAgePopup",{ajax:true,reasonId:reasonId},function(data){
            
iPopup.open(data,{title:'Укажите возраст'style: {width:545myclass'useragepopup'},footer'<span class="ibtn ibtn-blue" onclick="saveBirthDay()">Сохранить</span>'onclose:function(){userage.closePopup(callbackCancel)}});
        });
    },
    
closePopup: function(c){ if ($.isFunction(c)) c(); }
};

var 
showUploadPhotoPopup = function (albumIdreasoncustomcallbacksourcefield) {
    if($(
'body').hasClass('fs-1')){
        
window.open'/user/'+currentUser.userId+'/?uploadPhoto=1''_blank');
        return 
true;
    }
    var 
userId 0;
    var 
galleryId 0;
    var 
imageId 0;

    if (
custom) {
        
userId custom.userId custom.userId 0;
        
galleryId custom.galleryId custom.galleryId 0;
        
imageId custom.imageId custom.imageId 0;
    }

    
_ajax.get('/userphoto/ajax/uploadphotopopup/', {albumIdalbumIdreason:reasongalleryIdgalleryIduserIduserIdimageIdimageIdsourcesourcefieldfield}, function(htmlstatusdata) {
        if (
status === 'ok') {
            if (!
albumId) {
                
title 'Загрузка личных фотографий';
            } else {
                
title 'Загрузка фотографий';
            }

            var 
= $(html);
            
iPopup.open(a.slice(01).html(), { titletitlestyle: {width500}, onopen: function () {
                $(
'.iPopup:last').append(a.slice(1));
                var 
offset parseInt($('#popupWin').css('top'));
                var 
offsetY offset 150;
                if(
typeof callback != 'undefined') {
                    
callback();
                }
            }, 
onclose: function(){
                $(
'#button-go-photo-album:visible *').click();
                if(
typeof clickStat != 'undefined')
                    
clickStat('closechild');
            } });
        } else {
            if (
status === 'no_phone') {
                
showConfirmPhonePopup();
            } else if (
status === 'no_email') {
                
showConfirmEmailPopup();
            } else if (
status === 'is_banned') {
                
popup.simple('<h4>Вы сможете загрузить фотографии после окончания блокировки Вашего профиля.</h4>');
            } else if (
status === 'select_album') {
                
userpic.selectPersonalAlbum();
            } else if (
status === 'no_album') {

            } else if (
status === 'no_main_photo') {
                
// 50 = FIELD_UPLOADER_SOURCE_AVATAR_NEW
                
userpic.showUploadPopupNewFs2(21, function () { location.reload(true) }, function() {}, 050);
            }
        }
    });
};

var 
showUploadPhotoPopupWithSource = function (fieldalbumIdreasoncustomcallbacksource) {
    
showUploadPhotoPopup(albumIdreasoncustomcallbacksourcefield);
};


/* complaint */

var complaintPopup = {
    
add: function(typeiddatareasonemail) {
        
email typeof email != 'undefined' email '';
        $.
post('/support/complaint/add/', { ajaxtruetypetypeididdatadatareasonreasonemailemail }, function(response) {
            if (
parseInt(response.accepted)) {
                
fs.notify('Твоя жалоба принята к рассмотрению');
            }
        });
    },

    
showForm: function(typeiddata) {
        $.
post('/support/complaint/popup/', { ajaxtruetypetypeididdataunescape(data) }, function(response) {
            if (
response.html) {
                
iPopup.open(response.html, {
                    
titleresponse.title,
                    
footer'<a href="/security/?from=context" target="_blank">Сделаем Фотострану безопаснее вместе</a>',
                    
noOverlayClosetrue,
                    
noOverlayfalse,
                    
noFormattingfalse,
                    
style: {
                        
width700,
                        
top_offsetfalse
                    
}
                });
            }
        });
    }
};

/**
 * Right Tabs (31.10.2012)
 *
 * @param element кнопка открытия/закрытия блока с содержимым
 * @param contentBlock блок для вывода содержимого
 */
var rightTabDropMenu = {
    
currConfignull,
    
click: function(elementeventconfig){
        
rightTabDropMenu.toggle(elementconfig);
        
sp(event);
    },
    
open: function (elementconfig) {
        
rightTabDropMenu.closeAll();

        
rightTabDropMenu.currConfig config;

        
element = $(element);
        
element.addClass('on');
        
element.find('.tab-content-wrap').stop(true).show().css('opacity'0).fadeTo(3001);

        $(
document).bind('click'rightTabDropMenu.closeAll);

        if (
rightTabDropMenu.currConfig && typeof rightTabDropMenu.currConfig.onOpen == 'function') {
            
rightTabDropMenu.currConfig.onOpen();
        }
    },
    
close: function (element) {
        if (
element) {
            
element = $(element);
            
element.removeClass('on');
            
element.find('.tab-content-wrap').stop(true).fadeTo(2000, function () { $(this).hide(); });
        }

        $(
document).unbind('click'rightTabDropMenu.closeAll);

        if (
rightTabDropMenu.currConfig && typeof rightTabDropMenu.currConfig.onClose == 'function') {
            
rightTabDropMenu.currConfig.onClose();
        }

        
rightTabDropMenu.currConfig null;
    },
    
closeAll: function () {
        
rightTabDropMenu.close();

        $(
'#setting-tabs .tab-name').removeClass('on');
        $(
'#setting-tabs .tab-content-wrap').stop(true).fadeOut(200);
    },
    
toggle: function (elementconfig) {
        if(
rightTabDropMenu.isOpened(element)) {
            
rightTabDropMenu.close(element);
        } else {
            
rightTabDropMenu.open(elementconfig);
        }
    },
    
isOpened: function (element) {
        return $(
element).hasClass('on');
    },
    
setContent: function (tabcontent) {
        var 
container = $('.tab-content'element);
        
container.children().not('.fs-ie-pseudo').remove();
    },



    
/**
     * Новости друзей. Импорт новостей из ВК  (31.10.2012)
     */
    
loadNewsfeedVk: function (tabevent){
        
rightTabDropMenu.click(tabevent, {
            
onOpen: function () {
                
newsfeed.vkImport.vkImportPopupFs2('newsfeed', $('.tab-content'tab));
            },
            
onClose: function () {
              $(
'.tab-content'tab).html('');
            }
        });
    },

    
/**
     * Новости друзей. Настройки  (31.10.2012)
     */
    
loadNewsfeedSettings: function(tab,event,type){
        
rightTabDropMenu.click(tabevent, {
            
onOpen: function () {
                $.
get("/newsfeed/ajax/settingsDialog/",{ajax:1type:type}, function(settingsHTML) {
                    $(
'.tab-content'tab).html(settingsHTML);
                });
            }
        });
    },

    
/**
     * Лучшие фотографии. Настройки  (31.10.2012)
     */
    
loadPhototopSettings:function(tab,event,type){
        
rightTabDropMenu.click(tabevent, {
            
onOpen: function () {
                $.
get("/newsfeed/ajax/settingsDialog/",{ajax:1type:type}, function(settingsHTML) {
                    $(
'.tab-content'tab).html(settingsHTML);
                });
            }
        });
    },

    
/**
     * Пакмен. Настройки  (31.10.2012)
     */
    
loadPacmanSettings:function(tabevent){
        
rightTabDropMenu.click(tabevent, {
            
onOpen: function () {
                var 
content = $('.tab-content'tab);
                
content.html('<div class="tab-preloader"><i class="icn icn-process"></i></div>');
                $.
get("/pacman/ajax/appsSettings/",{ ajax}, function(settingsHTML) {
                    
content.html(settingsHTML.content);
                });
            }
        });
    }
};

(function (
dragndrop) {
    var 
startOffset 5,
        
classAdded,
        
started false,
        
startXstartY,
        
dxdy,
        
dropTargetSelector,
        
dropTargetdropTargetPosdropTargetWdropTargetH,
        
elementelementPoselementWelementH,
        
maxWmaxH,
        
dropCallbackFn;

    var 
checkDrag = function (e) {
        if (
started || Math.abs(e.clientX startX) > startOffset || Math.abs(e.clientY startY) > startOffset) {
            if (!
started) {
                
startDrag();
            }
            
elementPos = {
                
lefte.pageX dx,
                
tope.pageY dy
            
};
            
element.offset(elementPos);
            if (
intersects()) {
                
dropTarget.addClass('dragndrop-target-active');
            } else {
                
dropTarget.removeClass('dragndrop-target-active');
            }
        }
    }, 
startDrag = function () {
        
started true;

        
element = $(element);

        var 
startPos element.offset();
        
dx startX startPos.left;
        
dy startY startPos.top;
        
dropTarget = $(dropTargetSelector);
        
dropTargetPos dropTarget.offset();
        
dropTargetW dropTarget.width()/2;
        
dropTargetH dropTarget.height()/2;
        
elementW element.width()/2;
        
elementH element.height()/2;
        
maxW elementW dropTargetW;
        
maxH elementH dropTargetH;

        
element.addClass('dragndrop-elem-dragging');
        if (!
element.hasClass('unselectable')) {
            
element.addClass('unselectable');
            
classAdded true;
        }
        
element.bind('click.dragndrop', function (e) {
            
pd(e);
            
sp(e);
        });

        $(
'body').css('cursor''move');
    }, 
intersects = function () {
        var 
x1 elementPos.left elementW,
            
y1 elementPos.top elementH,
            
x2 dropTargetPos.left dropTargetW,
            
y2 dropTargetPos.top dropTargetH;

        if (
Math.abs(y1 y2) < maxH) {
            return 
Math.abs(x1 x2) < maxW;
        }
        return 
false;
    }, 
deselectText = function () {
        if (
document.selection) {
            
document.selection.empty();
        } else if (
document.getSelection) {
            
document.getSelection().removeAllRanges();
        }
    };

    
dragndrop.start = function(elemeventdropSelectordropCallback) {
        
dragndrop.stop();
        
deselectText();
        
pd(event);
        
sp(event);

        
element elem;
        
startX event.pageX;
        
startY event.pageY;
        
dropTargetSelector dropSelector;
        
dropCallbackFn dropCallback;

        $(
'body').addClass('unselectable');

        $(
document).bind('mousemove.dragndrop', function (e) {
            
checkDrag(e);
        }).
bind('mouseup.dragndrop', function (e) {
            
dragndrop.stop();
        });
    };
    
dragndrop.stop = function() {
        $(
document).unbind('.dragndrop');
        $(
'body').removeClass('unselectable');

        if (
started) {
            $(
'body').css('cursor''');

            if (
classAdded) {
                
element.removeClass('unselectable');
            }
            var 
elCached element;
            
setTimeout(function () {
                
elCached.unbind('click.dragndrop');
                
elCached null;
            }, 
10); // hack чтобы успел отработать click и попасть в обработчик, где отменится дефлотное поведение. Нужно, чтобы тык по ссылкам во время драгндропа не срабатывал.

            
if (dropTarget) {
                
dropTarget.css('opacity''');
            }

            if (
intersects()) {
                if (
dropCallbackFn) {
                    
dropCallbackFn(elementdropTarget);
                }
            } else {
                
dragndrop.cancelDragging(element);
            }

            
started false;
            
element null;
            
dropTarget null;
            
dropCallbackFn null;
        }
    };
    
dragndrop.cancelDragging = function(element) {
        if (!
element instanceof jQuery) {
            
element = $(element);
        }
        
element.removeClass('dragndrop-elem-dragging');
        
element.css({
            
left'',
            
top''
        
});
    };
})(
window.dragndrop = {});

var 
topper = new function(){
  var 
self this,
      
sideHeight 0bufferTop 0toUp truetoUpEl nulltoUpSide nullwidthContent null;

  
self.init = function(){
    
self.update();
    
toUpEl = $('#topper-block');
    
toUpSide = $('#topper-side');

    $(
window).bind('resize'self.checkWidth).bind('scroll'topper.onScroll);
    
self.checkWidth();
  };
  
// update method
  
self.update = function(){
    
sideHeight ge('side-content') ? ge('side-content').clientHeight 0;
  };

  
self.onScroll = function(){
    var 
delta fs.scrollTop sideHeight;
    
toUpSide.hide();
    if(
delta 0) {
      
toUpEl.addClass('on').removeClass('to-bottom');
      if(!
toUptoUpEl.html('<div class="topper-inner">Наверх <i class="icn icn-gray icn-up"></i></div>');
      
toUp true;
    } else if(
delta && !toUp) {
      
toUpEl.addClass('on to-bottom').html('<div class="topper-inner"><i class="icn icn-gray icn-down"></i></div>');
      
toUpSide.show().css({
        
'top' : -delta 55
      
})
    } else if(
delta 0) { toUpEl.removeClass("on to-bottom"); }
  };

  
self.onClick = function(){
    if(
toUp) {
      
bufferTop fs.scrollTop;
      $(
window).scrollTop(0);
      
toUp false;
      
toUpEl.html('<div class="topper-inner"><i class="icn icn-gray icn-down"></i></div>');
    } else {
      $(
window).scrollTop(bufferTop);
      
toUp true;
      
toUpEl.html('<div class="topper-inner">Наверх <i class="icn icn-gray icn-up"></i></div>');}
  };

  
self.checkWidth = function(){
    var 
width document.documentElement.clientWidth;
    
toUpEl[((width 1290 && width 1240) || (width 1070) ? 'add' 'remove') + 'Class']('to-bottom-hide');
    if(
width 1024){
      
toUpEl.attr('style''margin: 0 ' + (width/170) + 'px 0 0; top: 0');
      
toUpSide.attr('style''margin: 0 ' + (width/170) + 'px 0 0;');
    } else {
      
toUpEl.removeAttr('style');
    }
  };

  
self.sideOver = function(){toUpEl.addClass('hover');};
  
self.sideOut = function(){toUpEl.removeClass('hover');};

  
self.clear = function(){ $(toUpEl).removeClass('on with-menu').html('<div class="topper-inner">Наверх <i class="icn icn-gray icn-up"></i></div>'); toUp true; $(toUpSide).hide();};
  
self.destroy = function(){ self.clear(); $(window).unbind('resize'self.checkWidth).unbind('scroll'topper.onScroll);}
};

messageFormEventer = new Eventer({ eventPrefix'' });
(function () {
    var 
MessageForm window.MessageForm = function (uidconfig) {
        if (
arguments[0]) {
            
this.uid uid;
            
this.init(config);
        }
    };
    var 
proto MessageForm.prototype = {};
    
proto._defaultConfig = {
        
expandedClass       'message-form-expanded',
        
hasTextClass        'message-form-has-text',
        
enabledClass        'message-form-enabled',
        
saveButtonSelector  '.message-form-save-btn',
        
textAreaSelector    '.message-form-text',
        
limitTextSelector   '.message-form-limit',
        
placeholderSelector '.message-form-placeholder',
        
smilesBtnSelector   '.message-form-smiles',
        
attachPhotoBtnSelector   '.message-form-photo',
        
attacherId          'message-form-attacher',
        
attacherFormId      'message-form-form',
        
negativeLimitClass  'message-form-limit-negative',
        
btnDisabledClass    'btn-disabled',
        
additionalContentEnabled   false,
        
additionalDataCache : [],
        
additionalDataSelector '.message-form-attachments',
        
textLimit           280
    
};
    
proto.applyConfig = function (config) {
        $.
extend(thisthis._defaultConfigconfig);
    };
    
proto.getContainer = function () {
        if (
this.uid) {
            
this.container = $('#messageForm'+this.uid);
        }
    };
    
proto.init = function (config) {
        var 
me this;

        
this.applyConfig(config);

        
this.getContainer();

        
this.container.bind('mousedown', function (event) {
            
cancelEvent(event);
            return 
false;
        });

        
this.textArea this.container.find(this.textAreaSelector);
        
this.textArea.removeAttr('ondrop');
        
this.textArea.removeAttr('keydown');
        var 
fn = function () {
                
me.onChange();
            },
            
delayedFn = function () {
                
setTimeout(fn0);
            };
        
this.textArea.bind('change'fn);
        if(
this.additionalContentEnabled){
            
this.textArea.bind('paste', function(){ st( function(){ me.parseLinks.call(me); }, 0); });
            
this.textArea.bind('cut drop keydown'delayedFn);
        } else {
            
this.textArea.bind('cut paste drop keydown'delayedFn);
        }
        
this.textArea.bind('mousedown', function (event) {
            
sp(event);
        });

        
this.saveButton this.container.find(this.saveButtonSelector);

        
this.limitText this.container.find(this.limitTextSelector);

        
this.placeholder this.container.find(this.placeholderSelector);

        
this.smilesBtn this.container.find(this.smilesBtnSelector);

        
this.attachPhotoBtn this.container.find(this.attachPhotoBtnSelector);

        if(
this.additionalContentEnabled)
            
this.additionalDataContainer this.container.find(this.additionalDataSelector);

        
this._saveCheckFn();
    };
    
proto._makeFakeTextarea = function () {
        if (
this.textAreaFake) return;
        
this.textAreaFake this.textArea.clone();
        
this.textAreaFake
            
.removeAttr('name onfocus onblur onkeydown ondrop oncut onpaste id')
            .
css({
                
position'absolute',
                
visibility'hidden',
                
height'auto',
                
padding0
            
});
        
this.textArea.after(this.textAreaFake);
    };
    
proto._removeFakeTextarea = function () {
        if (!
this.textAreaFake) return;
        
this.textAreaFake.remove();
        
this.textAreaFake null;
    };
    
proto._saveFn = function () {
        
console.warn('MessageForm._saveFn is an abstract method and must be overriden');
    };
    
proto.save = function () {
        if (
this.checkSave()) {
            
this.disable();
            
this.textArea.attr('disabled'true);
            
this._saveFn();
        }
    };
    
proto.checkSave = function () {
        if (!
this.isEnabled()) return false;
        if (
this.textLimit && this.get(true).length this.textLimit) {
            
fs.notify('Максимальный объём текста превышен');
            return 
false;
        }
        return 
true;
    };
    
proto.setLimitText = function () {
        if (
this.limitText.length) {
            var 
this.textLimit this.get().length;
            if (
0) {
                
= -d;
                
this.limitText.addClass(this.negativeLimitClass);
                
this.limitText.text('Объём превышен на ' fs.plural(d' символ'' символа'' символов'));
            } else {
                if (
15) {
                    
this.limitText.removeClass(this.negativeLimitClass);
                    
this.limitText.text(fs.plural(d'Остался '+d+' символ''Осталось '+d+' символа''Осталось '+d+' символов'));
                } else {
                    
this.limitText.empty();
                }
            }
        }
    };
    
proto.expand = function () {
        
this.container.addClass(this.expandedClass);
        
this._makeFakeTextarea();
    };
    
proto.collapse = function () {
        
this.container.removeClass(this.expandedClass);
        if (
this.smilesBtn.size()) {
            
smilesTooltip.hide(this.smilesBtn[0]);
        }
        
this._removeFakeTextarea();
    };
    
proto._onClick = function (event) {
        
this.save();
    };
    
proto._onFocus = function (event) {
        
this.expand();
    };
    
proto._onBlur = function (event) {
        if (!
this.get(true).length) {
            
this.collapse();
        }
    };
    
proto._onKeyDown = function (event) {
        switch (
event.keyCode) {
        case 
27// Esc
            
if (!this.isEnabled()) {
                
this.blur();
            }
            break;
        case 
13// Enter
            
if (event.ctrlKey) {
                
this.save();
            }
            break;
        }
    };
    
proto.focus = function () {
        
this.textArea.focus();
    };
    
proto.blur = function () {
        
this.textArea.blur();
    };
    
proto.enable = function () {
        if (!
this.isEnabled()) {
            
this.container.addClass(this.enabledClass);
            
this.saveButton.removeClass(this.btnDisabledClass);
            if (
this.textArea.attr('disabled')) {
                
this.textArea.removeAttr('disabled');
            }
        }
    };
    
proto.disable = function () {
        if (
this.isEnabled()) {
           
this.container.removeClass(this.enabledClass);
           
this.saveButton.addClass(this.btnDisabledClass);
        }
    };
    
proto._saveCheckFn = function () {
        if (
this.textArea.attr('disabled')) return;
        var 
text this.get(true);
        if (
text.length) {
            
this.container.addClass(this.hasTextClass);
            
this.enable();

            if (!
this.textAreaFake) {
                
this._makeFakeTextarea();
            }
            
this.textAreaFake.val(this.textArea.val());
            
this.textArea.css({
                
heightthis.textAreaFake[0].scrollHeight
            
});
        } else {
            
this.container.removeClass(this.hasTextClass);
            
this.disable();
            
this.textArea.css('height''');
        }
        if (
this.textLimit) {
            
this.setLimitText();
        }
    };
    
proto.parseLinks = function(){
        var 
context this,
            
text this.get(true),
            
ijalreadyParsed,
            
urls text.match(/(https?://([a-z0-9-]+[.])+([a-z]{2,4}))(?:(/[^s]+)|[^a-z]|$)/ig);

        
if(typeof urls !== 'undefined'){
            for(
i in urls){
                
alreadyParsed false;
                for(
j in context.additionalDataCache){
                    if(
context.additionalDataCache[j].indexOf([urls[i]]) > -1){
                        
alreadyParsed true;
                        break;
                    }
                }
                if(!
alreadyParsed){
                    
context.additionalDataCache.push(urls[i]);
                    
context.parseUrl(urls[i]);
                }
            }
        }
    };
    
proto.subscribeToEventer = function(eventNameuid){
        var 
context this;
        
messageFormEventer.on(eventName+'.'+uid, function(eventdata){ context['on'+eventName].call(contextdatauid); } );
        if(
eventName == 'parseComplete')
            
st(function(){context.unsubscribeToEventer('parseComplete'uid); }, 5000);
    };
    
proto.unsubscribeToEventer = function(eventNameuid){
        
messageFormEventer.off(eventName+'.'+uid);
    };
    
proto.onparseComplete = function(datauid){
        if(
data.task != uid)
            return 
false;
        if(!
this.additionalData)
            
this.additionalData = {};
        if(
data.type == 'img'){
            
this.additionalData['img'+data.imageId] = {type'img'iddata.imageIdurldata.previewUrl};
        } else if(
data.type == 'site'){
            
this.additionalData['site'+data.siteId+'_'+data.linkId] = {type'site'iddata.siteId+'_'+data.linkIdimgIddata.imageIdurldata.previewUrl };
        }
        
this.additionalDataContainer.html(this.renderAdditionalData());
        
this.unsubscribeToEventer('removeAttachment'uid);
        
this.subscribeToEventer('removeAttachment'uid);
        
this.unsubscribeToEventer('parseComplete'uid);
    };
    
proto.onremoveAttachment = function(datauid){
        if(
typeof this.additionalData[data.uid] !== 'undefined'){
            
delete this.additionalData[data.uid];
            var 
html this.renderAdditionalData();
            
this.additionalDataContainer.html(html)[html 'removeClass' 'addClass']('d-n');
        }
    };
    
proto.onChange = function () {
        
this._saveCheckFn();
    };
    
proto.isEnabled = function () {
        return 
this.container.hasClass(this.enabledClass);
    };
    
proto.set = function (text) {
        if(
this.additionalContentEnabled && typeof text === 'object'){
            var 
html this.renderAdditionalData(text.additionalDatatrue),
                
totalPhotos 0;
            
this.additionalDataContainer.html(html)[html 'removeClass' 'addClass']('d-n');
            if(
typeof this.uploaderObj === 'object'){
                for(var 
i in this.additionalData){
                    
totalPhotos++;
                }
                
this.uploaderObj.totalPhotos totalPhotos;
            }
            
text text.text;
        }
        
this.textArea.val(text);
        
this._saveCheckFn();
    };
    
proto.get = function (isEmpty) {
        if(
isEmpty || !this.additionalContentEnabled) {
            var 
result this.textArea.val();
            if(!
result.length && this.additionalData)
                
result 'true';
            return 
result;
        } else {
            var 
text this.textArea.val();
            if(
text.length 0){
                
text text.split('[img:');
                if(
text.length 1){
                    for(var 
i=1i<text.lengthi++){
                        if(
text[i].indexOf(']') > -1)
                            
text[i] = text[i].slice(text[i].indexOf(']')+1);
                    }
                }
                return 
text.join('');
            } else {
                return 
text;
            }
        }
    };
    
proto.parseUrl = function (url) {
        var 
context this;
        
fs.post('/attach/upload/', {urlurlajax1ownerType:1ownerIdcurrentUser.userId}, {
            
onError:function(data){
                return 
false;
            },
            
onSuccess:function(data){
                if (
data.result) {
                    
context.currentParseTaskId null;
                    
context.onparseComplete(data.result);
                } else {
                    
context.currentParseTaskId data.task;
                    
context.subscribeToEventer('parseComplete'data.task);
                }
            }
        });
    };
    
proto.getData = function(dataType){
        var 
context this,
            
newData false,
            
idataItem;
        
dataType dataType || 'img';

        if(
context.additionalData){
            for(
i in context.additionalData){
                
dataItem context.additionalData[i];
                if(
dataItem.type == dataType){
                    if(!
newDatanewData = {};
                    
newData[i] = dataItem;
                }
            }
        } else {
            
newData '';
        }
        return 
newData;
    };
    
proto.getSerializedData = function(dataType){
        if(!
this.additionalContentEnabled)
            return 
false;
        var 
result '',
            
data '';
        if(!
dataType){
            
dataType = ['img''site''json'];
        } else {
            
dataType = (typeof dataType === 'string') ? [dataType] : dataType;
        }
        for(var 
j in dataType){
            if(
dataType[j] != 'json'){
                
data this.getData(dataType[j]);
                for(var 
i in data){
                    if(
data[i].type && data[i].id && data[i].url){
                        
result += '['+data[i].type+':'+data[i].id+':'+data[i].url.replace(/./g',')+']';
                    }
                }
            } else {
                
data this.getData('photo');
                if(
data)
                    
result += '[json:'+JSON.stringify(data).replace(/]/g']').replace(/[/g'[') +']';
            }
        }
        return 
result.length ' '+result false;
    };
    
proto.renderAdditionalData = function(textforceDataUpdate){
        if(!
this.additionalContentEnabled)
            return 
false;
        var 
data false,
            
result '',
            
i,
            
series '';

        
data text this.constructor.getData(text'img') : this.getData('img');
        if(
data){
            if(
text && text.length && !forceDataUpdate){
                for(
i in data){
                    
series += (series.length ',' '')+data[i].id;
                }
                for(
i in data){
                    
result += '<div class="comments-attachment-img" onclick="showPhoto({photoid: '+data[i].id+', '+ (series.length 'series: ''+series+'', ''') +'type: 6})"><img src="'+data[i].url.replace(/,/g'.')+'" /></div>';
                }
            } else {
                if(
forceDataUpdate) {
                    
this.additionalData this.additionalData || {};
                    $.
extend(this.additionalDatadata);
                }
                for(
i in data){
                    
series += data[i].id;
                }
                for(
i in data){
                    
result += '<div class="comments-attachment-img" onclick="showPhoto({photoid: '+data[i].id+', '+ (series.length 'series: ''+series+'', ''') +'type: 6})">'
                        
+'<img src="'+data[i].url.replace(/,/g'.')+'" />'
                        
+'<span class="comments-attachment-remove tr-opacity-03" onclick="messageFormEventer.emit('removeAttachment', {uid: 'img'+data[i].id+''}); sp(event);">'
                            
+'<i class="icn icn-close icn-white"></i>'
                        
+'</span>'
                    
+'</div>';
                }
            }
        }

        
data text this.constructor.getData(text'site') : this.getData('site');
        if(
data){
            if(
text && text.length && !forceDataUpdate){
                
// asch' asch'
            
} else {
                if(
forceDataUpdate) {
                    
this.additionalData this.additionalData || {};
                    $.
extend(this.additionalDatadata);
                }
                for(
i in data){
                    
result += '<div class="comments-attachment-site">'
                            
+'<span class="comments-attachment-site-anchor">Ссылка <i class="icn icn-close icn-gray" onclick="messageFormEventer.emit('removeAttachment', {uid: 'site'+data[i].id+''}); sp(event);"></i></span>'
                            
+'<div class="comments-attachment-site-box">'
                                
+'<h3 class="comments-attachment-site-title">Морфология. Задачи и подходы к их решению</h3>'
                                
+'<img class="comments-attachment-site-preview" src="'+data[i].url.replace(/,/g'.')+'" />'
                                
+'<p class="comments-attachment-site-description">Содержание цикла статей про морфологию • Морфология и компьютерная лингвистика для самых маленьких • Роль морфологии в компьютерной лингвистике • Морфология. Задачи и подходы к их решению • Псевдолемматизация, композиты и прочие странные словечки В прошлой статье мы вплотную подошли к решению задачи</p>'
                            
+'</div>'
                        
+'</div>';
                }
            }
        }

        
data text this.constructor.getData(text'json') : this.getData('json');
        if(
data){
            if(
text && text.length && !forceDataUpdate){
                for(
i in data){
                    
series += (series.length ',' '')+data[i].id;
                }
                for(
i in data){
                    
result += '<div class="comments-attachment-img" onclick="showPhoto({photoid: '+data[i].id+', '+ (series.length 'series: ''+series+'', ''') +'type: 6})"><img src="'+data[i].url+'" /></div>';
                }
            } else {
                if(
forceDataUpdate) {
                    
this.additionalData this.additionalData || {};
                    $.
extend(this.additionalDatadata);
                }
                for(
i in data){
                    
series += data[i].id;
                }
                for(
i in data){
                    if(
forceDataUpdate && typeof this.uploaderObj === 'object'){
                        
this.unsubscribeToEventer('removeAttachment''photo'+data[i].id);
                        
this.subscribeToEventer('removeAttachment''photo'+data[i].id);
                    }
                    if(
typeof this.renderAttachmentPhoto === 'function'){
                        
result += this.renderAttachmentPhoto(data[i]);
                    } else {
                        
result += '<div class="message-form-photo-preload-wrap" onclick="showPhoto({photoid: '+data[i].id+', '+ (series.length 'series: ''+series+'', ''') +'type: 6})">'
                            
+'<img class="message-form-photo-preload-img" src="'+data[i].url+'" />'
                            
+'<div class="message-form-photo-preload-delete message-form-photo-preload-action-btn tr-opacity-03" onclick="messageFormEventer.emit('removeAttachment', {uid: 'photo'+data[i].id+'', element: $(this).closest('.message-form-photo-preload-wrap')}); sp(event);"><i class="icn icn-light-gray icn-cross"></i></div>'
                            
+'</div>';
                    }
                }
            }
        }
        
// there should be renders for other data types
        
return result.length '<div class="comments-attachments-wrap">'+result+'</div>' '';
    };
    
proto.getSimpleData = function(text){
        var 
dataTypes = ['img''vid''site''json'],
            
result typeof text !== 'undefined' text this.textArea.val();
        for(var 
i in dataTypes){
            
result result.split('['+dataTypes[i]+':')[0];
        }
        return 
result == text text result.slice(0, -1);
    };
    
proto.reset = function () {
        if (
this.textArea.attr('disabled')) {
            
this.textArea.removeAttr('disabled');
        }
        if(
this.additionalContentEnabled){
            
this.additionalData false;
            
this.additionalDataContainer.empty();
            
this.additionalDataCache = [];
        }
        
this.set('');
        
this.blur();
    };

    function 
checkOffsets(elstartend) {
        
start = (start 0) ? start el.value.length start;
        
end = (typeof end == 'undefined') ? start : (end 0) ? end el.value.length end;
        return {
start:startend:end};
    }
    function 
offsetToRange(eloffset) {
        return 
offset - (el.value.slice(0offset).split("rn").length 1);
    }
    var 
getSelection = function(t) {
        var 
el t[0];
        var 
start 0end 0text '';
        if (
typeof el.selectionStart !== 'undefined') {
            
start el.selectionStart;
            
end el.selectionEnd;
            
text el.value.slice(startend);
        } else if (
typeof document.selection == 'object') {
            var 
textRangeendRangelen el.value.lengthrange document.selection.createRange();
            if (
range && range.parentElement() == el) {
                
text el.value.replace(/rn/g"n");
                
textRange el.createTextRange();
                
endRange el.createTextRange();
                
textRange.moveToBookmark(range.getBookmark());
                
endRange.collapse(false);
                if (
textRange.compareEndPoints('StartToEnd'endRange) > -1) {
                    
start end len;
                } else {
                    
start = -textRange.moveStart('character', -len);
                    
start += text.slice(0start).split("n").length 1;
                    if (
textRange.compareEndPoints('EndToEnd'endRange) > -1) {
                        
end len;
                    } else {
                        
end = -textRange.moveEnd('character', -len);
                        
end += text.slice(0end).split("n").length 1;
                    }
                }
            } else if (
t.data('lastSelection')) {
                var 
data t.data('lastSelection');
                
start data.start;
                
end data.end;
                
text data.text;
            } else {
                
start end len;
            }
        }
        return {
start:startend:endtext:text};
    };
    var 
setSelection = function(tstartend) {
        var 
el t[0];
        var 
offsets checkOffsets(elstartend);
        if (
typeof el.selectionStart != 'undefined') {
            
el.selectionStart offsets.start;
            
el.selectionEnd offsets.end;
        } else if (
typeof document.selection == 'object') {
            var 
range el.createTextRange();
            var 
startCharMove offsetToRange(eloffsets.start);
            
range.collapse(true);
            if (
offsets.start == offsets.end) {
                
range.move("character"startCharMove);
            } else {
                
range.moveEnd("character"offsetToRange(eloffsets.end));
                
range.moveStart("character"startCharMove);
            }
            
range.select();
        }
    };
    var 
replaceSelection = function(ttext) {
        var 
sel getSelection(t), t.val();
        
t.focus();
        var 
idx sel.start text.length;
        
t.val(v.slice(0sel.start) + text v.slice(sel.end));
        
setSelection(tidx);
    };
    
proto.getSelection = function () {
        
getSelection(this.textArea);
    };
    
proto.setSelection = function (startend) {
        
setSelection(this.textAreastartend);
    };
    
proto.replaceSelection = function (text) {
        
replaceSelection(this.textAreatext);
    };

    
MessageForm.extend = function() {
        var 
Parent this,
            
Child = function (config) {
                
Parent.call(thisconfig);
            };
        
Child.prototype = new Parent();
        
Child._super Parent.prototype;
        
Child.prototype._defaultConfig = $.extend({}, Child._super._defaultConfig);
        
Child.prototype.constructor Child;
        
Child.getData Parent.getData;
        return 
Child;
    };
    
MessageForm.getData = function(textdataType){
        var 
context this,
            
newData false,
            
ijsonidurl;
        
dataType dataType || 'img';

        if(
text && text.length 5) return newData;
        
text text.split('['+dataType+':');
        if(
text.length 1){
            for(
i=1i<text.lengthi++){
                
text[i] = text[i].slice(0text[i].indexOf(']'));
                
newData newData || {};
                if(
dataType != 'json'){
                    
id text[i].split(':')[0];
                    
url text[i].slice(id.length 1);

                    
newData[dataType id] = {
                        
type dataType,
                        
id id,
                        
url url
                    
};
                } else {
                    try {
                        
json JSON.parse(text[i]);
                        $.
extend(newDatajson);
                    } catch(
e){}
                }
            }
        }
        return 
newData;
    };

    var 
messageForm window.messageForm = {
        
cache: {},
        
formConstructorMessageForm,
        
isInitedfalse,
        
init: function () {
            if (!
this.isInited) {
                var 
me this;
                
nav2.gc(function () {
                    
me.destroy();
                });
                
this.isInited true;
            }
        },
        
getInstance: function (uid) {
            if (!
this.isInited) {
                
this.init();
            }
            return 
this._getInstanceFn(uid);
        },
        
_getInstanceFn: function (uid) {
            if (!
this.cache[uid]) {
                
this.cache[uid] = new this.formConstructor(uid);
            }
            return 
this.cache[uid];
        },
        
renderAdditionalData: function(text){
            return 
this.getInstance().renderAdditionalData(text);
        },
        
getSimpleData: function(text){
            return 
this.getInstance().getSimpleData(text);
        },
        
getData: function(textdataType){
            if(
typeof text === 'string'){
                return 
this.formConstructor.getData(textdataType);
            } else {
                return 
this.getInstance().getData(dataType);
            }
        },
        
destroy: function () {
            
this.isInited false;
            
this._destroyFn();
        },
        
_destroyFn: function () {
            
this.cache = {};
        },
        
edit: function (uid) {
            
this.getInstance(uid).expand();
        },
        
set: function (uidtext) {
            
this.getInstance(uid).set(text);
        },
        
get: function (uid) {
            
this.getInstance(uid).get();
        },
        
save: function (uid) {
            
this.getInstance(uid).save();
        },
        
focus: function (uid) {
            
this.getInstance(uid).focus();
        },
        
blur: function (uid) {
            
this.getInstance(uid).blur();
        },
        
onKeyDown: function (uidevent) {
            
this.getInstance(uid)._onKeyDown(event);
        },
        
onFocus: function (uidevent) {
            
this.getInstance(uid)._onFocus(event);
        },
        
onBlur: function (uidevent) {
            
this.getInstance(uid)._onBlur(event);
        },
        
onDrop: function (uidevent) {
            var 
me this;
            
setTimeout(function () {
                
me.getInstance(uid)._saveCheckFn();
            }, 
0);
        }
    };
})();

var 
smilesTooltip = {
    
confignull,
    
showBy100,
    
showed0,
    
messageFormnull,
    
tooltipnull,
    
scrollbarfalse,
    
show : function(elementmessageFormtooltipClassanimatedSmiles){
        var 
node_heap = $('#node-heap-smiles-tooltip');
        if (!
node_heap.length) {
            
node_heap = $('<div>', {'id''node-heap-smiles-tooltip'}).appendTo($('#node-heap'));
        }

        
smilesTooltip.tooltipClass tooltipClass;
        var 
btn = $(element);
        if (
smilesTooltip.tooltip) { // Костыль для того, чтобы не создавалось over9000 тултипов в ДОМе для каждой кнопки смайла
            
if (smilesTooltip.tooltip.element[0] != element && smilesTooltip.tooltip.is_visible) { // попап открыт на другой кнопке, нужно его сначала закрыть
                
smilesTooltip.tooltip.wrapper.css({opacity0});
                
smilesTooltip.tooltip.is_visible false;
                
smilesTooltip.tooltip.element.removeClass('on');
            }
            
element.tooltip smilesTooltip.tooltip;
            
element.tooltip.element btn;
        }
        if (
btn.hasClass('on')) {
            
smilesTooltip.hide(element);
        } else {
            
smilesTooltip.messageForm messageForm;
            var 
btn = $(element).addClass('on');
            
AnyTooltip.show(element, {
                
content: {
                    
func: function(tooltip){
                        if(!
smilesTooltip.config){
                            $.
get('/usercontact/ajax/getusersmiles/', $.extend({}, {animatedanimatedSmiles}),function(response){
                                if (
response && response.ret == 1) {
                                    
smilesTooltip.config = $.merge(response.freeresponse.premium);
                                } else {
                                    
smilesTooltip.config = [];
                                }
                                
tooltip.html(smilesTooltip.render());
                                
smilesTooltip.scrollbar = new Scrollbar(tooltip.wrapper.find('.smiles-tooltip-box'), { moresmilesTooltip.more });
                            }, 
'JSON');
                        } else {
                            
tooltip.html(smilesTooltip.render());
                            
smilesTooltip.scrollbar = new Scrollbar(tooltip.wrapper.find('.smiles-tooltip-box'), { moresmilesTooltip.more });
                        }
                        
nav2.gc(smilesTooltip.destroy'smilesTooltipGc');
                    }
                },
                
style: {
                    
show_delay1,
                    
show_distance10,
                    
show_duration180,
                    
hide_delay1,
                    
hide_distance10,
                    
hide_duration180,
                    
no_closetrue,
                    
node_heap'#node-heap-smiles-tooltip',
                    
animate_open: function(me){
                        
smilesTooltip.tooltip me;
                        
me.wrapper.attr('onmousedown''cancelEvent(event); return false;')
                            .
removeClass()
                            .
addClass('iTooltip smiles-tooltip ' + (smilesTooltip.tooltipClass||''));

                        var 
wrap me.element,
                            
finalX Math.round(-(wrap.offset().left wrap.width())),
                            
finalY Math.round(-(wrap.offset().top 5));

                        if (
smilesTooltip.scrollbar) {
                            
smilesTooltip.scrollbar.update(falsetrue);
                            
smilesTooltip.scrollbar.val(smilesTooltip.scrollbar_top || 0);
                        }

                        
me.arrow.css({rightwrap.width()/2});

                        
me.wrapper
                            
.css({ rightfinalXbottomfinalY me.show_distanceopacity})
                            .
stop()
                            .
animate({ bottomfinalYopacity}, me.show_duration);
                    },
                    
animate_close: function(me){
                        
smilesTooltip.scrollbar_top smilesTooltip.scrollbar.val();
                        
me.wrapper
                            
.stop()
                            .
animate({ bottom'+=' me.hide_distanceopacity}, me.hide_duration, function(){
                                
me.wrapper.css('right'10000);
                                
me.is_visible false;
                            });
                    }
                }
            });

            if (!
element.hideSmilesTooltipelement.hideSmilesTooltip = function(event){ smilesTooltip.hide(elementevent); };
            
st(function(){ $(document).bind('click'element.hideSmilesTooltip); }, 0);
        }

    },
    
hide: function(elementevent){
        if (
checkEvent(event)) return;

        var 
event && $(event.target);
        if (
&& (t.hasClass('smiles-tooltip') || t.parent().hasClass('smiles-tooltip-box') || t.parent().parent().hasClass('smiles-tooltip-box'))) return;

        if (
element && element.hideSmilesTooltipst(function(){ $(document).unbind('click'element.hideSmilesTooltip); }, 0);
        $(
element).removeClass('on');
        
AnyTooltip.hide(element);
        
smilesTooltip.messageForm null;
        
smilesTooltip.showed 0;
    },
    
render: function () {
        var 
res '<div class="smiles-tooltip-box"><div class="smiles-tooltip-inner"><div class="smiles-tooltip-list">';
        
res += smilesTooltip.renderPortion();
        
res += '</div></div></div>';
        return 
res;
    },
    
renderPortion: function () {
        var 
res ''smileTxt;
        for (var 
smilesTooltip.showedMath.min(smilesTooltip.showed smilesTooltip.showBysmilesTooltip.config.length), smileli++ ) {
            
smilesTooltip.showed++;
            
smile smilesTooltip.config[i];
            
smileTxt smile.text.replace(/\/g'\\').replace(/'/g, '\'');
            
res += '<img src="' smile.url '" onload="if (smilesTooltip.scrollbar) smilesTooltip.scrollbar.update(false, true);" onclick="smilesTooltip.insert('' + smileTxt + '');" alt="'+smileTxt+'" title="'+smileTxt+'" />';
        }
        return 
res;
    },
    
insert: function (smileStr) {
        if (
smilesTooltip.messageForm) {
            
smilesTooltip.messageForm.replaceSelection(' ' smileStr ' ');
            
smilesTooltip.messageForm.textArea.triggerHandler('change');
        }
    },
    
more: function(){
        if (
smilesTooltip.scrollbar) {
            var 
portion smilesTooltip.renderPortion();
            if (
portion.length) {
                
smilesTooltip.scrollbar.content.append(portion);
                
smilesTooltip.scrollbar.update(falsetrue);
            } else {
                
smilesTooltip.scrollbar.options.more null;
            }
        }
    },
    
destroy: function () {
        
smilesTooltip.showed 0;
        
smilesTooltip.messageForm null;
        
smilesTooltip.tooltip null;
        
delete smilesTooltip.scrollbar;
        
smilesTooltip.scrollbar false;
    }
};

var 
mutualFriendsPopup = function(friendId) {
    $.
get('/friends/ajax/sourcessuggestedfriends/',
        {
            
friendId:friendId,
            
ajax1
        
},
        function (
response) {
            if (
response.ret == 1) {
                
iPopup.open(response.html, {
                    
title"Ваши общие друзья",
                    
style: {
                        
width682
                    
},
                    
onopen: function(){
                        var 
source_friends_scrollbar = new Scrollbar('scrollbar-source-friends-wrap');
                    }
                });
            } else {
                
fs.notify(response.message);
            }
        },
        
'JSON'
    
);

    return 
false;
};

/*
 * Попап с двумя списками с возможностью переносить элементы из одного в другой и сохранять изменения.
 */
var listManagePopup = function (opts) {
    
this.construct(opts);
};

listManagePopup.prototype = {
    
construct: function (opts) {
        var 
self this;

        $.
extend(self, {
            
title' ',
            
listTitles: ['Первый список''Второй список'],
            
emptyMessages: ['Список пуст.''Список пуст.'],
            
inputPlaceholder'',
            
width500,
            
closeOnSavetrue,
            
footer'<div class="ibtn ibtn-blue btn-save">Сохранить</div>',
            
myclass'list-manage-popup',
            
loadAjaxUrl'',
            
saveAjaxUrl'',
            
flySearchfalse
        
}, opts);
        
self.managedItemIds = [{}, {}];
        
self.offsets = [00];
        
self.hasNext = [truetrue];
        
self.filter '';
        
self.loadLocks false;
        
self.saveLocks false;

        
self._onAjaxLoadSuccess = function (res) {
            
self.onLoadSuccess(res);
        };
        
self._onAjaxSaveSuccess = function (res) {
            
self.onSaveSuccess(res);
        };
        
self._onOpen = function (popup) {
            
self.onOpen(popup);
        };
        
self._onClose = function (popup) {
            
self.onClose(popup);
        };
        
self._onSaveClick = function () {
            
self.save();
        };
    },
    
tpl: function () {
        return 
'<div class="filter-input-wrap"><input class="filter-input form-input" placeholder="'+this.inputPlaceholder+'" /></div>'+
                
'<ul class="managed-lists nclear">'+
                    
'<li class="managed-list-wrap managed-list1">' +
                        
'<div class="managed-list-title">'+this.listTitles[0]+'</div>' +
                        
'<div class="managed-list-scrollarea unselectable"><div class="managed-list-inner"><ul class="managed-list"></ul></div>'+
                    
'</li>'+
                    
'<li class="managed-lists-divider"></li>' +
                    
'<li class="managed-list-wrap managed-list2">' +
                        
'<div class="managed-list-title">'+this.listTitles[1]+'</div>' +
                        
'<div class="managed-list-scrollarea unselectable"><div class="managed-list-inner"><ul class="managed-list"></ul></div>'+
                    
'</li>'+
                
'</ul>'
    
},
    
open: function () {
        var 
self this;

        
iPopup.open(self.tpl(), $.extend({
            
titleself.title,
            
footerself.footer,
            
style: {
                
widthself.width,
                
myclassself.myclass
            
},
            
onopenself._onOpen,
            
oncloseself._onClose
        
}, self.popupConfig));

        
self.lists self.popup.inner.find('.managed-list');
        
self.lists.on('click''.managed-list-item', function () {
            
self.swap($(this));
        });

        
// self.lists.eq(0).append('<li class="managed-list-empty-item">'+self.emptyMessages[0]+'</li>');
        // self.lists.eq(1).append('<li class="managed-list-empty-item">'+self.emptyMessages[1]+'</li>');

        
self.lists[0].scrollbar = new Scrollbar(self.lists.eq(0).closest('.managed-list-scrollarea')[0], {
            
more: function(){
                if (
self.hasNext[0]) self.load(false0);
            }
        });
        
self.lists[1].scrollbar = new Scrollbar(self.lists.eq(1).closest('.managed-list-scrollarea')[0], {
            
more: function(){
                if (
self.hasNext[1]) self.load(false1);
            }
        });

        
self.load(true);

        
self.filterInput self.popup.inner.find('.filter-input');

        if (
self.flySearch) {
            
self.flySearch = new flySearch($.extend({
                
elementself.filterInput,
                
ajaxUrltrue,
                
onSearch: function (params) {
                    
self.filter params.query;
                    
self.offsets = [00];
                    
self.load(true);
                },
                
onCancel: function () {
                    
self.filter '';
                    
self.offsets = [00];
                    
self.load(true);
                }
            }, 
self.flySearch));

            
self.filterInput.keyup(function () {
                
self.flySearch.search();
            });
        }
    },
    
close: function () {
        if (
this.popup) {
            
iPopup.close();
            
this.popup null;
        }
    },
    
load: function (clearBeforelistIndex) {
        if (
this.loadLock) return;

        
this.loadLock true;
        
this.clearBefore clearBefore;

        
this.showPreloader(listIndex);

        $.
get(this.loadAjaxUrl, $.isFunction(this.loadAjaxParams) ? this.loadAjaxParams() : this.loadAjaxParamsthis._onAjaxLoadSuccess'json');
    },
    
showPreloader: function (listIndex) {
        var 
lists typeof listIndex == 'undefined' ? [01] : [listIndex];

        for (var 
0lists.lengthi++) {
            
this.lists.eq(i).append('<li class="manage-item-preloader"><i class="icn icn-process"></i></li>');
        }
    },
    
hidePreloader: function (listIndex) {
        
this.lists.find('.manage-item-preloader').remove();
    },
    empty: function (
listIndex) {
        if (
typeof listIndex == 'undefined') {
            
this.lists.empty();
            
this.offsets[0] = 0;
            
this.offsets[1] = 0;
            
this.hasNext[0] = true;
            
this.hasNext[1] = true;
        } else {
            
this.lists.eq(listIndex).empty();
            
this.offsets[listIndex] = 0;
            
this.hasNext[listIndex] = true;
        }
    },
    
loadAjaxParams: function (listIndex) {
        var 
offsets = (typeof listIndex == 'undefined') ? this.offsets : [-1, -1];
        if (
typeof listIndex != 'undefined') {
            
offsets[listIndex] = this.offsets[listIndex];
        }

        return {
            
offsetsoffsets,
            
filterthis.filter
        
}
    },
    
isChanged: function () {
        for (var 
0jthis.managedItemIds.lengthi++) {
            for (
j in this.managedItemIds[i]) {
                if (
this.managedItemIds[i][j]) return true;
            }
        }

        return 
false;
    },
    
saveAjaxParams: function () {
        return {
            
liststhis.managedItemIds
        
};
    },
    
// перекладываем элементы, расположенные не в своей колонке, но еще не сохраненные
    
reassembleLists: function (lists) {
        for (var 
ii 0ll lists.lengthcurrListoppositeListijii llii++) {
            
currList lists[ii].data;

            if (!
currList) continue;

            
ij = (ii+1)%2;
            
oppositeList lists[ij].data;

            for (var 
0idcurrList.length; ) {
                
id this.getDataId(currList[i]);
                if (
this.managedItemIds[ij][id]) { // нашли элемент в противоположном списке
                    
oppositeList.splice(Math.min(ioppositeList.length-1), 0currList[i]);
                    
currList.splice(i1);
                } else {
                    
i++;
                }
            }
        }
    },
    
onLoadSuccess: function (res) {
        
this.hidePreloader();
        if (
res.ret == 1) {
            
this.reassembleLists(res.list);

            for (var 
0res.list.lengthi++) {
                if (
this.clearBefore && res.list[i].data && res.list[i].data.length) {
                    
this.empty(i);
                    
this.lists[i].scrollbar.scrollToY(0);
                }
                if (
res.list[i].data) {
                    
this.offsets[i] = res.list[i].offset;
                    
this.hasNext[i] = res.list[i].hasNext;
                    
this.renderList(res.list[i].datai);
                }
            }
        }
        
this.loadLock false;
    },
    
onSaveSuccess: function () {
        
this.saveLocks false;
        
this.managedItemIds = [{}, {}];
        
this.lists.eq(0).find('.managed-list-item').data('srcListIdx'0);
        
this.lists.eq(1).find('.managed-list-item').data('srcListIdx'1);
        if (
this.closeOnSave) {
            
this.close();
        }
    },
    
renderItem: function (datalistIndex) {
        return $(
'<li class="managed-list-item">'+data+'<i class="icn icn-gray icn-close"></i><i class="icn icn-gray icn-plus"></i></li>');
    },
    
renderList: function (list, listIndex) {
        if (!list.
length && this.offsets[listIndex] == && !this.filter) {
            
this.addEmptyMessage(listIndex);
        } else if (list.
length) {
            
this.removeEmptyMessage(listIndex);
        }
        for (var 
0= list.lengthitemli++) {
            
item this.renderItem(list[i], listIndex).data({
                
'itemId'this.getDataId(list[i]),
                
'srcListIdx'listIndex,
                
'listIdx'listIndex
            
}).appendTo(this.lists.eq(listIndex));
        }
        
this.lists[listIndex].scrollbar.update(falsetrue);
    },
    
addEmptyMessage: function (listIndex) {
        if (!
this.lists[listIndex].emptyMessage) {
            
this.lists[listIndex].emptyMessage = $('<li class="managed-list-empty-item">'+this.emptyMessages[listIndex]+'</li>').appendTo(this.lists[listIndex]);
        }
    },
    
removeEmptyMessage: function (listIndex) {
        if (
this.lists[listIndex].emptyMessage) {
            
this.lists[listIndex].emptyMessage.remove();
            
this.lists[listIndex].emptyMessage null;
        }
    },
    
swap: function (item) {
        var 
data item.data(),
            
listIdx data.listIdx,
            
oppositeListIdx = (listIdx 1) % 2,
            
swappedFromSource = (data.srcListIdx == listIdx);

        
item.detach().prependTo(this.lists.eq(oppositeListIdx));
        
this.removeEmptyMessage(oppositeListIdx);
        if (!
this.lists.eq(listIdx).find('.managed-list-item').length) {
            
this.addEmptyMessage(listIdx);
        }
        
data.listIdx oppositeListIdx;
        
this.lists[listIdx].scrollbar.update(falsetrue);
        
this.lists[oppositeListIdx].scrollbar.update(falsetrue);
        if (
swappedFromSource) {
            
this.managedItemIds[oppositeListIdx][data.itemId] = true;
        } else {
            
delete this.managedItemIds[listIdx][data.itemId];
        }
    },
    
getDataId: function (data) {
        return 
data;//.id;
    
},
    
save: function () {
        if (
this.saveLocks) return;
        
this.saveLocks true;
        if (!
this.isChanged()) return this.onSaveSuccess();
        
fs.post(this.saveAjaxUrlthis.saveAjaxParams(), this._onAjaxSaveSuccess);
    },
    
onOpen: function (popup) {
        
this.popup popup;
        
popup.popupBody.find('.popup-footer .btn-save').click(this._onSaveClick);
    },
    
onClose: function (popup) {
        
this.popup null;
    }
};

/*
 * Попап для управления списками людей
 */
var peopleManagePopup = function (opts) {
    var 
popup = new listManagePopup($.extend({
        
title'Выберите людей',
        
inputPlaceholder'Начните вводить имя или фамилию',
        
myclass'list-manage-popup people-manage-popup',
        
listTitles: ['Все люди''Выбранные люди'],
        
width620,
        
loadAjaxUrl'',
        
saveAjaxUrl'',
        
renderItem: function (data) {
            return $(
'<li class="managed-list-item"><div class="friend-avatar"><img src="'+data.image+'"/></div><span class="friend-name ellipsis">'+data.name+'</span><i class="icn icn-gray icn-close"></i><i class="icn icn-gray icn-plus"></i></li>');
        },
        
getDataId: function (data) {
            return 
data.id;
        },
        
flySearchtrue
    
}, opts));
    
popup.open();
    return 
popup;
};

var 
contextNav = {};
(function(
cn) {
    
/**
     * go back button
     */
    
var buttonRenders = {
            
profileRender : function(html){
                var 
navTabs = $('#context-nav-tabs');
                if (!
navTabs.length) {
                    
navTabs = $('<div id="context-nav-tabs" class="nclear"></div>').prependTo('#content-inner');
                }
                
navTabs.find('.contextNav-profileRender').remove();
                
this.elem = $('<span class="tab-name menu-link ellipsis contextNav-profileRender" onclick="contextNav.clickStats({from: 'profile', url: ''+this.url+''}); contextNav.clear(''+this.name+''); nav2.go(''+this.url+'', false, { back: true });"><i class="icn icn-gray icn-left"></i>'+this.html+'</span>').appendTo(navTabs);
            },
            
pacmanRender: function(html){
                var 
navTabs = $('#context-nav-tabs');
                if (!
navTabs.length) {
                    
navTabs = $('<div id="context-nav-tabs" class="nclear"></div>').prependTo('#content-inner');
                }
                
navTabs.find('.contextNav-pacmanRender').remove();
                
this.elem = $('<span class="tab-name menu-link ellipsis contextNav-pacmanRender" onclick="contextNav.clickStats({from: 'pacman', url: ''+this.url+''}); contextNav.clear(''+this.name+''); nav2.go(''+this.url+'', false, { back: true });"><i class="icn icn-gray icn-left"></i>'+this.html+'</span>').appendTo(navTabs);
            },
            
defaultRender : function(html){
                
console.log('default attach button render');
                var 
navTabs = $('#context-nav-tabs');
                if (!
navTabs.length) {
                    
navTabs = $('<div id="context-nav-tabs" class="nclear"></div>').prependTo('#content-inner');
                }
                
navTabs.find('.contextNav-defaultRender').remove();
                
this.elem = $('<span class="tab-name menu-link ellipsis contextNav-defaultRender" onclick="contextNav.clickStats({url: ''+this.url+''}); contextNav.clear(''+this.name+''); nav2.go(''+this.url+'', false, { back: true });"><i class="icn icn-gray icn-left"></i>'+this.html+'</span>').appendTo(navTabs);
            }
        },
        
buttonRenderKeys = {
            
'/^\/user\/\d+\/$/'buttonRenders.profileRender,
            
'/^\/user\/\d+\/(friends|blog|info)\/$/'buttonRenders.profileRender,
            
'/^\/user\/\d+\/albums\/$/'buttonRenders.profileRender,
            
'/^\/user\/\d+\/giftroom\/$/'buttonRenders.profileRender,
            
'/^\/user\/\d+\/album\/\d+\/((photos|settings|comments)\/)?(\d+\/)?$/'buttonRenders.profileRender,
            
'/^\/user\/\d+\/board\/\d+\/$/'buttonRenders.profileRender,
            
'/^\/\d+\/$/'buttonRenders.profileRender,
            
'/^\/u\/[a-z\d-]+\/$/i'buttonRenders.profileRender,

            
'/^\/pacman\/news\//'buttonRenders.pacmanRender,
            
'/^\/play\/feed\/board\//i'buttonRenders.pacmanRender
        
},
        
regExpGroups= {
            
profile: [
                /^/
user/d+/$/,
                /^/
d+/$/,
                /^/
u/[a-zd-]+/$/i
            
],
            
profilePages: [
                /^/
user/d+/(friends|blog|info)/$/,
                /^/
user/d+/albums/$/,
                /^/
user/d+/giftroom/$/,
                /^/
user/d+/album/d+/((photos|settings|comments)/)?(d+/)?$/,
                /^/
user/d+/board/d+/$/
            ],
            
pacmanNews: [ /^/pacman/news// ],
            
ny2014: [ /^/holiday/ny2014// ],
            
playfeed: [
                /^/
play/feed/board//i
            
]
        };


    $.
extend(cn, {
        
cache : {},
        
isInitedfalse,
        
initLaterfalse,
        
stack: [],
        
ssCache : {},
        
newButton: function(nameopts){
            if(!
cn.isInited){
                if(!
cn.initLater)
                    
cn.initLater = [];
                
cn.initLater.push({namenameoptsopts});
                return 
true;
            }
            var 
item = $.extend({
                
namename,
                
html'',
                
urlfalse,
                
contexts: [],
                
maxDuplicates1,
                
preserveUponReloadfalse,
                
attachcn.attach,
                
detachcn.detach,
                
destroycn.destroy
            
}, opts);

            
cn.pushToStack(item);

            
nav2.eventer.on('setParam.cn'+item.name, function(eventdata){
                
cn.updateSavedUrl.call(itemdata.url);
                if (
item.preserveUponReload) {
                    
cn.saveToSessionStorage(item.nameopts);
                }
            });
            if (
item.preserveUponReload) {
                
cn.saveToSessionStorage(item.nameopts);
            }

            if(
typeof item.contexts === 'string')
                
cn.convertContextToArray.call(item);
        },
        
pushToStack: function(item){
            if (
cn.cache[item.name]) {
                if(
cn.cache[cn.stack[cn.stack.length-1]].url == item.url){
                    
cn.clear(cn.stack[cn.stack.length-1]);
                    
cn.pushToStack(item);
                } else {
                    if(
item.maxDuplicates 1){
                        for(var 
i=1pushOk=falsei<item.maxDuplicatesi++){
                            if(!
cn.cache[item.name+'##'+i]){
                                
item.name += '##'+i;
                                
cn.cache[item.name] = item;
                                
cn.stack.push(item.name);
                                
pushOk true;
                                break;
                            }
                        }
                        if(!
pushOk){
                            
cn.removeDuplicate(itemcn.pushToStack);
                        }
                    } else {
                        
cn.removeDuplicate(itemcn.pushToStack);
                    }
                }
            } else {
                
cn.cache[item.name] = item;
                
cn.stack.push(item.name);
            }
        },
        
removeDuplicate: function(itemcallback){
            for(var 
i=0i<cn.stack.lengthi++){
                if(
cn.stack[i] == item.name){
                    for(var 
j=ij<cn.stack.lengthj++){
                        if(
cn.stack[j] != item.name+'##'+1){
                            
cn.destroy.call(cn.cache[cn.stack[j]]);
                            
j--;
                        } else {
                            break;
                        }
                    }
                    break;
                }
            }
            
cn.updateIndexes();
            if(
typeof callback === 'function'){ callback(item); }
        },
        
initFromArray: function(){
            for(var 
button in cn.initLater){
                
cn.newButton(cn.initLater[button].namecn.initLater[button].opts);
            }
            
cn.initLater false;
        },
        
updateIndexes: function(){
            for(var 
i in cn.stack){
                var 
oldKey cn.stack[i],
                    
index oldKey.split('##'),
                    
key index[0],
                    
newKey;
                
index index[1];

                if(
typeof index !== 'undefined'){
                    
newKey key + (index>'##'+parseInt(index-1) : '');
                    if(
typeof cn.cache[newKey] === 'undefined'){
                        
cn.stack[i] = newKey;
                        
cn.cache[newKey] = cn.cache[oldKey];
                        
cn.cache[newKey].name newKey;
                        
delete cn.cache[oldKey];
                        
cn.ssCache[newKey] = cn.ssCache[oldKey];
                        
delete cn.ssCache[oldKey];
                    }
                }
            }
            
ss.set('contextNav'cn.ssCache);
            
ss.set('contextNavStack'cn.stack);
        },
        
refresh : function (location) {
            var 
navItem;
            
location location || nav2.location;

            for (var 
cn.stack.length 1>= 0i--) {
                
navItem cn.cache[cn.stack[i]];
                var 
context cn.check.call(navItemlocation.pathname);
                if (
context) {
                    
cn.attach.call(navItemcontext);
                    break;
                }
            }
            
nav2.gc(cn.gc'contextNav');
        },
        
check : function (url) {
            if(
url == (this.baseUrl || this.url))
                return 
false;
            for (var 
0this.contexts.lengthcontexti++) {
                
context this.contexts[i];
                if (
context instanceof RegExp) {
                    if(
context.test(url)){
                        return 
context;
                    }
                }
            }
            return 
false;
        },
        
attach : function (context) {
            
context context.toString();
            if(
typeof buttonRenderKeys[context] === 'function'){
                
buttonRenderKeys[context].call(this);
            } else {
                
buttonRenders.defaultRender.call(this);
            }
        },
        
detach : function () {
            
/* no real need to detach element, it will be removed on navigation
            if (this.elem) {
                this.elem.remove();
                this.elem = null;
            }*/
            
return true;
        },
        
destroy : function () {
            
cn.detach.call(this);
            for(var 
cn.stack.length-1i>=0i--){
                if(
cn.stack[i] == this.name){
                    
cn.stack.splice(i,1);
                    break;
                }
            }
            
delete cn.cache[this.name];
            
cn.removeFromSessionStorage(this.name);
        },
        
clear: function(name){
            
cn.initLater false;
            if(
typeof name === 'undefined'){
                for(var 
i in cn.stack){
                    
cn.detach.call(cn.cache[cn.stack[i]]);
                }
                
cn.cache = {};
                
cn.stack = [];
                
cn.ssCache = {};
            } else if(
name == 'this_url') {
                
cn.destroy.call(cn.cache[cn.stack[cn.stack.length 1]]);
            } else if(
cn.cache[name]) {
                for(var 
cn.stack.length-1i>=0i--){
                    if(
cn.stack[i] == name){
                        
cn.destroy.call(cn.cache[cn.stack[i]]);
                        break;
                    } else {
                        
cn.destroy.call(cn.cache[cn.stack[i]]);
                    }
                }
            }
            
ss.set('contextNav'cn.ssCache);
            
ss.set('contextNavStack'cn.stack);
        },
        
updateSavedUrl: function(url){
            
this.baseUrl this.baseUrl || this.url;
            
this.url url;
        },
        
convertContextToArray: function(){
            var 
contexts this.contexts.split(',');
            
this.contexts = [];
            for(var 
i in contexts){
                if(
typeof regExpGroups[contexts[i]] !== 'undefined')
                    
this.contexts this.contexts.concat(regExpGroups[contexts[i]]);
            }
        },
        
saveToSessionStorage : function (nameopts) {
            
cn.ssCache[name] = opts;
            
ss.set('contextNav'cn.ssCache);
            
ss.set('contextNavStack'cn.stack);
        },
        
removeFromSessionStorage : function (name) {
            
delete cn.ssCache[name];
            
ss.set('contextNav'cn.ssCache);
            
ss.set('contextNavStack'cn.stack);
        },
        
loadFromSessionStorage : function () {
            
cn.isInited true;
            var 
cache ss.get('contextNav'),
                
stack ss.get('contextNavStack'),
                
name;
            if(!
stack)
                return 
false;
            for (var 
j=0stack.lengthj++) {
                
name stack[j];
                
cn.newButton(name.split('##')[0], cache[name]);
            }
            if(
cn.initLater){
                
cn.initFromArray();
            }
        },
        
clickStats: function(params) {
          $.
post('/fast/contextnav.php'params);
        },
        
gc : function () {
            var 
context,
                
navItem,
                
location location || nav2.location,
                
name;
            for(var 
cn.stack.length 1>= 0i--){
                
name cn.stack[i];
                
navItem cn.cache[name];

                
nav2.eventer.off('setParam.cn'+name);
                if (
cn.check.call(navItemlocation.pathname)) {
                    
cn.detach.call(navItem);
                    break;
                } else {
                    
cn.destroy.call(navItem);
                }
            }
        }
    });

    $(function(){
        
cn.loadFromSessionStorage();
        
cn.refresh();
    });
})(
contextNav);

// Прилипающая к верху экрана панель
var floatingPanel = function (opts) {
    $.
extend(this, {
        
wrapnull,
        
floatingElemnull,
        
floatClass'fp-is-floating',
        
startFloatOffset0,
        
stopFloatOffset0,
        
onStartFloatnull,
        
onStopFloatnull,
        
enabledtrue
    
}, opts);
    
this.init();
};
floatingPanel.cache = [];
floatingPanel.gc = function () {
    
floatingPanel.cache = [];
    $(
window).unbind('scroll'floatingPanel.scrollHandlerFn);
    
floatingPanel.scrollHandlerBinded false;
};
floatingPanel.scrollHandlerTimeout null;
floatingPanel.scrollHandlerFn = function () {
    
clearTimeout(floatingPanel.scrollHandlerTimeout);
    
floatingPanel.scrollHandlerTimeout setTimeout(floatingPanel.scrollHandlerTimeoutCallback0);
};
floatingPanel.scrollHandlerTimeoutCallback = function () {
    
floatingPanel.windowScrollTop = $(window).scrollTop();
    
floatingPanel.windowScrollLeft = $(window).scrollLeft();
    for (var 
0floatingPanel.cache.lengthli++) {
        
floatingPanel.cache[i].scrollHandler();
    }
};
floatingPanel.scrollHandlerBinded false;
floatingPanel.prototype = {
    
init: function () {
        if (
this.inited) return;
        var 
me this;

        
this.inited false;
        
this.floating false;

        
floatingPanel.cache.push(this);

        
this.wrap = $(this.wrap);
        
this.floatingElem = $(this.floatingElem);

        if (!
floatingPanel.scrollHandlerBinded) {
            $(
window).bind('scroll'floatingPanel.scrollHandlerFn);
            
floatingPanel.scrollHandlerBinded true;
            
floatingPanel.scrollHandlerFn();
        }

        
nav2.gc(floatingPanel.gc'floatingPanel');

        
this.inited true;
    },
    
scrollHandler: function () {
        if (!
this.enabled) return;
        if (
this.floating && this.wrap.offset().top >= floatingPanel.windowScrollTop this.stopFloatOffset) {
            
this.stopFloat();
        } else if (!
this.floating && this.wrap.offset().top floatingPanel.windowScrollTop this.startFloatOffset) {
            
this.startFloat();
        }
        if (
this.onScroll) {
            
this.onScroll();
        }
    },
    
startFloat: function () {
        if (
this.floating) return;

        
this.wrap.css({
            
widththis.wrap.width(),
            
heightthis.wrap.height()
        });

        
this.floatingElem.css({
            
'position''fixed'
        
}).addClass(this.floatClass);
        
this.floating true;
        if (
this.onStartFloat) {
            
this.onStartFloat();
        }
    },
    
stopFloat: function () {
        if (!
this.floating) return;

        
this.wrap.css({
            
width'',
            
height''
        
});

        
this.floatingElem.css({
            
'position'''
        
}).removeClass(this.floatClass);
        
this.floating false;
        if (
this.onStopFloat) {
            
this.onStopFloat();
        }
    },
    
destroy: function () {
        if (!
this.inited) return;

        var 
cacheIndex floatingPanel.cache.indexOf(this);
        if (
cacheIndex != -1) {
            
floatingPanel.cache.splice(cacheIndex1);
        }

        
this.wrap null;
        
this.floatingElem null;

        
this.inited false;
    }
};

// обретка для fsSelect, позволяющая ему "плавать" за панелью
var fsSelectFloating = function (floatingPanelfsSelectOpts) {
    
nav2.gc(fsSelectFloating.gc'fsSelectFloating');
    return new 
fsSelect($.extend({
        
showFinder: function () {
            var 
self this;

            
fsSelectFloating.lastOpened self;

            if(
fsSelect.current == self.element) {return;}
            if(
self.disabled) {return;}
            else {
                $(
document)
                    .
unbind('click'fsSelect.hideFinder)
                    .
bind('click'fsSelect.hideFinder);
                var 
offsetPosition self.wrapper.offset(),
                    
headerHeight self.header.outerHeight(),
                    
headerWidth self.header.outerWidth();

                
fsSelect.current self.element;
                
self.wrapper.addClass('opened');
                
self.finderBox = $("#form-selector-box");
                if(
self.finderBox.length == 0self.finderBox = $('<div>', {'id' :'form-selector-box''onclick' "sp(event)"}).appendTo("#node-heap");

                
self.finderBox.css({
                    
'left' offsetPosition.left,
                    
'top' offsetPosition.top headerHeight 1,
                    
'width' headerWidth 2,
                    
'display''block',
                    
'z-index': (self.selectIndex self.selectIndex 2)
                }).
html("");

                var 
html self.render(self.array);
                
self.finderBox.html(html);

                var 
selected self.finderBox.find('.selected');
                
self.finderBox.scrollTop(selected.length self.finderBox.scrollTop() + selected.position().top 0);
            }

            if (($.
isFunction(floatingPanel) ? floatingPanel() : floatingPanel).floating) {
                
self.startFloat();
            }
        },
        
startFloat: function () {
            if(
this.finderBox) {
                
this.finderBox.css({
                    
position'fixed',
                    
topthis.wrapper.offset().top this.header.outerHeight() - - (($.isFunction(floatingPanel) ? floatingPanel() : floatingPanel) instanceof window.floatingPanel window.floatingPanel.windowScrollTop fs.scrollTop)
                });
            }
        },
        
stopFloat: function () {
            if(
this.finderBox) {
                
this.finderBox.css({
                    
position'',
                    
topthis.wrapper.offset().top this.header.outerHeight() - 1
                
});
            }
        }
    }, 
fsSelectOpts));
};
fsSelectFloating.lastOpened null;
fsSelectFloating.gc = function () {
    
fsSelectFloating.lastOpened null;
};

(function($) {
    $.
fn.timer = function(secondsoptions) {
        var 
settings = $.extend({
            
callback""
            
//format:
        
}, options),
        
style = ['visible','hidden']; // костыль для хрома
        /* ToDo:
            1. клерить $.fn.timer.interval если $.fn.timer.objs пустой
            3. добавить проверки на андефайнеты и прочие возможные ошибки
            5. Разобраться с костылем для хрома
        */
        
if(!$.fn.timer.interval) {
            $.
fn.timer.objs = [];
            var 
handler = function() {
                for(var 
0< $.fn.timer.objs.lengthi++) {
                    if($.
fn.timer.objs[i] && $.fn.timer.objs[i][1] >= 0) {
                        if($.
isFunction($.fn.timer.objs[i][2].format)) {
                            $($.
fn.timer.objs[i][0]).html($.fn.timer.objs[i][2].format($.fn.timer.objs[i][1]));
                        } else {
                            $($.
fn.timer.objs[i][0]).html(timeSmall($.fn.timer.objs[i][1], true));
                        }
                        if($.
isFunction($.fn.timer.objs[i][2].step)) {
                            $.
fn.timer.objs[i][2].step($($.fn.timer.objs[i][0]));
                        }
                        if ($.
browser.webkit) { // тоже костыль для хрома
                            
$($.fn.timer.objs[i][0]).css('overflow',style[$.fn.timer.objs[i][1] % 2]);
                        }
                        $.
fn.timer.objs[i][1]--;
                    } else {
                        if($.
isFunction($.fn.timer.objs[i][2].callback)) {
                            $.
fn.timer.objs[i][2].callback($($.fn.timer.objs[i][0]));
                        }
                        $.
fn.timer.objs.splice(i1);
                        
i--;
                    }
                }
            };
            
handler();
            $.
fn.timer.interval setInterval(handler1000);
        }
        return 
this.each(function() {
            $.
fn.timer.objs.push([thissecondssettings]);
        });
    };
})(
jQuery);


try{
staticManager.done('js_fs2_js')}catch(e){}
?>
Онлайн: 0
Реклама