var timeout = 10000;

function RotateBanner(JSON_Obj)
{
	this.JSON_Object = JSON_Obj;
	this.to = 0;
	this.value = 0;
}

RotateBanner.prototype.getImage = function()
{
	with(this)
	{
		document.write("<div id=\"imgDiv" + JSON_Object.zoneid + "\" style=\"width: " + JSON_Object.imgWidth + "px; height: " + JSON_Object.imgHeight + "px;\"></div>");
		nextAd();
	}
}

RotateBanner.prototype.makeHttpRequest = function(url, callback_function, return_xml)
{
	with(this)
	{
	   var http_request = false;

	   if (window.XMLHttpRequest) { // Mozilla, Safari,...
	       http_request = new XMLHttpRequest();

	   } else if (window.ActiveXObject) { // IE
	       try {
		   http_request = new ActiveXObject("Msxml2.XMLHTTP");
	       } catch (e) {
		   try {
		       http_request = new ActiveXObject("Microsoft.XMLHTTP");
		   } catch (e) {}
	       }
	   }

	   if (!http_request) {
	       alert('Unfortunatelly you browser doesn\'t support this feature.');
	       return false;
	   }
	   http_request.onreadystatechange = function() {
	       if (http_request.readyState == 4) {
		   if (http_request.status == 200) {
		   	if (callback_function != "")
		       		eval(JSON_Object.name + "." + callback_function + '(http_request.responseText)');
		   }
	       }
	   }
	   http_request.open('GET', url, true);
	   http_request.send(null);
	}
}

RotateBanner.prototype.loadBanner = function(html_content)
{
	with(this)
	{
		document.getElementById("imgDiv" + JSON_Object.zoneid).innerHTML = html_content;

		try {
			clearTimeout(to);
		} catch (e) {}
		
		if (JSON_Object.fade)
		{		
			value = 0;

			if (window.sidebar)
			{
				setInterval(JSON_Object.name + ".MOZ()",100)
			}

			if (document.all)
			{
				setInterval(JSON_Object.name + ".IE()",100)
			}
		}
		
	    
		if (typeof(JSON_Object.timeout) != "undefined")
	    		timeout = JSON_Object.timeout;

	    	to = setTimeout(JSON_Object.name + ".nextAd()", timeout);
	}
}

RotateBanner.prototype.updateClick = function(zoneid, adid)
{
	with(this)
	{
		var url = 'ajax_banner.asp?action=click&zoneid=' + JSON_Object.zoneid + "&adid=" + adid + "&time=" + new Date().getTime();
		makeHttpRequest(url, '', true);
	}
}

RotateBanner.prototype.updateView = function(zoneid, adid)
{
	with(this)
	{
		var url = 'ajax_banner.asp?action=view&zoneid=' + JSON_Object.zoneid + "&adid=" + adid + "&time=" + new Date().getTime();
		makeHttpRequest(url, '', true);
	}
}

RotateBanner.prototype.nextAd = function()
{
	with(this)
	{
		var attributes = "";
		if (typeof(JSON_Object.imgWidth) != "undefined")
			attributes = "&width=" + JSON_Object.imgWidth;
		if (typeof(JSON_Object.imgHeight) != "undefined")
			attributes += "&height=" + JSON_Object.imgHeight;
		attributes += "&fade=" + JSON_Object.fade;
		attributes += "&time=" + new Date().getTime();

		var url = 'ajax_banner.asp?action=load&sitezone=' + JSON_Object.sitezone + '&logstatus=' + JSON_Object.logstatus + '&zoneid=' + JSON_Object.zoneid + '&objname=' + JSON_Object.name + attributes;
		makeHttpRequest(url, 'loadBanner', true);
	}
}

RotateBanner.prototype.IE = function()
{
	with(this)
	{
		if (value >= 100)
			return;
		
		value += 5;
		
		document.getElementById("img" + JSON_Object.name).filters[0].opacity=value;
	}
}


RotateBanner.prototype.MOZ = function()
{
	with(this)
	{
		if (value >= 1)
			return;
		
		value += 0.05;
		
		document.getElementById("img" + JSON_Object.name).style.MozOpacity = value;
	}
}

