var base_domain = base_domain || "/";

/**
 * 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;
}

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" ) {
		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;

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, woBounds) {
  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 (!woBounds) 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 now() {
  return +new Date;
}

function trim(text) {
  return (text || "").replace(/^\s+|\s+$/g, "");
}

/**
 *  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;
};



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

	// Handle a deep copy situation
	if (typeof target === "boolean") {
		deep = target;
		target = arguments[1] || {};
		// skip the boolean and the target
		i = 2;
	}

	// Handle case when target is a string or something (possible in deep copy)
	if (typeof target !== "object" && !isFunction(target))
		target = {};

	// return target object if only one argument is passed
	if (length == i) {
		return target;
	}

	for (; i < length; i++)
		// Only deal with non-null/undefined values
		if ((options = arguments[i]) != null)
			// Extend the base object
			for (var name in options) {
				var src = target[name], copy = options[name];

				// Prevent never-ending loop
				if (target === copy)
					continue;

				// Recurse if we're merging object values
				if (deep && copy && typeof copy === "object" && !copy.nodeType)
					target[name] = extend(deep, 
						// Never move original objects, clone them
						src || (copy.length != null ? [] : { })
					, copy);

				// Don't bring in undefined values
				else if (copy !== undefined)
					target[name] = copy;
			}

	// Return the modified object
	return target;
}


/**
 * CSS classes
 **/



// Get computed style
function getStyle(elem, name) {  
  
  if (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];
		// 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 (name == 'opacity'){
    if (browser.msie) {elem.style.filter = "alpha(opacity=" + value*100 + ")"; elem.style.zoom = 1; };
    elem.style.opacity = value;
  } else elem.style[name] = typeof(value) == 'number' && !(/z-?index|font-?weight|opacity|zoom|line-?height/i).test(name) ? value + 'px': value;
}

/**
 * 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;
}



/**
 * Simple FX
 **/
function animate(el, params, speed, callback) {
  el = ge(el);
  var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: callback || function(){}});
  var tween = data(el, 'tween');
  if (tween) {
    tween.setOptions(options);
  } else {
    tween = data(el, 'tween', new Fx.Base(el, options));
  }
  return tween.custom(params);
}

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

var Fx = 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; }
};

Fx.Attrs = [
  [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
  [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
  [ "opacity" ]
];

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 = function(el, options){
  this.element = ge(el);
  this.setOptions(options);
  this.now = {};
};
Fx.Base.prototype = {

  setOptions: function(options){
    if (this.isTweening()) return;
    this.options = extend({
      onComplete: function(){},
      transition: Fx.Transitions.sineInOut,
      duration: 500
    }, options || {});
  },

  step: function(){
    var time = new Date().getTime();
    if (time < this.time + this.options.duration){
      this.cTime = time - this.time;
      this.setNow();
    } else {
      setTimeout(this.options.onComplete.bind(this, this.element), 10);
      this.clearTimer();
      this.now = this.to;
      if (this.options.hide) hide(this.element);
      if (this.options.hide) {
        this.now = this.options.orig;
      }
      this.increase();
      return false;
    }
    this.increase();
    return true;
  },

  setNow: function(){
    for (p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]);
  },

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

  clearTimer: function(){
    clearInterval(this.timer);
    this.timer = null;
    return this;
  },

  _start: function(from, to){
    if (this.timer) return;
    this.from = from;
    this.to = to;
    this.time = new Date().getTime();
    if (this.step()) this.timer = setInterval(this.step.bind(this), 13);
    return this;
  },

  increase: function(){
    for (var p in this.now) setStyle(this.element, p, this.now[p]);
  },

  isTweening: function() {
    return this.timer ? true : false;
  },

  custom: function(prop){
    if (this.isTweening()) return false;
    
    var from = {}, to = {}, visible = isVisible(this.element), from_val, self = this;
    
    self.options.show = self.options.hide = false;
    self.options.orig = {};
    
    for (p in prop) { 
      if (prop[p] == 'show' && visible || prop[p] == 'hide' && !visible) 
        return this.options.onComplete.call(this, this.element);
    }
    each(prop, function(name, val){
      from_val = parseFloat(getStyle(self.element, name)) || 0;
      val = val == 'toggle' ? visible ? 'hide' : 'show' : val;
      if (val == 'show') {
        self.options.show = true;
        val = from_val;
        from_val = (name == "width" || name == "height" ? 1 : 0);
        show(self.element);
      } else if (val == 'hide') {
        self.options.hide = true;
        self.options.orig[name] = getStyle(self.element, name);
        val = 0;
      } else {
        var parts = val.toString().match(/^([\d+-.]+)(.*)$/);
        val = parts ? parseFloat(parts[1]) : val;
      }
      
      if ((name == "height" || name == "width") && self.element.style) {
        self.element.style.overflow = 'hidden';
        self.element.style.display = 'block';
      }
      if (name == "opacity" && val > 0 && !visible) {
        setStyle(self.element, 'opacity', 0);
        from_val = 0;
        show(self.element);
      }
      
      if (from_val != val) {
        from[name] = from_val;
        to[name] = val;
      }
    });
    return this._start(from, to);
  }
};

	
/**
 * Events
 **/
var KEY = window.KEY = {
  LEFT: 37,
 	UP: 38,
 	RIGHT: 39,
 	DOWN: 40,
 	DEL: 8,
 	TAB: 9,
 	RETURN: 13,
 	ESC: 27,
 	PAGEUP: 33,
 	PAGEDOWN: 34,
 	SPACE: 32
 };
 








/**
 * Ajax
 **/

 
 function Ajax(onDone, onFail, eval_res){
 	var _t = this;
 	this.onDone = onDone;
 	this.onFail = onFail;
 	var tram = null;
 	try { tram = new XMLHttpRequest(); }
 	catch(e) { tram = null; }
 	if (!tram) {
 	 try { if(!tram) tram = new ActiveXObject("Msxml2.XMLHTTP"); }
 	 catch(e) { tram = null; }
 	}
 	if (!tram) {
 	 try { if(!tram) tram = new ActiveXObject("Microsoft.XMLHTTP"); }
 	 catch(e) { tram = null; }
 	}
 	
 	var readystatechange = function(url, data) {
			if(tram.readyState == 4 ) {
 			if(tram.status >= 200 && tram.status < 300) {
 				if(eval_res) parseRes();
 				if( _t.onDone ) _t.onDone(extend(_t, {url: url, data: data}), tram.responseText);
 			} else {
 				if( _t.onFail ) _t.onFail(extend(_t, {url: url, data: data}), tram.responseText);
 			}
 		}
	};

 	var parseRes = function(){
 		if(!tram || !tram.responseText)return;
 		var res = tram.responseText.replace(/^[\s\n]+/g, '');

 		if(res.substr(0,10)=="<noscript>")
 		{
 			try{
 				var arr = res.substr(10).split("</noscript>");
 				eval(arr[0]);
 				tram.responseText = arr[1];
 			}catch(e){
 			}
 		}else{}
 	};
 	this.get = function(u, d, f){
 		tram.onreadystatechange = function(){ readystatechange(u, d); };
 		f = f || false;
 		var q = (typeof(d) != 'string') ? ajx2q(d) : d;
 		u = u + (q ? ('?'+q) : '');
 		tram.open('GET', u, !f);
 		
 		tram.setRequestHeader("X-Requested-With", "XMLHttpRequest");
 		tram.send('');
 	};
 	this.post = function(u, d, f){ 		
 	  tram.onreadystatechange = function(){ readystatechange(u, d); };
 		f = f || false;
 		var q = (typeof(d) != 'string') ? ajx2q(d) : d;
 		try {
 		  tram.open('POST', u, !f);
 	  } catch(e) {
 	    alert('ERROR. Please disable AdBlock or some other buggy component in your browser. Studio DizelBox (http://inmybook.ru).');
 		}
 		tram.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 		tram.setRequestHeader("X-Requested-With", "XMLHttpRequest");
 		tram.send(q);
 	};
 	
 }

(function(){
  var ajaxObjs = {};
  window.Ajax.Get = function(p){
    var a = (p.key)?ajaxObjs[p.key]:null;
    if(!a){
      a = new Ajax(p.onDone, p.onFail, p.eval); 
      if(p.key)ajaxObjs[p.key] = a;
    }
    a.get(p.url, p.query, p.sync);
  }
  window.Ajax.Post = function(p){
    var a = (p.key)?ajaxObjs[p.key]:null;
    if(!a){
      a = new Ajax(p.onDone, p.onFail, p.eval); 
      if(p.key)ajaxObjs[p.key] = a;
    }
    a.post(p.url, p.query, p.sync);
  }
  window.Ajax.postWithCaptcha = function(url, data, options){
    var onSuccess, onFail, onCaptchaShow, onCaptchaHide;
    onSuccess = options.onSuccess;
    onFail = options.onFail;
    onCaptchaShow = options.onCaptchaShow;
    onCaptchaHide = options.onCaptchaHide;
    var difficulty = options.difficultCaptcha ? '' : 's=1&';
    var p = {
      url: url,
      query: data,
      onFail: function(ajaxObj, responseText) {
        if (isFunction(onFail)) onFail(ajaxObj, responseText);
        if (window.Ajax._captchaBox) {
          window.Ajax._captchaBox.setOptions({onHide: function(){}}).hide();
          if (isFunction(onCaptchaHide)) onCaptchaHide(true);
        }
      },
      onDone: function(ajaxObj, responseText) {
        var response;
        try {
        response = eval('(' + responseText + ')');
        if (response.ok && response.ok == -2) {
          if (window.Ajax._captchaBox == undefined) {
             window.Ajax._captchaBox = new MessageBox({title: 'Введите код с картинки', width: 300});
          }
          var box = window.Ajax._captchaBox;
          box.removeButtons();
          var key;
          var onClick = function(){
           removeEvent(key, 'keypress');
           if (typeof(p.query) == 'object') {
             extend(p.query, {'captcha_sid': response.captcha_sid, 'captcha_key': key.value});
           } else {
             p.query += '&captcha_sid=' + response.captcha_sid + '&captcha_key=' + key.value;
           } 
           Ajax.Post(p);
           hide('captchaKey');
           show('captchaLoader');
           return false;
          };
//          box.addButton({label: captcha_cancel, style: 'button_no', onClick: function(){
          box.addButton({label: 'Отмена', style: 'button_no', onClick: function(){
            removeEvent(key, 'keypress');
            box.hide();
          }});
//          box.addButton({label: captcha_send, onClick: onClick});
          box.addButton({label: 'Отправить', onClick: onClick});
          box.setOptions({onHide: onCaptchaHide});
          box.content('<div style="text-align: center; height: 76px"><a href="#" id="refreshCaptcha" title="Нажмите, чтобы обновить картинку"><img id="captchaImg" class="captchaImg" src="'+base_domain+'captcha.php?' + difficulty + 'sid=' + response.captcha_sid + '"/></a><div /><input id="captchaKey" name="captcha_key" type="text" style="width: 120px; margin: 3px 0px 0px;" maxlength="7"/><img id="captchaLoader" src="'+base_domain+'images/progress7.gif" style="display:none; margin-top: 13px;" /></div>');
          box.show();
          if (isFunction(onCaptchaShow)) onCaptchaShow();
          key = ge('captchaKey'); 
          addEvent(key, 'keypress', function(e){ if(e.keyCode==13){ onClick(); }});
          addEvent(ge('refreshCaptcha'), 'click', onClick);
          key.focus();
         } else {
            throw "Exit";
         }
       } catch (e) { // if captcha test passed
         if (response && typeof(response.text) == 'string')
           responseText = response.text;
         if (window.Ajax._captchaBox) {
           window.Ajax._captchaBox.setOptions({onHide: function(){}}).hide();
           if (isFunction(onCaptchaHide)) onCaptchaHide(true);
         }
         if (isFunction(onSuccess)) onSuccess(ajaxObj, responseText);
       }
      }
     };
    Ajax.Post(p);
  }
})();
     
 function ajx2q(qa)
 {
   var query = [], q, i =0;

   for (var key in qa) {
     if (qa[key] === undefined || qa[key] === null || typeof(qa[key]) == 'function') continue;
     if (isArray(qa[key])) {
       for (var i = 0; i < qa[key].length; ++i) {
         if (qa[key][i] === undefined || qa[key][i] === null || typeof(qa[key][i]) == 'function') continue;
         query.push(encodeURIComponent(key) + '[]=' + encodeURIComponent(qa[key][i]));
       }
     } else {
       query.push(encodeURIComponent(key) + '=' + encodeURIComponent(qa[key]));
     }
   }
   return query.join('&');
 }

var _cookies;
function _initCookies() {
	_cookies = {};
  var ca = document.cookie.split(';');
  for(var i = 0; i < ca.length; i++) {
		var c = ca[i].split("=");
		if(c.length == 2) _cookies[c[0].match(/^[\s]*([^\s]+?)$/i)[1]] = unescape(c[1].match(/^[\s]*([^\s]+?)$/i)[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 = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

//profile
function quickReply(id, dopen, dclose, foca){
  var box = ge(id);
  if(!box) return;
  var c = geByClass("r", box)[0];
  if (!c) return;
  if (!isVisible(c)) 
    slideDown(c, 200, function(){ ge("reply_field").focus(); });
  else 
    slideUp(c, 200);
}

function quickShow(id, dopen, dclose, foca){
  var box = ge(id);
  if(!box) return;
  var c = geByClass("r", box)[0];
  if (!c) return;
  if (!isVisible(c)) 
    slideDown(c, 200, function(){});
  else 
    slideUp(c, 200);
}

//utils
utils = {
	readCookie:function(cookieName) {
		var theCookie=""+document.cookie;
		var ind=theCookie.indexOf(cookieName);
		if (ind==-1 || cookieName=="") return ""; 
		var ind1=theCookie.indexOf(';',ind);
		if (ind1==-1) ind1=theCookie.length; 
		return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	},
	htmlentities:function(s){
		var div = document.createElement('div');
		var text = document.createTextNode(s);
		div.appendChild(text);
		return div.innerHTML;
	},
	lastLength:0,
	checkTextLength:function(max_len, val, warn, exceedFunc, remainFunc){
		if(this.lastLength==val.length)return;
		this.lastLength=val.length;
		n_len = this.replaceChars(val).length;
		if (n_len > max_len) {
			var n_plus = n_len - max_len;
			warn.style.display = "";
			warn.innerHTML = langpack[(exceedFunc || 'textExceedsSymbolLimit')](n_plus);
		} else if (n_len > max_len - 100) {
			var n_rem = max_len - n_len;
			warn.style.display = "";
			warn.innerHTML = langpack[(remainFunc || 'textNSymbolsRemains')](n_rem);
		} else {
			warn.style.display = "none";
			warn.innerHTML = '';
		}
	},
	replaceChars:function(text){
		//text = text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/\n/g, "<br>").replace(/\r/g, "").replace(/!/g, "&#33;").replace(/'/g, "&#39;");
		var res = "";
		temp = "";
		for(var i =0; i<text.length; i++){
			var c = text.charCodeAt(i);
			temp+=c+",";
			if((c > 0x80 && c < 0xC0) || c>0x500){
				res += "&#"+c+";";
			}else{
				switch(c){
					case 0x26:res+="&amp;";break;
					case 0x3C:res+="&lt;";break;
					case 0x3E:res+="&gt;";break;
					case 0x22:res+="&quot;";break;
					case 0x0D:res+="";break;
					case 0x0A:res+="<br>";break;
					case 0x21:res+="&#33;";break;
					case 0x27:res+="&#39;";break;
					default:res+=text.charAt(i);break;
				}
			}
		}
		return res;
	},
	trim:function(str){
		return str.replace(/(^\s+|\s+)$/g, "", str);
	},
	submit:function(e, form, val){
		if(val !== undefined && this.trim(val).length==0)return;
		if (e.keyCode==10 || (e.ctrlKey && e.keyCode==13)) {
			if(typeof(form)=='function'){form();}
			else if(form){form.submit();}
		}
	}
}

function readCookie(cookieName) {
 return utils.readCookie(cookieName);
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}


function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function fadeOpacity(sElemId, sRuleName, bBackward)
{
	var elem = document.getElementById(sElemId);
	if (!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;
	
	var rule = fadeOpacity.aRules[sRuleName];
	var nOpacity = rule.nStartOpacity;
	
	if (fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity = fadeOpacity.aProc[sElemId].nOpacity;}
	if ((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;

	fadeOpacity.aProc[sElemId] = {'nOpacity':nOpacity, 'tId':setInterval('fadeOpacity.run("'+sElemId+'")', fadeOpacity.aRules[sRuleName].nDalay), 'sRuleName':sRuleName, 'bBackward':Boolean(bBackward)};
}

fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity, 'nFinishOpacity':nFinishOpacity, 'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};

fadeOpacity.back = function(sElemId){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true);};

fadeOpacity.run = function(sElemId)
{
	var proc = fadeOpacity.aProc[sElemId];
	var rule = fadeOpacity.aRules[proc.sRuleName];
	
	proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*10)/10;
	setElementOpacity(document.getElementById(sElemId), proc.nOpacity);
	
	if (proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) clearInterval(fadeOpacity.aProc[sElemId].tId);
}
fadeOpacity.aProc = {};
fadeOpacity.aRules = {};

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}
