﻿var resizePlay = false;
var myBodyWidth = 5000;
var myBodyHeight = 5000;
function resizeEvent() {
	if (resizePlay) return
	resizePlay = true
	makeResize()

	var resizeAgain = function() {
		if (resizePlay) return
		resizePlay = true
		makeResize()
	}
	var s = setTimeout(resizeAgain, 1000)
} //resizeEvent

var wrapper, disabler, resizePlay
function makeResize() {
	var s
	if (typeof (window.innerWidth) == 'number') {
		//Non-IE
		myBodyWidth = window.innerWidth;
		myBodyHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		myBodyWidth = document.documentElement.clientWidth;
		myBodyHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		myBodyWidth = document.body.clientWidth;
		myBodyHeight = document.body.clientHeight;
	}
	s = setTimeout('resizePlay = false', 300)

} // makeResize()﻿

window.onresize = function() { resizeEvent(); }
resizeEvent()

var leftAdsInit = function() {
	var ME = this
	var minTop = 1
	var timer
	var timer2
	var newRelPoz
	var frame = document.getElementById("main_central_div")
	var bodyDom = document.body
	var htmlDom = document.getElementsByTagName("HTML")[0]
	var check = function() {
		if (myBodyWidth < 1057) {
			ME.style.display = "none"
			frame.style.left = "0px"
			return
		} else {
			ME.style.display = "block"
			framePoz = (myBodyWidth - frame.offsetWidth) / 2
			if (framePoz > 139) {
				
				ME.style.left = (framePoz - 160) + "px"
				frame.style.right = "-60px"

			} else {
				ME.style.left = "0px"
				frame.style.right = "-90px"

			}
		}
		clearInterval(timer2)
		var maxTop = 1400
		try {
			maxTop = frame.offsetHeight - ME.offsetHeight
		} catch (e) { }
		var currScrollTop = bodyDom.scrollTop + htmlDom.scrollTop

		if (minTop < currScrollTop) {
			newPoz = currScrollTop
			if (newPoz > maxTop) newPoz = maxTop

			newRelPoz = newPoz//-minTop
			timer2 = setInterval(moveTo, 50)
		} else {
			newRelPoz = minTop
			timer2 = setInterval(moveTo, 50)
		}

	}
	timer = setInterval(check, 200)
	var moveTo = function() {
		var distance = (newRelPoz - clrPx(getStyle(ME, "top")))
		var New = Math.round(distance / 3)
		//ME.style.top=Math.floor(New).toString()+"px"	
		if (Math.abs(New) > 1) {
			ME.style.top = (clrPx(getStyle(ME, "top")) + New).toString() + "px"
		} else {
			clearInterval(timer2)
			ME.style.top = newRelPoz + "px"
		}
	}
	
	function getStyle(oElm, strCssRule) {
		var strValue = "";
		if (document.defaultView && document.defaultView.getComputedStyle) {
			strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
		}
		else if (oElm.currentStyle) {
			strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
				return p1.toUpperCase();
			});
			strValue = oElm.currentStyle[strCssRule];
		}
		return strValue;
	}
}  //lefttAdsInit

