// ################################################################
//  Preload timers and page set up 
// ################################################################
function preLoad() { 	// I load the page.
	reBox();
	window.onresize = reBox;
	// doAlphaChange(document.getElementById('topBanner'),0,100,20,10,1);
	//time1a = setTimeout("doAlphaChange(document.getElementById('NavBackground'),0,100,20,10,1);",100);
	 doContent();
}
// ################################################################
//  Page set up and div positions
// ################################################################
function reBox() {
	var TheCheat = document.getElementById('cheater');
	var TheCBox = document.getElementById('truC');
	var RealSizeH = TheCheat.offsetHeight;
	var RealSizeW = TheCheat.offsetWidth;
	var RealCSizeH = TheCBox.offsetHeight;
	var RealCSizeW = TheCBox.offsetWidth;
	var TheMiddle = Math.round((RealSizeW / 2)-1.4);
	var widthOffset = 990;
	var TheLeftEdge = (TheMiddle - (widthOffset / 2));
	var TheRightEdge = (TheMiddle + (widthOffset / 2));
	if(document.getElementById('truC').offsetHeight > 300) { 
	var minCHeight = document.getElementById('truC').offsetHeight
	} else {
	var minCHeight = 300;
	}
	// document.getElementById('cTop').innerHTML= minCHeight+' || '+document.getElementById('truC').offsetHeight ;
	var bannerHeight = 400;
	var TheContentHeight = (RealSizeH); 
	var sideSize = 150;
	var barWidth = 2;
	var topPad = 100;
	var minLeft = 0;
	if (TheLeftEdge <= minLeft) {
		TheLeftEdge = 0;
		TheRightEdge = widthOffset;
		TheMiddle = widthOffset / 2;
	}
	document.getElementById('logo').style.left = TheLeftEdge+"px";
	document.getElementById('logo').style.top = topPad+"px";
	document.getElementById('theNav').style.left = TheLeftEdge+"px";
	document.getElementById('theNav').style.top = topPad+72+"px";
	document.getElementById('LBar').style.left = TheLeftEdge+sideSize+"px";
	document.getElementById('RBar').style.left = TheRightEdge-sideSize-barWidth+"px";
	document.getElementById('LBar').style.width = barWidth+"px";
	document.getElementById('RBar').style.width = barWidth+"px";
	document.getElementById('contentbox').style.left = TheLeftEdge+sideSize+barWidth+"px";
	document.getElementById('contentbox').style.width = widthOffset-sideSize-sideSize-barWidth-barWidth+"px";
	document.getElementById('cHolder').style.height = topPad+"px";
	document.getElementById('cTop').style.height = topPad+"px";

	// document.getElementById('underC').style.left = TheLeftEdge+sideSize+barWidth+"px";
	// document.getElementById('underC').style.width = widthOffset-sideSize-sideSize-barWidth-barWidth+"px";
	// document.getElementById('underC').style.height = RealSizeH+"px";
	// alert(widthOffset-sideSize-sideSize-barWidth-barWidth);
	// document.getElementById('cImage').style.width = widthOffset-sideSize-sideSize-barWidth-barWidth+"px";
	document.getElementById('cImage').style.width = widthOffset-sideSize-sideSize-barWidth-barWidth+"px"; 
	document.getElementById('cImage').style.top = topPad+"px";
	document.getElementById('cHolder').style.top = topPad+bannerHeight+"px";
	document.getElementById('cHolder').style.width = widthOffset-sideSize-sideSize-barWidth-barWidth+"px";
	document.getElementById('truC').style.width = widthOffset-sideSize-sideSize-barWidth-barWidth-50+"px";
	
	if ((RealSizeH-bannerHeight-topPad ) < minCHeight) {
		document.getElementById('contentbox').style.height = topPad+bannerHeight+minCHeight+"px";
		document.getElementById('RBar').style.height = topPad+bannerHeight+minCHeight+"px";
		document.getElementById('LBar').style.height = topPad+bannerHeight+minCHeight+"px";
		document.getElementById('cHolder').style.height = minCHeight+"px";
	} else { 
		document.getElementById('cHolder').style.height = RealSizeH - topPad - bannerHeight+"px";
		document.getElementById('RBar').style.height = RealSizeH+"px";
		document.getElementById('LBar').style.height = RealSizeH+"px";
		document.getElementById('contentbox').style.height = RealSizeH+"px";
	}
}

rollImgs = new Array()
rollImgs[0] = new Image(); rollImgs[0].src = "images/VintageGroup.gif";
rollImgs[1] = new Image(); rollImgs[1].src = "images/VintageGroup2.gif";

function rollIt(way){ 
	if(way){	document.getElementById('Vlogo').src = rollImgs[1].src;
	} else {	document.getElementById('Vlogo').src = rollImgs[0].src;
	}
 }
 
 
// ###############################
// initial load of content
// ###############################
function doContent() { 
	origText = document.getElementById("truC").innerHTML;
	document.getElementById("truC").innerHTML = ""
	// thisPadder = "0px";
	if ( origText.indexOf('<!-- split -->') != -1 ) {
		theSplit = origText.split('<!-- split -->');		
		if (theSplit.length == 4) {
			// document.getElementById('banner').innerHTML=theSplit[1];
			document.getElementById('imgBox').innerHTML=theSplit[2];
			theContent = theSplit[3];
			wipeContentA('up');
		} else if (theSplit.length == 2) {
				theContent = theSplit[1];				
				preCount = theSplit[0].split('<!-- count -->'); document.getElementById('cImage').innerHTML=preCount[0]; if (preCount[1]*1 > 1) {slideshow(1,preCount[1],6000);}  
				
				
				 wipeContentA('up');
		} else { alert(theSplit.length);
			// document.getElementById('banner').innerHTML="Error!";
			theContent = "an error occured with the request, please retry. If this problem persists, please contact a site administrator<br><br><hr>"+M_contentJax.responseText;
			wipeContentA('up');
		}	
	} // else {
	// document.getElementById('banner').innerHTML="Error!";
	// theContent = "an error occured with the request, please retry. If this problem persists, please contact a site administrator<br><br><hr>"+M_contentJax.responseText;
	// wipeContentA('up');
	// }
	// alert("loaded content");
}


// ##############################
// SlideShow
//###############################

function slideshow(start,last,interval) {
  var frame = start;
  var nextframe = start+1;
  Effect.Appear('img1',{duration:.5,from:0.0,to:1.0});
    setInterval(function() {
    Effect.Fade('img'+frame,{duration:.5,from:1.0,to:0.0,afterFinish:function(){
    $('img'+frame).hide();
    Effect.Appear('img'+nextframe,{duration:.5,from:0.0,to:1.0});
    frame = nextframe;
    nextframe = (frame == last) ? start : nextframe+1;
    }});
 },interval);
 return;
};

function wipeContentA(move) {
	isContent="A";
	document.getElementById('truC').innerHTML= theContent;
	elem = document.getElementById('truC');
	// reBox();
	// elem.style.zIndex=10;
	// elem.innerHTML="";
	if (move == 'up') { 
		fromHeight= 0; // document.getElementById('RightC').offsetHeight; 
		toHeight = document.getElementById('truC').offsetHeight; 
		// alert(fromHeight+" ,"+toHeight);
	} else { 
		isContent="0";
		fromHeight=elem.offsetHeight; 
		toHeight = 1; 
	}	
	// doHeightChange(document.getElementById("truC"),fromHeight,toHeight,50,10,1);
	contentTimerA = setTimeout("reBox()",500);
	contentTimerB = setTimeout("reBox()",1000);
	// contentTimer = setTimeout("showContentA()",2100);
}

// check AJAX and define an AJAX object.
function GetXmlHttpObject() {
	var MyAjax=null;
	try {// Firefox, Opera 8.0+, Safari
  		MyAjax=new XMLHttpRequest();
  	}
	catch (e) {	// Internet Explorer
  		try { MyAjax=new ActiveXObject("Msxml2.XMLHTTP"); }
  		catch (e) { MyAjax=new ActiveXObject("Microsoft.XMLHTTP"); }
  	}
	return MyAjax;
} 
