var base_domain = 'http://123-realty.ru/';
var links_visibility = 66978303;
css_versions = extend(css_versions, {
  lib_ui_controls_js: 32,
  ui_controls_css: 12,

  privacy_css: 12,
  wiki_css: 11,
  gifts_css: 14
});

var is_rtl = false;
if (parent && parent != window && (browser.msie || browser.opera || browser.mozilla || browser.chrome || browser.safari || browser.iphone)) {
  if (parent.location.path.indexOf('vkontakte.ru') != -1) {
    setCookie('remixframe', 1, 0);
  } else {
    onDomReady(function() {    
      document.write('<h1 style="color: #F00">THIS IS NOT 123-REALTY.RU SITE</h1>');
    });
  }
}




Fast_find='Быстрый поиск';
head_search='поиск';
search_by_ad='по объявлениям';
search_by_app='по новостям';
search_by_audio='по статьям';
search_by_event='по блогу';
search_by_group='по пресс-релизам';
search_by_note='по форуму';
search_by_person='по соседям';
search_by_question='по вопросам';
search_by_topic='по событиям';
search_by_video='по советам';



// version = 753;

function langNumeric(count, variants) {
 if (!variants) {
  return count;
 }
 var result;
 if (isArray(variants)) {
  result = slavicNumbers(count, variants);
 } else {
   result = variants;
 }

 result = (result || '%s').replace('%s', count);
 return result;
}

function slavicNumbers(count, variants) {
 try { count = parseFloat(count); } catch(e) { return variants[3] || variants[1]; }
 if (count != Math.round(count)) {
   return variants[2] || variants[1];
 }
 count %= 100;
 if (count > 4 && count < 21) {
  return variants[3] || variants[1];
 }
 count %= 10;
 switch (count) {
  case 1: return variants[1]; break;
  case 2:
  case 3:
  case 4: return variants[2] || variants[1]; break;
  default: return variants[3] || variants[1];
 }
}
var market_currency_count = ['RUB','UAH','KZT','USD','EUR'];

var qArr = [[0, search_by_person, '', 'people', 0],
[1, search_by_group, '', 'groups', 0x00800000],
[2, search_by_event, '', 'events', 0x01000000],
[3, search_by_audio, '', 'audio',  0x00000002],
[4, search_by_video, '', 'video',  0x00400000],
[5, search_by_ad, '', 'ads', 0x00000100],
[6, search_by_app, '', 'apps', 0x00000020],
[7, search_by_question, '', 'questions', 0x00000040],
[8, search_by_note, '', 'notes', 0x02000000],
[9, search_by_topic, '', 'topics', 0x00800000]];

var year_offset = 0;

var larr = '&larr;';
var rarr = '&rarr;';  





 




// Кодировка, определись!

var css_versions = {};
var _ua = navigator.userAgent.toLowerCase();
var browser = {
  version: (_ua.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
  opera: /opera/i.test(_ua),
  msie: (!this.opera && /msie/i.test(_ua)),
  msie6: (!this.opera && /msie 6/i.test(_ua)),
  msie8: (!this.opera && /msie 8/i.test(_ua)),
  mozilla: /firefox/i.test(_ua),
  chrome: /chrome/i.test(_ua),
  safari: (!(/chrome/i.test(_ua)) && /webkit|safari|khtml/i.test(_ua)),
  iphone: /iphone/i.test(_ua)
}

function getLang(){
  try {
    var args = Array.prototype.slice.call(arguments);
    var key = args.shift();
    if (!key) return '...';
    var val = (window.lang && window.lang[key]) || (window.langpack && window.langpack[key]) || window[key];
    if (!val) {
      return key.replace(/_/g, ' ');
    }
    if (isFunction(val)) {
      return val.apply(null, args);
    } else if (isArray(val)) {
      return langNumeric(args[0], val);
    } else {
      return val;
    }
  } catch(e) {
    debugLog('lang error:' + e.message + '(' + Array.prototype.slice.call(arguments).join(', ') + ')');
  }
}
/**
 * DOM
 **/
function ge() {
  var ea;
  for (var i = 0; i < arguments.length; i++) {
    var e = arguments[i];
    if (typeof e == 'string')
      e = document.getElementById(e);
    if (arguments.length == 1)
      return e;
    if (!ea)
      ea = new Array();
    ea.push(e);
  }
  return ea;
}

var _logTimer = (new Date()).getTime();
function debugLog(msg){
  try {
    var t = '['+(((new Date()).getTime() - _logTimer)/1000)+'] ';
    if (ge('debuglog')) {
      if (msg===null) msg = '[NULL]'; else if (msg===undefined) msg = '[UNDEFINED]';
      ge('debuglog').innerHTML += t + msg.toString().replace('<', '&lt;').replace('>', '&gt;')+'<br/>';
    }
    if(window.console && console.log){console.log(t + msg);}
  } catch (e) {}
}

function geByClass(searchClass, node, tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  if (node.getElementsByClassName) {
    classElements = node.getElementsByClassName(searchClass);
    if (tag != '*') {
      for (i = 0; i < classElements.length; i++) {
        if (classElements.nodeName == tag)
          classElements.splice(i, 1);
      }
    }
    return classElements;
  }
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function show(elem) {
  if (arguments.length > 1) {
    for (var i = 0; i < arguments.length; i++) {
      show(arguments[i]);
    }
    return;
  }
  elem = ge(elem);
  if (!elem) return;
  var old = data(elem, "olddisplay");
  elem.style.display = old || "";

  if (getStyle(elem, 'display') == "none" ) {
    if (elem.tagName.toLowerCase() == 'tr' && !browser.msie) {
      elem.style.display = 'table-row';
    } else if (elem.tagName.toLowerCase() == 'table' && !browser.msie) {
      elem.style.display = 'table';
    } else {
      elem.style.display = data(elem, "olddisplay", "block");
    }
  }
}

function hide(elem){
  if (arguments.length > 1) {
    for (var i = 0; i < arguments.length; i++) {
      hide(arguments[i]);
    }
    return;
  }
  elem = ge(elem);
  if (!elem) return;
  if (getStyle(elem, 'display') != "none")
    data(elem, "olddisplay", elem.style.display);
  elem.style.display = "none";
}
function isVisible(elem) {
 elem = ge(elem);
 return getStyle(elem, 'display') != 'none' && getStyle(elem, 'visibility') != 'hidden';
}
function toggle(elem) {
  if (isVisible(elem)) {
    hide(elem);
  } else {
    show(elem);
  }
}
window.shide = toggle;

var hfTimeout;
function toggleFlash(show, timeout) {
 if (/mac/i.test(navigator.userAgent)) return;
 clearTimeout(hfTimeout);
 if (timeout > 0) {
   hfTimeout = setTimeout(function(){toggleFlash(show, 0)}, timeout);
   return;
 }
 var body = document.getElementsByTagName('body')[0];

 var f = function() {
   if (this.getAttribute('preventhide')) {
     return;
   } else if  (this.id == 'app_container' && browser.msie)
     show ? setStyle(this, {position:"static", top:0}) : setStyle(this, {position:"absolute", top:"-5000px"});
   else
     this.style.visibility = show ? 'visible' : 'hidden';
 };
 each(body.getElementsByTagName('embed'), f);
 each(body.getElementsByTagName('object'), f);
}

function getXY(obj) {
 if (!obj || obj == undefined) return;
 var left = 0, top = 0;
 if (obj.offsetParent) {
  do {
   left += obj.offsetLeft;
   top += obj.offsetTop;
  } while (obj = obj.offsetParent);
 }
 return [left,top];
}

function getSize(elem, withoutBounds) {
  var s = [0, 0];
  if (elem == document) {
    s =  [Math.max(
        document.documentElement["clientWidth"],
        document.body["scrollWidth"], document.documentElement["scrollWidth"],
        document.body["offsetWidth"], document.documentElement["offsetWidth"]
      ), Math.max(
        document.documentElement["clientHeight"],
        document.body["scrollHeight"], document.documentElement["scrollHeight"],
        document.body["offsetHeight"], document.documentElement["offsetHeight"]
      )];
  } else if (elem){
    function getWH() {
      s = [elem.offsetWidth, elem.offsetHeight];
      if (!withoutBounds) return;
      var padding = 0, border = 0;
      each(s, function(i, v) {
        var which = i ? ['Top', 'Bottom'] : ['Left', 'Right'];
        each(which, function(){
          s[i] -= parseFloat(getStyle(elem, "padding" + this)) || 0;
          s[i] -= parseFloat(getStyle(elem, "border" + this + "Width")) || 0;
        });
      });
      s = [Math.round(s[0]), Math.round(s[1])];
    }
    if (!isVisible(elem)) {
      var props = {position: "absolute", visibility: "hidden", display:"block"};
      var old = {};
      each(props, function(i, val){
        old[i] = elem.style[i];
        elem.style[i] = val;
      });
      getWH();
      each(props, function(i, val){
        elem.style[i] = old[i];
      });
    } else getWH();

  }
  return s;
}


/**
 *  Useful utils
 */

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
};
function isFunction(obj) { return Object.prototype.toString.call(obj) === "[object Function]"; }
function isArray(obj) { return Object.prototype.toString.call(obj) === "[object Array]"; }
function isEmpty(o) { if(Object.prototype.toString.call(o) !== "[object Object]") {return false;} for(var i in o){ if(o.hasOwnProperty(i)){return false;} } return true; }
function now() { return +new Date; }
function trim(text) { return (text || "").replace(/^\s+|\s+$/g, ""); }
function stripHTML(text) { return text ? text.replace(/<(?:.|\s)*?>/g, "") : ''; }
function escapeRE(s) { return s ? s.replace(/[.*+?^${}()|[\]\/\\]/g, '\\$0') : ''; }
function intval(value) {
  if (value === true) return 1;
  return isNaN(parseInt(value)) ? 0 : parseInt(value);
}
function winToUtf(text) {
  var m, i, j, code;
  m = text.match(/&#[0-9]{2}[0-9]*;/gi);
  for (j in m) {
    var val = '' + m[j]; // buggy IE6
    code = intval(val.substr(2, val.length - 3));
    if (code >= 32 && ('&#' + code + ';' == val)) { // buggy IE6
      text = text.replace(val, String.fromCharCode(code));
    }
  }
  text = text.replace(/&quot;/gi, '"').replace(/&amp;/gi, '&').replace(/&lt;/gi, '<').replace(/&gt;/gi, '>');
  return text;
}

/**
 *  Arrays, objects
 **/

function each(object, callback) {
  var name, i = 0, length = object.length;

  if ( length === undefined ) {
    for ( name in object )
      if ( callback.call( object[ name ], name, object[ name ] ) === false )
        break;
  } else
    for ( var value = object[0];
      i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}

  return object;
};
function indexOf(arr, value, from) {
  from = (from == null) ? 0 : from;
  var m = arr.length;
  for(var i = from; i < m; i++)
    if (arr[i] == value)
       return i;
   return -1;
}

function clone(obj) {
  var newObj = {};
  for (var i in obj) {
    newObj[i] = obj[i];
  }
  return newObj;
}

// Extending object by another
function extend() {
  var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;

  if (typeof target === "boolean") {
    deep = target;
    target = arguments[1] || {};
    i = 2;
  }

  if (typeof target !== "object" && !isFunction(target))
    target = {};

  if (length == i) {
    return target;
  }

  for (; i < length; i++)
    if ((options = arguments[i]) != null)
      for (var name in options) {
        var src = target[name], copy = options[name];

        if (target === copy)
          continue;

        if (deep && copy && typeof copy === "object" && !copy.nodeType)
          target[name] = extend(deep,
            src || (copy.length != null ? [] : { })
          , copy);

        else if (copy !== undefined)
          target[name] = copy;
      }
  return target;
}


/**
 * CSS classes
 **/

function hasClass(obj, name) {
  obj=ge(obj);
  return obj && (new RegExp('(\\s|^)' + name + '(\\s|$)')).test(obj.className);
}

function addClass(obj, name) {
  obj=ge(obj);
  if (obj && !hasClass(obj, name)) obj.className = (obj.className ? obj.className + ' ' : '') + name;
}

function removeClass(obj, name) {
  obj=ge(obj);
  if (obj && hasClass(obj, name)) obj.className = obj.className.replace((new RegExp('(\\s|^)' + name + '(\\s|$)')), ' ');
}
//shortcuts
function btnOut(o){removeClass(geByClass('box_button', o)[0], 'button_hover');}
function btnOver(o){addClass(geByClass('box_button', o)[0], 'button_hover');}


// Get computed style
function getStyle(elem, name, force) {
  elem = ge(elem);
  if (force === undefined)
    force = true;
  if (!force && name == 'opacity' && browser.msie) {
    var filter = elem.style['filter'];
    return filter ? (filter.indexOf("opacity=") >= 0 ?
      (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1') : '';
  }
  if (!force && elem.style && (elem.style[name] || name == 'height'))
    return elem.style[name];

  if (force && (name == "width" || name == "height")) {
    return getSize(elem, true)[({'width':0, 'height':1})[name]] + 'px';
  }

  var ret, defaultView = document.defaultView || window;
  if (defaultView.getComputedStyle) {
    name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
    var computedStyle = defaultView.getComputedStyle( elem, null );
      if (computedStyle)
        ret = computedStyle.getPropertyValue(name);
  } else if (elem.currentStyle) {
    if (name == 'opacity' && browser.msie) {
      var filter = elem.currentStyle['filter'];
      return filter && filter.indexOf("opacity=") >= 0 ?
        (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1';
    }
    var camelCase = name.replace(/\-(\w)/g, function(all, letter){
      return letter.toUpperCase();
    });
    ret = elem.currentStyle[name] || elem.currentStyle[camelCase];
    //dummy fix for ie
    if(ret == 'auto')ret = 0;
    // If we're not dealing with a regular pixel number
    // but a number that has a weird ending, we need to convert it to pixels
    if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
      // Remember the original values
      var left = style.left, rsLeft = elem.runtimeStyle.left;

      // Put in the new values to get a computed value out
      elem.runtimeStyle.left = elem.currentStyle.left;
      style.left = ret || 0;
      ret = style.pixelLeft + "px";

      // Revert the changed values
      style.left = left;
      elem.runtimeStyle.left = rsLeft;
    }
  }
  return ret;
}

function setStyle(elem, name, value){
  elem = ge(elem);
  if (typeof name == 'object') return each(name, function(k,v){setStyle(elem,k,v);});
  if (name == 'opacity'){
    if (browser.msie) {
      if ((value + '').length) {
        elem.style.filter = "alpha(opacity=" + value*100 + ")";
      } else {
        elem.style.filter = '';
      }
      elem.style.zoom = 1;
    };
    elem.style.opacity = value;
  } else {
    var isNum = typeof(value) == 'number' && !(/z-?index|font-?weight|opacity|zoom|line-?height/i).test(name);
    if(isNum && value < 0 && (/^(width|height)$/i).test(name)){
      value = 0; //fix for IE;
    }
    elem.style[name] = isNum ? value + 'px': value;
  }
}
function swapStyle(elem, options, callback) {
  elem = ge(elem);
  var old = {};
  for (var name in options) {
    old[name] = elem.style[name];
    elem.style[name] = options[name];
  }
  callback.call(elem);
  for (var name in options)
      elem.style[name] = old[ name ];
}

/**
 * Store data connected to element
 **/

var expand = "VK" + now(), vk_uuid = 0, vk_cache = {};

// Get or set element data
function data(elem, name, data) {
  var id = elem[ expand ], undefined;
  if ( !id )
    id = elem[ expand ] = ++vk_uuid;

  if (name && !vk_cache[id])
    vk_cache[id] = {};

  if (data !== undefined)
    vk_cache[id][name] = data;

  return name ?
    vk_cache[id][name] :
    id;
}

function removeData(elem, name) {
  var id = elem[expand];
  if (name) {
    if (vk_cache[id]) {
      delete vk_cache[id][name];
      name = "";
      for (name in vk_cache[id])
        break;

      if (!name)
        removeData(elem);
    }
  } else {
    try {
      delete elem[expand];
    } catch(e){ // fix for IE
      if (elem.removeAttribute)
        elem.removeAttribute(expand);
    }
    delete vk_cache[id];
  }
}

/**
 * Simple FX
 **/
function animate(el, params, speed, callback) {
  el = ge(el);
  var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: callback || function(){}});
  var fromArr = {}, toArr = {}, visible = isVisible(el), self = this, p;
  options.orig = {};
  params = clone(params);

  var tween = data(el, 'tween'), i, name, toggleAct = visible ? 'hide' : 'show';
  if (tween && tween.isTweening) {
    options.orig = extend(options.orig, tween.options.orig);
    tween.stop(false);
    if (tween.options.show) toggleAct = 'hide';
    else if (tween.options.hide) toggleAct = 'show';
  }
  for (p in params)  {
    if (!tween && (params[p] == 'show' && visible || params[p] == 'hide' && !visible))
      return options.onComplete.call(this, el);
    if ((p == "height" || p == "width") && el.style) {
      if (options.orig.overflow == undefined) {
        options.orig.overflow = getStyle(el, 'overflow');
      }
      el.style.overflow = 'hidden';
      el.style.display = 'block';
    }
    if (/show|hide|toggle/.test(params[p])) {
      if (params[p] == 'toggle')
        params[p] = toggleAct;
      if (params[p] == 'show') {
        var from = 0;
        options.show = true;
        if (options.orig[p] == undefined) {
          options.orig[p] = getStyle(el, p, false) || '';
          setStyle(el, p, 0);
        }
        var sopt = {};
        if (p == 'height' && browser.msie6) {
          sopt[p] = '0px';
          el.style.overflow = '';
        } else {
          sopt[p] = options.orig[p];
        }
        swapStyle(el, sopt, function() {
          params[p] = parseFloat(getStyle(el, p, true));
        });
        if (p == 'height' && browser.msie) {
          el.style.overflow = 'hidden';
        }
      } else {
        if (options.orig[p] == undefined) {
          options.orig[p] = getStyle(el, p, false) || '';
        }
        options.hide = true;
        params[p] = 0;
      }
    }
  }
  if (options.show && !visible)
    show(el);
  tween = new Fx.Base(el, options);
  each(params, function(name, to) {
    if (/backgroundColor|borderBottomColor|borderLeftColor|borderRightColor|borderTopColor|color|borderColor|outlineColor/.test(name)) {
      var p = (name == 'borderColor') ? 'borderTopColor' : name;
      from = getColor(el, p);
      to = getRGB(to);
    } else {
      var parts = to.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
        start = tween.cur(name, true) || 0;
      if (parts) {
        to = parseFloat(parts[2]);
        if ( parts[1] )
          to = ((parts[1] == "-=" ? -1 : 1) * to) + to;
      }

      if (options.hide && name == 'height' && browser.msie6) {
        el.style.height = '0px';
        el.style.overflow = '';
      }
            from = tween.cur(name, true);
      if (options.hide && name == 'height' && browser.msie6) {
        el.style.height = '';
        el.style.overflow = 'hidden';
      }
      if (from == 0 && (name == "width" || name == "height"))
        from = 1;

      if (name == "opacity" && to > 0 && !visible) {
        setStyle(el, 'opacity', 0);
        from = 0;
        show(el);
      }
    }
    if (from != to || (isArray(from) && from.join(',') == to.join(','))) {
      fromArr[name] = from;
      toArr[name] = to;
    }
  });
  tween.start(fromArr, toArr);
  data(el, 'tween', tween);

  return tween;
}

function fadeTo(el, speed, to, callback) {return animate(el, {opacity: to}, speed, callback);}

var Fx = fx = {
 Transitions: {
  linear: function(t, b, c, d) { return c*t/d + b; },
  sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; },
  halfSine: function(t, b, c, d) { return c * Math.sin(Math.PI * (t/d) / 2) + b; },
  easeOutBack: function(t, b, c, d) { var s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; }
 },
 Attrs: [
  [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
  [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
  [ "opacity" ]
 ],
 Timers: [],
 TimerId: null
};
Fx.Base = function(el, options, name){
  this.el = ge(el);
  this.name = name;
  this.options = extend({
    onComplete: function(){},
    transition: Fx.Transitions.sineInOut,
    duration: 500
  }, options || {});
};

function genFx(type, num){
  var obj = {};
  each( Fx.Attrs.concat.apply([], Fx.Attrs.slice(0,num)), function(){
    obj[this] = type;
  });
  return obj;
};

// Shortcuts for custom animations
each({slideDown: genFx('show', 1),
 slideUp: genFx('hide', 1),
 slideToggle: genFx('toggle', 1),
 fadeIn: {opacity: 'show'},
 fadeOut: {opacity: 'hide'},
 fadeToggle: {opacity: 'toggle'}}, function(f, val){
 window[f] = function(el, speed, callback){return animate(el, val, speed, callback);}
});

Fx.Base.prototype = {
  start: function(from, to){
    this.from = from;
    this.to = to;
    this.time = now();
    this.isTweening = true;

    var self = this;
    function t(gotoEnd) {
      return self.step(gotoEnd);
    }
    t.el = this.el;
    if (t() && Fx.Timers.push(t) && !Fx.TimerId) {
      Fx.TimerId = setInterval(function(){
        var timers = Fx.Timers;
        for (var i = 0; i < timers.length; i++)
          if (!timers[i]())
            timers.splice(i--, 1);
        if (!timers.length) {
          clearInterval(Fx.TimerId);
          Fx.TimerId = null;
        }
      }, 13);
    }
    return this;
  },

  stop: function(gotoEnd) {
    var timers = Fx.Timers;
    // go in reverse order so anything added to the queue during the loop is ignored
    for (var i = timers.length - 1; i >= 0; i--)
      if (timers[i].el == this.el ) {
        if (gotoEnd)
          // force the next step to be the last
          timers[i](true);
        timers.splice(i, 1);
      }
    this.isTweening = false;
  },

  step: function(gotoEnd){
    var time = now();
    if (!gotoEnd && time < this.time + this.options.duration){
      this.cTime = time - this.time;
      this.now = {};
      for (p in this.to) {
        // color fx
        if (isArray(this.to[p])) {
          var color = [], j;
          for (j = 0; j < 3; j++)
            color.push(Math.min(parseInt(this.compute(this.from[p][j], this.to[p][j])), 255));
          this.now[p] = color;
        } else
          this.now[p] = this.compute(this.from[p], this.to[p]);
      }
      this.update();
      return true;
    } else {
//      if (this.el.className == 'im_tab3') alert('this.time: ' + this.time + ', ' + (time - this.time) + ' > ' + this.options.duration);
      setTimeout(this.options.onComplete.bind(this, this.el), 10);
      this.now = extend(this.to, this.options.orig);
      this.update();
      if (this.options.hide) hide(this.el);
      this.isTweening = false;
      return false;
    }
  },

  compute: function(from, to){
    var change = to - from;
    return this.options.transition(this.cTime, from, change, this.options.duration);
  },

  update: function(){
    for (var p in this.now) {
      if (isArray(this.now[p])) setStyle(this.el, p, 'rgb(' + this.now[p].join(',') + ')');
      else this.el[p] != undefined ? (this.el[p] = this.now[p]) : setStyle(this.el, p, this.now[p]);
    }
  },

  cur: function(name, force){
    if (this.el[name] != null && (!this.el.style || this.el.style[name] == null))
      return this.el[name];
    return parseFloat(getStyle(this.el, name, force)) || 0;
  }
};



/**
 * Cookies
 **/

var _cookies;
function _initCookies() {
  _cookies = {};
  var ca = document.cookie.split(';');
  var re = /^[\s]*([^\s]+?)$/i;
  for(var i = 0; i < ca.length; i++) {
    var c = ca[i].split("=");
    if(c.length == 2) {
     _cookies[c[0].match(re)[1]] = unescape(c[1].match(re) ? c[1].match(re)[1] : '');
    }
  }
}
function getCookie(name) {
  if(!_cookies) _initCookies();
  return _cookies[name];
}
function setCookie(name, value, days) {
  if(!_cookies) _initCookies();
  _cookies[name] = value;
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  var domain = location.host.match(/[^.]+\.[^.]+$/);
  document.cookie = name+"="+escape(value)+expires+"; path=/"+(domain ? '; domain=.'+domain : '');
}

/**
 * Other stuff
 **/

function dispatchIntro(step, params) {
  if (typeof dispatchIntroEvent != 'undefined') {dispatchIntroEvent(step, params);}
}

var send_request_url = 'http://userapi.com/data?';

var qCur = 0, qOn = 0, sOn = 0, qfOn = 0, qd = 0, l = 0, qa = 0, qfCur = -1, newSearch = 0;
// var qArr is in langpack

reqs = []; res = [];
friends_l = [];
friends_arr = [];
floaded = false;

function doRequest(params, resultFunc) {
  var req = createRequest(params, resultFunc);
  sendRequest(req);
}

function createRequest(params, resultFunc) {
  var req = new Object();
  req.params = params;
  req.resultFunc = resultFunc;
  req.destroy = destroy;
  var rnum = Math.floor(Math.random()*1000);
  req.num = rnum;
  req.running = 1;
  reqs[rnum] = req;
  return req;
}

function getFriends() {
 doRequest('&id='+getCookie('remixmid')+'&act=friends&to=2500&w=50', gotFriends);
}

function gotFriends(result) {
 friends_arr = result;
 var l = friends_arr.length;
 for (var i = 0; i < l; i++) {
  friends_l[i] = friends_arr[i][1].toLowerCase();
 }
 floaded = true;
}

function friendNav(k) {
  if (k == 38) {
   if (qd) {if (qCur > 0) {qCur = qCur - 1} else {qCur = qArr.length-1}; genQDrop(); return true}
   if (qfCur > -1) {qfrOn(qfCur-1)} else {qfrOn(l-1)}
   return true;
  }
  if (k == 40) {
   if (qd) {if (qCur < qArr.length-1) {qCur = qCur + 1} else {qCur = 0}; genQDrop(); return true}
   if (qfCur < l - 1) {qfrOn(qfCur+1)} else {qfrOn(-1)}
   return true;
  }
  if (k == 27) {
    searchOut(ge('qinput'));
    return false;
  }
  if (k == 13) {
   if (qd) {hideQDrop(qCur); return true;}
   if (!parseInt(qCur) && qfCur > -1 && res.length && res[qfCur] && res[qfCur][0]) {
    window.location = base_domain+'id'+res[qfCur][0];
    return true;
   } else {
    if (!newSearch) {
     qDoSearch();
    } else {
     globalSearch();
    }
    return false;
   }
  }
  return true;
 }

function friendFilter(e) {
 var k = 0;
 if (e) {
  k = e.keyCode;
  if (!friendNav(k)) {
    return;
  }
 }

 if (parseInt((qArr[qCur]||[])[0])) {return;}

 res = [];
 if (!floaded) {
  qfCur = -1;
  getFriends();
  setTimeout(friendFilter, 700);
 }

 var st = 0, en = 0, img, cl, name, q_lat;
 var q = ge('qinput').value.toLowerCase();
 if (!q.length && k != 8) {
  return;
 }

// hideQDrop(qCur);

 q_lat = parseLatin(q);
 l = friends_l.length;
 for (var i = 0; i < l; i++) {
  if (q.length && friends_l[i].indexOf(q) != -1) {
   res.push(friends_arr[i]);
  } else if (q_lat && q_lat.length && friends_l[i].indexOf(q_lat) != -1) {
   res.push(friends_arr[i]);
  }
 }


 var str = '', onl = '';
 l = res.length;
 if (l > 10) {l = 10;}
 if (l) {
  for (var i = 0; i < l; i++) {
   name = res[i][1];
   if (qfCur == i) {cl = 'qfr_cell_on'} else if (qfCur > -1 && qfCur == i - 1) {cl = 'qfr_cell_un'} else {cl = 'qfr_cell'}
   pos = name.toLowerCase().indexOf(q);
   if (pos == -1 && q_lat && q_lat.length) {
    q = q_lat;
    pos = name.toLowerCase().indexOf(q);
   }
   if (pos != -1) {
    if (res[i][2].length > 1) {img = "<img src='"+res[i][2]+"'>";} else {img = "?";}
    if (res[i][3]) {onl = "<b class='qonl'>online</b>";} else {onl = "";}
    name = name.substr(0, pos) + "<span>" + name.substr(pos, q.length) + "</span>" + name.substr(pos+q.length);
   }
   var lnk = '<a href="'+base_domain+'mail.php?act=write&to='+res[i][0]+'" onclick="cancelEvent(event); return showBox(\'sendMsg\', \'mail.php\', {act: \'a_write_box\', to: '+res[i][0]+'}, true, true, {title: \''+(window['profile_newmsg_box_title'] || 'Новое сообщение')+'\', progress: \'sending_progress\', width: 450});" class="qfr_lnk">'+(window['global_write_msg'] || 'Написать сообщение')+'</a>';
   str += "<div id='qfr"+i+"' class='"+cl+"' onmousemove=\"qfrOn("+i+")\" onmouseout=\"qfrOff("+i+")\" onclick=\"window.location='"+base_domain+"id"+res[i][0]+"'\">"+lnk+"<table border=0><tr><td><div>"+img+"</div></td><td>"+name+onl+"</td></tr></table></div>";
  }
  show('qfriends');
  toggleFlash();
 } else {
  hide('qfriends');
  toggleFlash(true, 20);
 }
 ge('qfriends').innerHTML = str;
}




function destroy() {
 if (reqs[this.num]) {
  reqs[this.num].running = 0;
 }
}




function searchOn(obj) {
setTimeout(function() {  if (!qd) toggleFlash(true, 20);
  sOn = 1;
  var qq = ge('qquery');
  var ph = obj.getAttribute('placeholder');
  if (obj.value && obj.value != ph) {return;}
  hide('topNav');
  var pageOffset = ge('pageLayout').offsetWidth-791 + (browser.msie6 ? -15 : 0);
  qq.style.width = (browser.iphone) ? '238px': (618+pageOffset)+'px';
  obj.style.width = (browser.iphone) ? '68px': (448+pageOffset)+'px';
  ge('quickSearch').style.width = (browser.iphone) ? '245px': (625+pageOffset)+'px';
  obj.value = '';
  var qs = qd ? 'qdrop_on' : 'qdrop_off';
  ge('qchoose').innerHTML = "<div onclick=\"showQDrop()\" id='qdrop' class='"+qs+"' onmousemove=\"qOn = 1;if (!qd) {this.className='qdrop_over'}\" onmouseout=\"qOn = 0; if (!qd) {this.className='qdrop_off'}\">"+qArr[qCur][1]+"</div>";
  genQDrop();
  obj.style.color = '#000';
  if (!qa) showQDrop(); }, 0);
}

function searchOut(qi) {
 if (qOn || qfOn) {return;}
 hide('qfriends');
 sOn = 0;
// toggleFlash(true, 20);
 if (qd)
   hideQDrop(qCur);
 else
   toggleFlash(true, 20);
 qi.blur();
 qd = 0;
 var ph = qi.getAttribute('placeholder');
 if (qi.value && qi.value != ph) {
   return;
 }
 ge('qchoose').innerHTML = "";
 var qq = ge('qquery');
 qi.style.color = '#777';
 qi.style.width = '85px';
 qq.style.width = '105px';
 ge('quickSearch').style.width = '112px';
 show('topNav');
 qi.value = ph; qa = 0;
}

function genQDrop() {
 var str = '', qoff, qover, st = '', j;
 for (j = qArr.length - 1; j > -1; j--) {
  if (links_visibility & qArr[j][4] || !qArr[j][4]) {
   break;
  }
 }
 for (var i = 0; i < qArr.length; i++) {
  if (i != qCur) {qoff = 'qdiv_off', qover = 'qdiv_over'; if (!i) {qover='qdiv_over_top';}} else {qoff = 'qdiv_on', qover = 'qdiv_on';}
  if (i == j) {st = "style='border-bottom: 1px solid ";if (i!=qCur){st+="#2A5883;'";}else{st+="#839EB7;'";}} else {st='';}
  if (links_visibility & qArr[i][4] || !qArr[i][4]) {
   str += "<div onclick='hideQDrop("+i+")' class='"+qoff+"' onmousemove=\"qOn = 1; if(qd) this.className='"+qover+"'\" onmouseout=\"qon=0; this.className='"+qoff+"'\" "+st+">"+qArr[i][1]+"</div>";
  }
 }
 ge('qdropdown').innerHTML = str;
}

function startHide() {
 if (qOn) return;
 hideQDrop(qCur);
}

function showQDrop() {
 if (qd) {hideQDrop(qCur);return;}
// alert(ge('qdropdown').style.display);
//  hideQDrop(qCur);return;
 toggleFlash();
 hide('qfriends');
 genQDrop();
 qd = 1; qa = 1; qOn = 1;
 ge('qdrop').className = 'qdrop_on';
 show('qdropdown');
 dispatchIntro(2);
// ge('qinput').focus();
}

function hideQDrop(i) {
 if (!qd) return;
 qOn = 0; qCur = i; qd = 0;
 var qdrop = ge('qdrop');
 if (qdrop) {
  qdrop.innerHTML = qArr[i][1];
  qdrop.className = 'qdrop_off';
  hide('qdropdown');
 }
 toggleFlash(true, 20);
 if (sOn) ge('qinput').focus();
 dispatchIntro(3);
}

function qDoSearch() {
 var qi = ge('qinput');
 var names_only = "";
 var ph = qi.getAttribute('placeholder');
 if (!qi.value || qi.value == ph) {return;}
 if (!qCur && qi.value) {names_only = "&name=1";}
 window.location = base_domain+'search.php?section='+qArr[qCur][3]+'&q='+qi.value+names_only;
}



function doCnt(){
  document.ads_form.cnt.value=document.ads_form.ads_description.value.length;

}
