// JavaScript Document
var cenSize = 980
var overlap = 30;
var resizeInterval;

function startBg(){

	if(window.addEventListener){
		window.addEventListener("scroll", adjustForScroll, false);
		window.addEventListener("resize", adjustForResize, false);
	}else if(window.attachEvent){
		window.attachEvent("onscroll", adjustForScroll);
		window.attachEvent("onresize", adjustForResize);
	}else{
		alert("error: add/attach event");
	}
	
	var flashvars = {
		ws: 'left'
	};
	var params = {
		wmode: "transparent",
		scale: "noScale"
	};
	var attributes = false;
	swfobject.embedSWF(preURL+"/flash/liquid-sides.swf", "flashLeftBg", "100%", "100%", "8.0.0", "", flashvars, params, attributes);
	
	var flashvars2 = {
		ws: 'right'	
	};
	var params2 = {
		wmode: "transparent",
		scale: "noScale"
	};
	var attributes2 = false;
	swfobject.embedSWF(preURL+"/flash/liquid-sides.swf", "flashRightBg", "100%", "100%", "8.0.0", "", flashvars2, params2, attributes2);
	
	adjustForScroll();
	adjustForResize();
}

function getWindowSize(){
	var myWidth = 0, myHeight = 0;
	var results;
	
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//Non-IE
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	results = {w : myWidth, h : myHeight}
	return results;
}

function getScrollOffset(){
	var x,y;
	var results;
	
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	
	results = {x : x, y : y};
	return results;
}

function getDocumentSize(){
	var docWidth = 0, docHeight = 0;
	var results;
	
	document.body.style.height = 'auto';
	
	docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;
	docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
	
	results = {w : docWidth, h : docHeight};
	
	document.body.style.height = '100%';
	
	return results;
}

function adjustForScroll(){
	scrollOff = getScrollOffset();
	document.getElementById("flashLeftBg").style.top = scrollOff.y+"px";
	document.getElementById("flashRightBg").style.top = scrollOff.y+"px";
};

function adjustForResize(){
	
	clearTimeout(resizeInterval);
	performResize();
	resizeInterval = setTimeout(performResize, 50);

}

function performResize(){
	winSize = getWindowSize();
	scrollOff = getScrollOffset();
	docSize = getDocumentSize();
	
	var tw = 0;
	var th = 0;
	
	if(winSize.w > cenSize){
		tw = winSize.w;
	}else{
		tw = cenSize;
	}
	
	th = winSize.h;
		
	document.getElementById("flashLeftBg").style.width = ((tw-cenSize)/2)+'px';
	document.getElementById("flashLeftBg").style.height = th+'px';
	
	if(cenSize+(2*overlap) < winSize.w){
		document.getElementById("flashCenBg").style.width = cenSize+(2*overlap)+'px';
		document.getElementById("flashCenBg").style.left = ((tw-cenSize)/2)-overlap+'px';
	}else{
		document.getElementById("flashCenBg").style.width = winSize.w+'px';
		document.getElementById("flashCenBg").style.left = '0px';
	}
	
	document.getElementById("flashCenBg").style.height = docSize.h+'px';
		
	document.getElementById("flashRightBg").style.height = th+'px';
	document.getElementById("flashRightBg").style.left = (((tw-cenSize)/2)+cenSize)+'px';
	//document.getElementById("flashRightBg").style.width = ((tw-cenSize)/2)+overlap+'px';
	document.getElementById("flashRightBg").style.width = tw-Math.floor((((tw-cenSize)/2)+cenSize))+'px';
}

function addRisizeLoadEvent(func) { 
  var oldonload = window.onload; 
  if (typeof window.onload != 'function') { 
	window.onload = func; 
  } else { 
	window.onload = function() { 
	  if (oldonload) { 
		oldonload(); 
	  } 
	  func(); 
	} 
  } 
} 
addRisizeLoadEvent(startBg);