var _CLIENTX = 0;
var _CLIENTY = 0;

function getAndSetMousePos(e){
	if(!e) var e = window.event;

	_CLIENTX = e.clientX;
	_CLIENTY = e.clientY;
}

document.onmousemove = getAndSetMousePos;

function createCookie(name,value,days){
	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+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function getScroll(){
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof(document.body.scrollTop) != "undefined") {
		scrollX += document.body.scrollLeft;
		scrollY += document.body.scrollTop;
		if (document.body.parentNode && typeof(document.body.parentNode.scrollTop) != "undefined") {
			scrollX += document.body.parentNode.scrollLeft;
			scrollY += document.body.parentNode.scrollTop;
		}
	} else if (typeof(window.pageXOffset) != "undefined") {
		scrollX += window.pageXOffset;
		scrollY += window.pageYOffset;
	}
	return Array(scrollX, scrollY);
}

function getWindowSize() {
  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;
  }
 return Array(myWidth, myHeight);}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
        document.body.lastChild);

    // Pixel width of the scroller
    return (wNoScroll - wScroll);}


function getObjectProperties (object) {
var result = '';
for (var property in object) {
result += property + ': ' + object[property] + '\r\n';
}
return result;}

function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;}

function getScrollValues(){
//	document.write(getObjectProperties(document.body));
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof document.body.scrollTop != "undefined") {
		scrollX += document.body.scrollLeft;
		scrollY += document.body.scrollTop;
		if (document.body.parentNode &&
			typeof document.body.parentNode.scrollTop != "undefined") {
			scrollX += document.body.parentNode.scrollLeft;
			scrollY += document.body.parentNode.scrollTop;
		}
	} else if (typeof window.pageXOffset != "undefined") {
		scrollX += window.pageXOffset;
		scrollY += window.pageYOffset;
	}
	return Array(scrollX,scrollY);}



var Client = {
	scrollXFnc: function(){return (
								(document.body && (typeof(document.body.scrollTop) != "undefined"))
								?
									(
									 (document.body.parentNode && (typeof(document.body.parentNode.scrollTop) != "undefined"))
									 	?
											(document.body.scrollLeft + document.body.parentNode.scrollLeft)
										:
											document.body.scrollLeft
									)
								:
									(
									 (typeof(window.pageXOffset) != "undefined")
									 	?
											window.pageXOffset
										:
											0
									)
								);},
	scrollYFnc: function(){return (
								(document.body && (typeof(document.body.scrollTop) != "undefined"))
								?
									(
									 (document.body.parentNode && (typeof(document.body.parentNode.scrollTop) != "undefined"))
									 	?
											(document.body.scrollTop + document.body.parentNode.scrollTop)
										:
											document.body.scrollTop
									)
								:
									(
									 (typeof(window.pageYOffset) != "undefined")
									 	?
											window.pageYOffset
										:
											0
									)
								);},
	_width: function(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;},
	_height: function(){return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;}
}
//alert(Client._height());

function centralize($__Object){
			var winW = getClientWidth();
			var winH = getClientHeight();

			$__Object.style.top = (parseInt((winH/2) - ($__Object.offsetHeight/2)) + getScrollValues()[1]) + 'px';
			$__Object.style.left = (parseInt((winW/2) - ($__Object.offsetWidth/2)) + getScrollValues()[0]) + 'px';
}





function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

//====================================================================================



wait = {
	WaitLoader:undefined,
	CoverAria:undefined,
	ObjectAbout:undefined,
	
	OBJXPosition:0,
	OBJYPosition:0,
	OBJWidth:0,
	OBJHeight:0,
	OBJZIndex:0,
	__construct:function(){
		if(this.ObjectAbout!=undefined){
			this.OBJWidth = this.ObjectAbout.offsetWidth;
			this.OBJHeight = this.ObjectAbout.offsetHeight;
			this.OBJXPosition = findPos(this.ObjectAbout)[0];
			this.OBJYPosition = findPos(this.ObjectAbout)[1];
//			alert(this.ObjectAbout.parentNode)

//			alert(this.ObjectAbout.pixelTop);
			this.OBJZIndex = parseInt(this.ObjectAbout.style.zIndex)+1;
			if(this.OBJZIndex.toString() == "NaN") this.OBJZIndex = 1000;
		}else{
			this.OBJWidth = getClientWidth();
			this.OBJHeight = getClientHeight();
			this.OBJXPosition = 0;
			this.OBJYPosition = 0;
			this.OBJZIndex = 998;
		}

		this.createWaitLoader();
		this.createCoverAria();
	},
	__constructNotCover:function(){
		if(this.ObjectAbout!=undefined){
			this.OBJWidth = this.ObjectAbout.offsetWidth;
			this.OBJHeight = this.ObjectAbout.offsetHeight;
			this.OBJXPosition = findPos(this.ObjectAbout)[0];
			this.OBJYPosition = findPos(this.ObjectAbout)[1];
//			alert(this.ObjectAbout.parentNode)

//			alert(this.ObjectAbout.pixelTop);

		}else{
			this.OBJWidth = getClientWidth();
			this.OBJHeight = getClientHeight();
			this.OBJXPosition = 0;
			this.OBJYPosition = 0;
		}
		
		this.createWaitLoader();

	},
	__constructNotWait:function(){
		if(this.ObjectAbout!=undefined){
			this.OBJWidth = this.ObjectAbout.offsetWidth;
			this.OBJHeight = this.ObjectAbout.offsetHeight;
			this.OBJXPosition = findPos(this.ObjectAbout)[0];
			this.OBJYPosition = findPos(this.ObjectAbout)[1];
//			alert(this.ObjectAbout.parentNode)

//			alert(this.ObjectAbout.pixelTop);

		}else{
			this.OBJWidth = getClientWidth();
			this.OBJHeight = getClientHeight();
			this.OBJXPosition = 0;
			this.OBJYPosition = 0;
		}
		
		this.createCoverAria();

	},
	isset:function(){
		if(this.WaitLoader==undefined){
			return false;
		}else{
			return true;
		}
	},
	createWaitLoader:function(){
		this.WaitLoader = document.createElement("div");
		document.body.appendChild(this.WaitLoader); 
	
		this.WaitLoader.innerHTML = '<img src="/admin/design/default/images/ajax-loader.gif"><h3>Загрузка...</h3><span style="font-size:10px">Пожалуйста подождите!</span>';
		this.WaitLoader.className = 'WaitLoader';
		this.WaitLoader.style.position="absolute";
		this.WaitLoader.style.opacity = '0';
		this.WaitLoader.style.top=((this.OBJHeight/2) - (this.WaitLoader.offsetHeight/2) + this.OBJYPosition - 1)+"px";
		this.WaitLoader.style.left=((this.OBJWidth/2) - (this.WaitLoader.offsetWidth/2) + this.OBJXPosition - 1)+"px";
		this.WaitLoader.style.opacity = '1';
		this.WaitLoader.style.zIndex=9999;
	},
	createCoverAria:function(){
		this.CoverAria = document.createElement("div");
		document.body.appendChild(this.CoverAria); 
		this.CoverAria.style.position="absolute";
		this.CoverAria.style.zIndex=9999;
		this.CoverAria.style.top=this.OBJYPosition+"px";
		this.CoverAria.style.left=this.OBJXPosition+"px";
//		alert(this.OBJWidth);
//		this.CoverAria.style.background="url(http://megashop01.ru/design/default/images/page/background.jpg)";
		this.CoverAria.style.background="#000";
//alert(Client.scrollY());

		this.CoverAria.style.height=(this.OBJHeight + getScrollValues()[1])+"px";
		this.CoverAria.style.width=(this.OBJWidth + getScrollValues()[0])+"px";
		this.CoverAria.style.opacity = '0.60';
		this.CoverAria.style.filter = "alpha(opacity = 60)";
	},
	removeElement:function(el){
		el.parentNode.removeChild(el);
	},
	__destruct:function(){
		if(this.CoverAria!=undefined){ this.removeElement(this.CoverAria);		this.CoverAria = undefined;}
		if(this.WaitLoader!=undefined){ this.removeElement(this.WaitLoader);	this.WaitLoader = undefined;}
	}
}


function getScrollValues(){
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof document.body.scrollTop != "undefined") {
		scrollX += document.body.scrollLeft;
		scrollY += document.body.scrollTop;
		if (document.body.parentNode &&
			typeof document.body.parentNode.scrollTop != "undefined") {
			scrollX += document.body.parentNode.scrollLeft;
			scrollY += document.body.parentNode.scrollTop;
		}
	} else if (typeof window.pageXOffset != "undefined") {
		scrollX += window.pageXOffset;
		scrollY += window.pageYOffset;
	}
	return Array(scrollX,scrollY);
}



function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}


function mnuRoll() {
		if(parseInt(vIE())>6){
			var hmenuObj = document.getElementById('p_hmenu');
			var hmenuAbsObj = document.getElementById('bd');
			if(getScrollValues()[1]>149){
				hmenuObj.style.top = "0px";
				hmenuObj.style.position = "fixed";
				hmenuAbsObj.style.top = "11px";
				hmenuAbsObj.style.position = "fixed";
			}else{
				hmenuObj.style.top = "149px";
				hmenuObj.style.position = "absolute";
				hmenuAbsObj.style.top = "0px";
				hmenuAbsObj.style.position = "absolute";
			}
		}else{
			var hmenuObj = document.getElementById('p_hmenu');
			var hmenuAbsObj = document.getElementById('bd');
			if(getScrollValues()[1]>149){
				hmenuObj.style.top = getScrollValues()[1]+"px";
				hmenuAbsObj.style.position="absolute";
				hmenuAbsObj.style.top = (getScrollValues()[1]-150)+"px";
			}else{
				hmenuObj.style.top = "149px";
				hmenuAbsObj.style.top = "0px";
			}

/*
			if(getScrollValues()[1]>149){
				hmenuObj.style.top = getScrollValues()[1]+"px";
//				hmenuObj.style.position = "absolute";
				hmenuAbsObj.style.top = (getScrollValues()[1]+11)"px";
//				hmenuAbsObj.style.position = "absolute";
			}
*/
		}
//		alert(hmenuObj.offsetTop);
}
	window.onscroll = mnuRoll;