
/* Объявляем класс cBannerShowInspector начало */
with(cBannerShowInspector = function()
{
	this.aInspectingID = [];
	this.timer = false;
	this.bPageLoad = false;
}){
	
	prototype.addInspectingObj = function(hash) {this.aInspectingID.push(hash);}
	
	prototype.eventOnLoad = function()
	{
		obj = window.objBannerShowInspector;
		obj.bPageLoad = true;
		obj.eventAction();
	}
	
	prototype.eventAction = function()
	{
		obj = window.objBannerShowInspector;
		if(obj.bPageLoad == false) return false;
		
		if(obj.timer) clearTimeout(obj.timer);
		obj.timer = setTimeout(function(){obj.checkIsVisible.call(obj)}, 500);
	}
	
	prototype.checkIsVisible = function()
	{
		try
		{
			var body = document.body;
			var docElem = document.documentElement;
			
			//var visibleH = window.innerHeight ? window.innerHeight : (!(document.body.offsetHeight==0) ? document.body.offsetHeight : document.body.clientHeight);
			var isIE = !!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1);
			var visibleH =	isIE ?
								(!(document.documentElement.clientHeight)
								|| (document.documentElement.clientHeight === 0)) ?	
										// IE 5-7 Quirks and IE 4 case
										document.body.clientHeight :
										//IE 6+ Strict Case
										document.documentElement.clientHeight:
								// Gecko and Other DOM compliant case
								window.innerHeight; 
			
			var visibleW = 	isIE ?
							(!(document.documentElement.clientWidth)
							|| (document.documentElement.clientWidth === 0)) ?	
									// IE 5-7 Quirks and IE 4 case
									document.body.clientWidth :
									//IE 6+ Strict Case
									document.documentElement.clientWidth:
							// Gecko and Other DOM compliant case
							window.innerWidth; 
			
			var docScrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
			var docScrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
			var aDeleteIndex = [];
			for(var i=0; i<this.aInspectingID.length; i++)
			{	
				var banner = document.getElementById(this.aInspectingID[i].id);
				if(!banner) continue;		
				var elRect = banner.elRect ? banner.elRect : this.getOffsetRect(banner);
				banner.elRect = elRect;
				if(elRect.top <=docScrollTop+visibleH && elRect.left <=docScrollLeft+visibleW)
				{
					var script = document.createElement("script");
					script.type="text/javascript";
					script.src = "ht"+"tp://preved.tut.by/display_stat.php?bid="+this.aInspectingID[i].bid+"&fid="+this.aInspectingID[i].frameid+"&dt="+this.aInspectingID[i].date+"&h="+this.aInspectingID[i].hash+"&gid="+this.aInspectingID[i].gid;
										
					if(document.body) document.body.appendChild(script);
					else document.getElementsByTagName("body")[0].appendChild(script);
					
					aDeleteIndex.push(i);
				}
			}
			while(aDeleteIndex.length>0) this.aInspectingID.splice(aDeleteIndex.pop(),1);
		}
		catch(e){}
	}
	
	prototype.attachEvent = function()
	{
		try {
			if(window.addEventListener) 
			{
				window.addEventListener("load", this.eventOnLoad, true);
				window.addEventListener("scroll", this.eventAction, true);
				window.addEventListener("resize", this.eventAction, true);
			}
			else 
			{
				window.attachEvent("onload", this.eventOnLoad);
				window.attachEvent("onscroll", this.eventAction);
				window.attachEvent("onresize", this.eventAction);
			}
			window.objBannerShowInspector = this;
		}
		catch(e){}
	}
	
	prototype.getOffsetRect=function(elem)
	{
		var box = elem.getBoundingClientRect();
		
		var body = document.body;
		var docElem = document.documentElement;
		
		var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop;
		var scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft;
		
		var clientTop = docElem.clientTop || body.clientTop || 0;
		var clientLeft = docElem.clientLeft || body.clientLeft || 0;
		
		var top  = box.top +  scrollTop - clientTop;
		var left = box.left + scrollLeft - clientLeft;
		
		return { top: Math.round(top), left: Math.round(left) }
	}
}
/* Объявляем класс cBannerShowInspector конец */


