//the ajax objects
var secondaryNavObj = new ajaxObject('http://www.tietz-baccon.com/AJAX/secondaryNav.php', updateSecondaryNav);
var tertiaryNavObj = new ajaxObject('http://www.tietz-baccon.com/AJAX/tertiaryNav.php', updateTertiaryNav);

//keeps track of the position of the navigation elements
var primaryPos = -1;
var secondaryPos = -1;
var tertiaryPos = -1;
var navStep = 32;		//distance between nav elements (30px + 2px margin)

function loadSecondayNav(word){
	//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";
	
	//parse the variable to get the order of the variable and the link name
	number = parseInt(word.substr(0, 1));
	section = word.substr(2);
	
	primaryPos = number;
	secondaryPos = 0;
	
	//send the variables
	pVars = "placement="+number;
	secondaryNavObj.update(pVars, 'GET');	
	
	//turn all the primary nav to black and transparent
	document.getElementById('mainPROFILE').className = "navLi main";
	document.getElementById('mainSERVICES').className = "navLi main";
	document.getElementById('mainWORK').className = "navLi main";
	document.getElementById('mainNEWS').className = "navLi main";
	document.getElementById('mainCLIENTS').className = "navLi main";
	document.getElementById('mainLOGIN').className = "navLi main";
	document.getElementById('mainCONTACT').className = "navLi main";
	
	//turn the active button to pink
	document.getElementById('main'+section).className = "navLiOn main";
}

function loadTertiaryNav(word2, lnk){
	//clear existing stuff
	document.getElementById('contentHolder').style.display = "none";
	
	//parse the variable to get the order of the variable and the link name
	primary = parseInt(word2.substr(0,1));
	number = parseInt(word2.substr(2, 1));
	section = word2.substr(4);
			
	if(primaryPos == 0){
		document.getElementById('secondaryCOMPANY').className = "navLi secondary";
		//document.getElementById('secondaryTEAM').className = "navLi secondary";
	}else if(primaryPos == 1){
		document.getElementById('secondaryALL SERVICES').className = "navLi secondary";
		document.getElementById('secondaryFABRICATION').className = "navLi secondary";
		document.getElementById('secondaryDESIGN').className = "navLi secondary";
		document.getElementById('secondaryDETAILS').className = "navLi secondary";
	}else if(primaryPos == 2){
		document.getElementById('secondaryDESIGN').className = "navLi secondary";
		document.getElementById('secondaryFABRICATION').className = "navLi secondary";
	}else if(primaryPos == 3){
		document.getElementById('secondaryBLOG').className = "navLi secondary";
		document.getElementById('secondaryPRESS').className = "navLi secondary";
		//document.getElementById('secondarySOCIAL-MEDIA').className = "navLi secondary";
	}else if(primaryPos == 6){
		document.getElementById('secondaryLOCATION').className = "navLi secondary";
		document.getElementById('secondaryCOMMUNICATE').className = "navLi secondary";
		document.getElementById('secondaryJOBS').className = "navLi secondary";
	}
	
	//turn the active button to pink
	document.getElementById('secondary'+section).className = "navLiOn secondary";
	
	//figure out the height of current element
	curHeight = document.getElementById('secondaryNavUL').style.top;
	len = curHeight.length;
	len2 = curHeight.substr(0, len-2);
	oldH = parseInt(len2);
	
	if(number > secondaryPos){
		diff = (number - secondaryPos) * navStep;
		newH = oldH - diff;
	}else if(number < secondaryPos){
		diff = (secondaryPos - number) * navStep;
		newH = oldH + diff;
	}else{
		newH = oldH;
	}
	
	secondaryPos = number;
	tertiaryPos = 0;
	
	moveH = newH.toString()+"px";
	
	//send the variables
	pVars = "primary="+primary+"&placement="+number;
	tertiaryNavObj.update(pVars, 'GET');
	
	
	moveNav('secondaryNavUL', 5, oldH, newH, lnk);
}

function loadContent(word3, lnk2){
	//turn off existing content
	document.getElementById('contentHolder').style.display = "none";
	
	//parse the variable to get the order of the variable and the link name
	number = parseInt(word3.substr(0, 1));
	section = word3.substr(2);
	
	if(primaryPos == 0 && secondaryPos == 1){
		document.getElementById('tertiaryANDREW BACCON').className = "navLi tertiary";
		document.getElementById('tertiaryERIK TIETZ').className = "navLi tertiary";
		document.getElementById('tertiaryTHE PHILLIP LEE').className = "navLi tertiary";
	}else if(primaryPos == 2 && secondaryPos == 0){
		document.getElementById('tertiaryBUILDINGS').className = "navLi tertiary";
		document.getElementById('tertiaryCOMPONENTS').className = "navLi tertiary";
		document.getElementById('tertiaryOBJECTS').className = "navLi tertiary";
	}else if(primaryPos == 2 && secondaryPos == 1){
		document.getElementById('tertiarySMALL').className = "navLi tertiary";
		document.getElementById('tertiaryMEDIUM').className = "navLi tertiary";
		document.getElementById('tertiaryLARGE').className = "navLi tertiary";
	}else if(primaryPos == 3 && secondaryPos == 2){
		document.getElementById('tertiaryFACEBOOK').className = "navLi tertiary";
		document.getElementById('tertiaryTWITTER').className = "navLi tertiary";
		document.getElementById('tertiaryLINKED-IN').className = "navLi tertiary";
	}
		
	//turn the active button to pink
	document.getElementById('tertiary'+section).className = "navLiOn tertiary";
	
	//figure out the height of current element
	curHeight = document.getElementById('tertiaryNavUL').style.top;
	len = curHeight.length;
	len2 = curHeight.substr(0, len-2);
	oldH = parseInt(len2);
	
	if(number > tertiaryPos){
		diff = (number - tertiaryPos) * navStep;
		newH = oldH - diff;
	}else if(number < tertiaryPos){
		diff = (tertiaryPos - number) * navStep;
		newH = oldH + diff;
	}else{
		newH = oldH;
	}
	
	tertiaryPos = number;
	
	moveH = newH.toString()+"px";
	
	moveNav('tertiaryNavUL', 5, oldH, newH, lnk2);
	
}

var activeWork = "";

function updateWork(img,title, path){
	document.getElementById('workImage').innerHTML = '<img src="'+url+'IMG/WORK/'+path+'/'+img+'" width="500" height="375" border="0" />';
	if(activeWork == ""){
		activeWork = "thumb-"+title;
		document.getElementById(activeWork).className = "workThumbOn";
	}else{
		document.getElementById(activeWork).className = "workThumb";
		activeWork = "thumb-"+title;
		document.getElementById(activeWork).className = "workThumbOn";
	}	
}

var thumbPos = 0;

function moveThumbs(direction, steps, max){
	if(steps != 0){		
		
		if(direction == "right" && (thumbPos + 618) > (618 - max) ){
			if(steps == 4) thumbPos -= 30;
			else if(steps == 3 || steps == 2) thumbPos -= 15;
			else if(steps == 1) thumbPos -= 2;
			newPos = thumbPos.toString() + "px";
			
			document.getElementById('thumbBar').style.left = newPos;
		}else if(direction == "left" && thumbPos != 0){
			if(steps == 4) thumbPos += 30;
			else if(steps == 3 || steps == 2) thumbPos += 15;
			else if(steps == 1) thumbPos += 2;
			newPos = thumbPos.toString() + "px";
			
			document.getElementById('thumbBar').style.left = newPos;
		}
		
		newStep3 = steps - 1;
		the_timeout3 = setTimeout('moveThumbs("'+direction+'",'+newStep3+','+max+');',50);
	}
}

var galleryPos = 0;

function prepMoveGallery(num){
	posY = galleryPos/-432;
	sizer = Math.abs(posY-num);
		
	if(num > posY) moveGallery("UP",5, sizer);
	else if(num < posY) moveGallery("DOWN",5,sizer);
}

function moveGallery(upDown,steps, factor){
	if(steps != 0){
		
		if(upDown == "UP"){
			if(steps == 5 || steps == 4) galleryPos -= (150*factor);
			if(steps == 3 || steps == 2) galleryPos -= (60*factor);
			if(steps == 1 ) galleryPos -= (12*factor);
			newPosY = galleryPos.toString() + "px";
			document.getElementById('galleryMover').style.top = newPosY;
		}else{
			if(steps == 5 || steps == 4) galleryPos += (150*factor);
			if(steps == 3 || steps == 2) galleryPos += (60*factor);
			if(steps == 1 ) galleryPos += (12*factor);
			newPosY = galleryPos.toString() + "px";
			document.getElementById('galleryMover').style.top = newPosY;
		}
		newStep4 = steps - 1;
		the_timeout4 = setTimeout('moveGallery("'+upDown+'",'+newStep4+','+factor+');',50);
	
	}
}

var textToMove = false;
var maxMove = 0;
var minMove = 5;

function moveTextDown(){
	textToMove = true;
	aY = document.getElementById('workTxt').offsetHeight;
	
	maxMove = 366 - aY;
	moveText("down");
}

function moveTextUp(){
	textToMove = true;
	moveText("up");
}

function stopText(){
	textToMove = false;
}

function moveText(direction){
	topY = document.getElementById('workTxt').style.top;
	len = topY.length;
	len2 = topY.substr(0, len-2);
	oldY = parseInt(len2);
	
	if(direction == "down") oldY -= 5;
	else if(direction == "up") oldY += 5;
	
	newTopY = oldY.toString() + "px";
	
	
	if(textToMove && oldY > maxMove && oldY <= minMove){
		document.getElementById('workTxt').style.top = newTopY;
		the_timeout5 = setTimeout('moveText("'+direction+'");',50);
	}
}