/* cookies funcs */
var Cookies = {
	set: function(cookieName, cookieContent, cookieExpireTime){
		if (cookieExpireTime>0){
			var expDate=new Date();
			expDate.setTime(expDate.getTime()+cookieExpireTime*1000*60*60);
			var expires=expDate.toGMTString();
			document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"; expires="+expires
		}else{
			document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"";
		}
	},
	get: function(cookieName){
		var ourCookie=document.cookie;
		if (!ourCookie || ourCookie=="")return "";
		ourCookie=ourCookie.split(";");
		var i=0;
		var Cookie;
		while (i<ourCookie.length){
			Cookie=ourCookie[i].split("=")[0];
			if (Cookie.charAt(0)==" ") Cookie=Cookie.substring(1);
			if (Cookie==cookieName) return unescape(ourCookie[i].split("=")[1]);
			i++;
		}
		return "";
	},
	erase: function(cookieName){
		var cookie = Cookies.get(cookieName) || true;
		Cookies.set(cookieName, '', -1);
		return cookie;
	},
	accept: function(){
		if (typeof navigator.cookieEnabled == 'boolean') return navigator.cookieEnabled;
		Cookies.set('_test', '1');
		return (Cookies.erase('_test') = '1');
	}
}

/*
 * Randomly interchange elements
 * if param 'b' is set to 'true', it will shuffle sub- and multisubarrays
 * in their own right, the default value is 'false'
 */
Array.prototype.shuffle = function(b){
	var i = this.length, j, t;
	while(i){
		j = Math.floor((i--) * Math.random());
		t = b && typeof this[i].shuffle !== 'undefined' ? this[i].shuffle() : this[i];
		this[i] = this[j];
		this[j] = t;
	}
	return this;
};

/*
 * trim funcs
 */
Object.extend(String.prototype, {
	LTrim: function(){
		return this.replace(/\s*((\S+\s*)*)/, "$1");
	},
	RTrim: function(){
		return this.replace(/((\s*\S+)*)\s*/, "$1");
	},
	trim: function(){
		return this.LTrim(this.RTrim());
	}
});

/*
 * we need win1251, not that utf stuff
 */
window.encodeURIComponent = function(str){
	var trans = [];
	for (var i = 0x410; i <= 0x44F; i++) trans[i] = i - 0x350; // А-Яа-я
	trans[0x401] = 0xA8; // Ё
	trans[0x451] = 0xB8; // ё
	var ret = [];
	for (var i = 0; i < str.length; i++){
		var n = str.charCodeAt(i);
		if (typeof trans[n] != 'undefined') n = trans[n];
		if (n <= 0xFF) ret.push(n);
	}
	return escape(String.fromCharCode.apply(null, ret)).replace(/\+/g, '%2B'); // +
}
window.decodeURIComponent = function(str){
	return unescape(str);
}
function ContentLoader(
	oElementContent,
	oElementIframe,
	oOptions
	) {
	
	this.oElementContent = oElementContent;
	this.oElementIframe = oElementIframe;
	
	this.oOptions = oOptions || {};
	
	this.init();
	
}

ContentLoader.prototype = {

	init : function() {
				
		var oThis = this;
								
		$(this.oElementIframe).observe(
			'load',
			function() {
			
				oThis.setContent(oThis.getFrameContent());
			
			}
			);
			
		if(this.oOptions.iRefreshPeriod) {
			setInterval(
				function() {
				
					oThis.oElementIframe.src = oThis.oElementIframe.src.match(/^([^?]+)(\?r=)?/)[1] + "?r=" + Math.floor(Math.random() * 100);
				
				},
				this.oOptions.iRefreshPeriod
				);
		}
	
	},
	
	getFrameContent : function() {
		
		var oDocument =
			this.oElementIframe.contentDocument?
				this.oElementIframe.contentDocument :
				this.oElementIframe.contentWindow? 
					this.oElementIframe.contentWindow.document :
					this.oElementIframe.document
			; 
	
		return oDocument.body.innerHTML;
	
	},
	
	setContent : function(sContent) {
	
		this.oElementContent.innerHTML = sContent;
	
	}

};

function hidediv() 
{
    document.getElementById('picture_div').style.visibility = 'hidden';
    $('picture_div').setStyle({
    'left': '-1000px',
    'top': '-1000px',
    'height': '100px',
    'z-index': -100
    });
    document.getElementById('picture_src').src = '#';
}





function showdiv(id, width, height) {
    hidediv();
    var left = document.getElementById('left_td').offsetWidth + (document.getElementById('right_td').offsetWidth/2) - (width/2);
    left = Number(left).toFixed(0);
    
    var top = getDim(window)[3]/2 + ( getDim(window)[1] ) - ( height / 2 );
    top = Number(top).toFixed(0);

    document.getElementById('picture_src').src = '/upimg/pic/'+id+'.jpg';

    //Сделать проверку на TOP и LEFT вдруг вылезли в минус
    if(top<0)top=10;
    if(left<0) left=10;
    
    $('picture_div').setStyle({
    'left': left+'px',
    'top': top+'px',
    'height': height+45+'px',
    'z-index': 100
    });

    
    document.getElementById('picture_div').style.visibility = 'visible';
} 


function getDim(obj)
{
    if(obj == window) {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY, myWidth,myHeight];
    }
    else if (obj == document.body) {
    if (window.innerHeight && window.scrollMaxY) {
    yScroll = window.innerHeight + window.scrollMaxY;
    xScroll = window.innerWidth + window.scrollMaxX;
    } else if (obj.scrollHeight > obj.offsetHeight){ // all but Explorer Mac
    yScroll = obj.scrollHeight;
    xScroll = obj.scrollWidth;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    yScroll = obj.offsetHeight;
    xScroll = obj.offsetWidth;
    }
    return [xScroll, yScroll];
    }
    else {
    if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    var objParent = obj;
    objParent = objParent.offsetParent;
    while (objParent) {
    curleft += objParent.offsetLeft
    curtop += objParent.offsetTop
    objParent = objParent.offsetParent;
    }
    }
    return [curleft, curtop,obj.offsetWidth,obj.offsetHeight];
    }
}