var myWidth = 0, myHeight = 0, myScroll = 0;
var lastx = 0;
var adTimerId;

////////////////////////////
//
// UTILITY functions
//

// Utility: Set the opacity, compatible with a number of browsers. Value from 0 to 100.

function setOpacity(opacity, theID) {

	var object = document.getElementById(theID).style;

	// If it's 100, set it to 99 for Firefox.

	if (navigator.userAgent.indexOf("Firefox") != -1) {
		if (opacity == 100) { opacity = 99.9999; } // This is majorly awkward
	}

	// Multi-browser opacity setting

	object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
	object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla

}

function getSize() {

	// Window Size

	if (self.innerHeight) { // Everyone but IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}

	// Page size w/offscreen areas

	if (window.innerHeight && window.scrollMaxY) {	
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	}

}

function moveAd(divId, shift) {

	obj = document.getElementById(divId);
	obj.style.visibility = "visible";
	
	
	// move toward right
	obj.style.left = (lastx - shift)+'px';
	lastx -= shift;

	
	if(lastx > myWidth-221)
	{
		clearInterval(adTimerId);
		adTimerId = setInterval("moveAd('"+divId+"', "+shift+")", 25);		
		adActive = true; 
	}
	else
	{
		clearInterval(adTimerId);
		adTimerId = setInterval("doneAd('"+divId+"')", 60000);		
		
	}
	
		
	
}
function doneAd(divId)
{
	clearInterval(adTimerId);
	var e=document.getElementById(divId);
	e.style.visibility='hidden';
}
function startAd(divId) {


	// Get browser dimensions
	getSize();

	obj = document.getElementById(divId);
	obj.style.position = 'absolute';
	obj.style.visibility = "hidden";
	obj.style.left = myWidth;
	obj.style.top = 0;
	lastx = myWidth;

	// start AD in 3 seconds
	adTimerId = setInterval("moveAd('"+divId+"', "+10+")", 1000);	
	return false;
}


startAd('ad1001');
