		var timer;
		var adPage = 0;
		var scrollStep = 20;
		var scrollWidth = 950;
		var scrollTo = 0;
		var scrolling = false;
		var scrollLeft = false;
		var scrollRight = false;
		var rotateTimer;
		var rotateTime = 5000;
		var rotateLeft = false;
		var rotateRight = true;

		function disableTimer()
		{
			clearTimeout(timer);
			scrolling = false;
			scrollLeft = false;
			scrollRight = false;
		}


		var a=0;
		function getLeftPos()
		{
			var currentLeft = "";
			currentLeft = document.getElementById('adLayer').style.left;	
			currentLeft = currentLeft.replace("px", "")
			currentLeft = currentLeft.replace("pt", "")
			currentLeft = eval(currentLeft);
			return currentLeft;
		}

		function scroll()
		{
			timer = setTimeout(scroll,10);

			if (document.getElementById('adLayer').offsetLeft == scrollTo)
			{
				disableTimer();
			}
			else
			{
				scrolling = true;
			}

			if (scrolling == true)
			{
				if (scrollRight == true)
				{
					if (document.getElementById('adLayer').offsetLeft-scrollStep <= scrollTo)
					{
						document.getElementById('adLayer').style.left = scrollTo
						disableTimer();
					}
					else
					{
						document.getElementById('adLayer').style.left = getLeftPos() - scrollStep
					}
				}
				else
				{

					if (getLeftPos()+scrollStep >= scrollTo)
					{
						document.getElementById('adLayer').style.left = scrollTo
						disableTimer();
					}
					else
					{
						document.getElementById('adLayer').style.left = getLeftPos() + scrollStep
					}
				}
			}
		}

		function move_ad_left()
		{
			if (scrolling == false)
			{
				scrollLeft = true;

				if (getLeftPos() < 0 && (getLeftPos() + scrollWidth) <= 0) {
					//scrollTo = document.getElementById('adLayer').offsetLeft + scrollWidth
					scrollTo = 0;
				}
				else {
					scrollTo = 0;
					rotateRight = true;
					rotateLeft = false;
				}
				resetRotateTimer()
				scroll();
			}
		}

		function move_ad_right()
		{
			if (scrolling == false)
			{
				scrollRight = true;
				if (document.getElementById('adLayer').offsetWidth > Math.abs(getLeftPos() - (scrollWidth*2))) {
					scrollTo = getLeftPos() - scrollWidth
				}
				else {
					scrollTo = -(document.getElementById('adLayer').offsetWidth) + scrollWidth
					rotateRight = false;
					rotateLeft = true;
				}
				resetRotateTimer()
				scroll();
			}
		}

		function initAdRotate()
		{
			rotateTimer = setTimeout(rotateAd,rotateTime);
		}

		function rotateAd()
		{
			if (scrolling == false)
			{
				if (rotateRight == true)
					move_ad_right();
				else
					move_ad_left();
			}
			rotateTimer = setTimeout(rotateAd,rotateTime);
		}

		function resetRotateTimer()
		{
			clearTimeout(rotateTimer);
			rotateTimer = setTimeout(rotateAd,rotateTime);
		}


function getPageSize() 
{        
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

