// JavaScript Document

var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; initApp()}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1;
      initApp();
    }
  }
}  

window.onload=function(){
  setTimeout("if (!alreadyrunflag) initApp()", 0)
}
	 
/*window.addEvent('load', function() {


	initApp();
	
});*/

function initApp()
{
	
	spinner.addEvents({
					  'onHide' : function(){
						  $('documentBody').style.display = "block";
						  initCarousel();
						  resize();
					  }
					  
					  });
			   
 	// preload images
	var images = ['html/layout/site/images/tab_middle_bg.png',
				  'html/layout/site/images/menu_bg.png'];
	var loader = new Asset.images(images, {
		
		onComplete: function() {
			images.each(function(im) {
				
			});
			
			var tabMiddle = document.getElementById("tabMiddle");
			tabMiddle.style.background = "url(html/layout/site/images/tab_middle_bg.png) no-repeat top center";

			spinner.hide();
			
		}
	});

}


function resize()
{ 
	var cont = document.getElementById("bannerImage");
	var bod = document.getElementById("documentBody"); 

	
	if(document.body.clientWidth <= 860)
	{
		bod.style.width = "860px";	
		
	}
	else
	{
		bod.style.width = "100%";	
		
	
	}
	
	//bod.style.height = document.body.parentNode.clientHeight + "px";
	
	var leftOffset = (bod.clientWidth - 1280)/2;
	
	/*var tabMiddle = document.getElementById("tabMiddle");
	tabMiddle.style.background = "url(images/tab_middle_bg.png) no-repeat top center"*/
	
	var tabLeft = document.getElementById("tabLeft"); 
	var tabRight = document.getElementById("tabRight");
	
	
	
		var nextBut = document.getElementById("nextbutton");
		nextBut.style.left = document.body.clientWidth - 66 + 'px';
		if(document.body.clientWidth < 860)
		{
			nextBut.style.left = 795 + 'px';
		}
	
	if(leftOffset < 0)
	{
		
		tabLeft.style.width = 0;
		tabRight.style.width = 0;
		tabRight.style.left = 0;
		
		
		
	}
	else
	{
		tabLeft.style.width = leftOffset + "px";
		tabRight.style.width = leftOffset + "px";
		//tabRight.style.marginLeft = (leftOffset + 1280) + "px";
	}

	/*var bottom = document.getElementById("bottomFiller"); 
	var bottomHeight = 0;
	if (window.innerHeight)
	{
	bottomHeight = window.innerHeight - 740;
	}
	else if (document.body.clientHeight)
	{
	bottomHeight = document.body.clientHeight - 740;
	}
	if(bottomHeight < 0 ) {bottomHeight = 0; }
	bottom.style.height =  bottomHeight+"px";*/
	
	var page = document.getElementById("pageBody"); 
	var pagePos = (document.body.clientWidth - 860)/2;
	if(pagePos < 0) { pagePos = 0; }
	page.style.left = pagePos + "px";

	//page.style.height = bod.clientHeight + "px";
	page.style.height = "100%";
	

	
	
	
} 

