//url for page redirects, etc
var url = "http://www.tietz-baccon.com/";

//variables to handle size of the background image
var imgW = 1280;
var imgH = 960;
var imgRatio = imgW/imgH;

//calls the resizeImg() function when the window is resized			
window.onresize = resizeImg;

//resizes the background image according to the ratio
function resizeImg(){
	w = window.innerWidth;
	h = window.innerHeight;
	if(!h){
		w = document.body.offsetWidth;
		h = document.documentElement.clientHeight;
	}
	ratio = w/h;
	
	newScale = ratio/imgRatio;
	
	if(newScale > 1){
		document.getElementById('bgImg').width = w;
		document.getElementById('bgImg').height = Math.round(h*newScale);
	}else {
		document.getElementById('bgImg').width = Math.round(w/newScale);
		document.getElementById('bgImg').height = h;
	}
}

function expandTitle(w, goal, h, work){
	if(w == goal){
		document.getElementById('titleBarContent').style.display = 'block';
		expandContent(0,h, work);
	}else{
		
		if(goal - w == 90 || goal - w == 60 || goal - w == 30) newW = w+30;
		else newW = w+90;
		newWS = newW.toString() + "px";
		document.getElementById('titleBar').style.width = newWS;
		the_timeout2 = setTimeout('expandTitle('+newW+','+goal+','+h+','+work+');',50);
	}
}

function expandContent(h, goal, work){
	if(h == goal){
		document.getElementById('contentDiv').style.display = 'block';
		if(work == 1) document.getElementById('thumbContainer').style.display = 'block';
	}else{
		if(goal - h == 50 || goal - h == 25) newH = h+25;
		else newH = h+50;
		newHS = newH.toString() + "px";
		document.getElementById('contentBg').style.height = newHS;
		the_timeout3 = setTimeout('expandContent('+newH+','+goal+','+work+')',50);
	}
}

function moveNav(targetUL, steps, initY, finalY, lnk){
	if(steps != 0){
		//determine the step distance
		diff = finalY - initY;
		stepD = Math.abs(diff)/4;
		
		//set the factor
		if(steps > 2) factor = 6 - steps;
		else if(steps == 2) factor = 3.5;
		else if(steps == 1) factor = 4;
		
		//change style based on moving up or down
		if(diff > 0){
			newX = initY + factor*stepD;
			newXS = newX.toString() + "px";
			document.getElementById(targetUL).style.top = newXS; 
		}else{
			newX = initY - factor*stepD;
			newXS = newX.toString() + "px";
			document.getElementById(targetUL).style.top = newXS; 
		}
		
		//increment the step and reload on timer
		newStep = steps - 1;
		the_timeout = setTimeout('moveNav("'+targetUL+'",'+newStep+','+initY+','+finalY+',"'+lnk+'");',50);
	}else{
		if(lnk != "") window.location.href = url+lnk;
	}
}

function loadPage(word4, lnk3){
	//clear the existing stuff on the stage (tertiary nav and any page content that is on the page)
	document.getElementById('tertiaryNavUL').innerHTML = '&nbsp;';
	document.getElementById('contentHolder').style.display = "none";
	
	//forward to lnk
	window.location.href = url+lnk3;
}

function updateSecondaryNav(responseText, responseStatus){
	if (responseStatus==200) {
		//alert("responses: "+responseText);
		var responses = responseText.split("|"); //the split is the two data sets
		document.getElementById('secondaryNavUL').innerHTML = responses[0];
		document.getElementById('secondaryNavUL').style.top = responses[1];
	}else {
		//alert(responseStatus + ' -- Error Processing Request');
	}
}

function updateTertiaryNav(responseText, responseStatus){
	if (responseStatus==200) {
		var responses = responseText.split("|"); //the split is the two data sets
		document.getElementById('tertiaryNavUL').innerHTML = responses[0];
		document.getElementById('tertiaryNavUL').style.top = responses[1];
	}else {
		//alert(responseStatus + ' -- Error Processing Request');
	}
}


