// JavaScript Document
function getWindowScroll() {
	var w = window;
	  var T, L, W, H;
	  L = window.pageXOffset || document.documentElement.scrollLeft;
	  T = window.pageYOffset || document.documentElement.scrollTop;

	  if (window.ie) 
		W = Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
		else if (window.khtml) 
		  W = document.body.scrollWidth;
		else 
		  W = document.documentElement.scrollWidth;
		  
		if (window.ie) 
		  H = Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
		else if (window.khtml) 
		  H = document.body.scrollHeight;
		else
		  H = document.documentElement.scrollHeight;
		
	  return { top: T, left: L, width: W, height: H };
}

function getPageSize(){
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {  
	  xScroll = document.body.scrollWidth;
	  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
	  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;
	}  
	var pageHeight, pageWidth;
	
	if(yScroll < windowHeight){
	  pageHeight = windowHeight;
	} else { 
	  pageHeight = yScroll;
	}
	
	if(xScroll < windowWidth){  
	  pageWidth = windowWidth;
	} else {
	  pageWidth = xScroll;
	}
	
	return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
}
function reSize(){
	var dW_l = $("#adboxLeftId").width();
	var dH = $("#adboxLeftId").height();
	
	var dW = $("#adboxRightId").width();
	var dH = $("#adboxRightId").height();
	
	
	var pSize = getPageSize();
	var pScroll = getWindowScroll();
	
	var sTop = (pSize.windowHeight-dH)/3;
		sTop += pScroll.top;
		
	$('#adboxLeftId').css({
		top:	sTop
	});
	$('#adboxRightId').css({
		top:	sTop
	});
}
function initLayout(){	
	reSize();	
	$(window).resize(reSize);
	$(window).scroll(reSize);
	$("#adboxLeftId").fadeIn();
	$("#adboxRightId").fadeIn();
}
function ScrollAD(){
	setTimeout(initLayout, 5000);
}
