// SUBNAVIGATION MENUS

function showSubNav(theSection,theName) {
	var ajaxRequest;  // The variable that makes Ajax possible!
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		try {
			if (window.XMLHttpRequest)
				ajaxRequest = new XMLHttpRequest()
			else if (window.ActiveXObject)
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch(e) {
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		}
	}

	if (navigator.userAgent.indexOf("Mozilla") >= 0)
		ajaxRequest = new XMLHttpRequest()

	function processRequest() {
		if (ajaxRequest.readyState == 4) {
			if (ajaxRequest.responseText != "") {
				document.getElementById("content").innerHTML = ajaxRequest.responseText;
			}
		}
	}

	ajaxRequest.onreadystatechange = processRequest;
	ajaxRequest.open("GET",theSection+"/"+theName+".htm", true);
	ajaxRequest.send("");
}

function rollSubNav(theID) {
	if (document.getElementById("subNavItem"+theID).className != "subNavItem-on")
		if (document.getElementById("subNavItem"+theID).className == "subNavItem")
			document.getElementById("subNavItem"+theID).className = "subNavItem-roll"
		else
			document.getElementById("subNavItem"+theID).className = "subNavItem"
}

function goSubNav(theSection,theName,theID,IDs) {
	for (var i = 1; i <= IDs; i++) {
		document.getElementById("subNavItem"+i).className = "subNavItem";
	}
	document.getElementById("subNavItem"+theID).className = "subNavItem-on";
	showSubNav(theSection,theName);
}


// VALIDATE EMAIL FIELDS
function validateEmail(field) {
    var regex = /^[\'a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if (field.value != "") {
	    if (!regex.test(field.value)) {
	        alert("Invalid email address")
	        field.focus()
	        return false
	    }
	}
    return (true);
}


// HISTORY TIMELINE SELECT

var theInt = null;
var $crosslink, $navthumb;
var curclicked = 0;

theInterval = function(cur){
	clearInterval(theInt);

	if( typeof cur != 'undefined' )
		curclicked = cur;

	$crosslink.removeClass("active-thumb");
	$navthumb.eq(curclicked).parent().addClass("active-thumb");
		$(".stripNav ul li a").eq(curclicked).trigger('click');

	theInt = setInterval(function(){
		$crosslink.removeClass("active-thumb");
		$navthumb.eq(curclicked).parent().addClass("active-thumb");
		$(".stripNav ul li a").eq(curclicked).trigger('click');
		curclicked++;
		if( 6 == curclicked )
			curclicked = 0;

	}, 3000);
};


// PORTFOLIO MENU

function showCategory(theCategory,theProject) {
	var ajaxRequest;  // The variable that makes Ajax possible!
	if (navigator.userAgent.indexOf("MSIE") >= 0) {
		try {
			if (window.XMLHttpRequest)
				ajaxRequest = new XMLHttpRequest()
			else if (window.ActiveXObject)
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch(e) {
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		}
	}

	if (navigator.userAgent.indexOf("Mozilla") >= 0)
		ajaxRequest = new XMLHttpRequest()

	function processRequest() {
		if (ajaxRequest.readyState == 4) {
			if (ajaxRequest.responseText != "") {
				document.getElementById("category").innerHTML = ajaxRequest.responseText;
			}
		}
	}

	ajaxRequest.onreadystatechange = processRequest;
	ajaxRequest.open("GET","/portfolio/"+theCategory+".asp?p="+theProject, true);
	ajaxRequest.send("");
}


// PORTFOLIO PROJECT SELECT

function goProject(theDirection,IDs) {
	if (theDirection == "next") {
		if (document.selectedForm.selectedProject.value < IDs) {
			var newID = Number(document.selectedForm.selectedProject.value) + 1;
			showProject(newID,IDs);
		}
	}
	else if (theDirection == "prev") {
		if (document.selectedForm.selectedProject.value > 1) {
			var newID = Number(document.selectedForm.selectedProject.value) - 1;
			showProject(newID,IDs);
		}
	}
}

function highlightProject(theID,theAction) {
	if (document.selectedForm.selectedProject.value != theID) {
		if (theAction == "on") {
			document.getElementById("project"+theID+"sm").style.opacity = .50;
			document.getElementById("project"+theID+"sm").style.filter = "alpha(opacity=50)";
		}
		else {
			document.getElementById("project"+theID+"sm").style.opacity = .25;
			document.getElementById("project"+theID+"sm").style.filter = "alpha(opacity=25)";
		}
	}
}

function showProject(theID,IDs) {
	document.selectedForm.selectedProject.value = theID;

	for (var i = 1; i <= IDs; i++) {
		document.getElementById("project"+i).style.display = "none";
		document.getElementById("project"+i+"sm").style.opacity = .25;
		document.getElementById("project"+i+"sm").style.filter = "alpha(opacity=25)";
	}
	document.getElementById("projectName").innerHTML = document.getElementById("title"+theID).innerHTML;
	document.getElementById("project"+theID+"sm").style.opacity = 1;
	document.getElementById("project"+theID+"sm").style.filter = "alpha(opacity=100)";
	var thumb = document.getElementById("thumb"+theID);
	var div = document.getElementById("filmstrip");
	div.scrollLeft = thumb.offsetLeft;
	$("#project"+theID).fadeIn("slow");

	if (theID == 1 && theID == IDs) {
		document.getElementById("prevButtonOff").style.display = "";
		document.getElementById("prevButton").style.display = "none";
		document.getElementById("nextButtonOff").style.display = "";
		document.getElementById("nextButton").style.display = "none";
	}
	else if (theID == 1) {
		document.getElementById("prevButtonOff").style.display = "";
		document.getElementById("prevButton").style.display = "none";
		document.getElementById("nextButtonOff").style.display = "none";
		document.getElementById("nextButton").style.display = "";
	}
	else if (theID == IDs) {
		document.getElementById("prevButtonOff").style.display = "none";
		document.getElementById("prevButton").style.display = "";
		document.getElementById("nextButtonOff").style.display = "";
		document.getElementById("nextButton").style.display = "none";
	}
	else {
		document.getElementById("prevButtonOff").style.display = "none";
		document.getElementById("prevButton").style.display = "";
		document.getElementById("nextButtonOff").style.display = "none";
		document.getElementById("nextButton").style.display = "";
	}
}


// CAREERS BLOCK SELECT

function showBlock(theDiv) {
	if (document.getElementById(theDiv+"Open").style.display == "none") {
		document.getElementById(theDiv+"Open").style.display = "";
		document.getElementById(theDiv+"Close").style.display = "none";
	}
	else {
		document.getElementById(theDiv+"Open").style.display = "none";
		document.getElementById(theDiv+"Close").style.display = "";
	}
}


// CAREERS MASER LIFE SELECT

function goMaserLife(theDiv,divCount) {
	document.getElementById("employee"+theDiv).style.display = ""
	for (var i = 1; i <= divCount; i++) {
		if (i != theDiv)
			document.getElementById("employee"+i).style.display = "none"
	}
}


// CAREERS EVENT SELECT

function goEvent(theDiv,divCount,theEvent) {
	if (document.getElementById("event"+theDiv).style.display == "none")
		document.getElementById("event"+theDiv).style.display = ""
	else
		document.getElementById("event"+theDiv).style.display = "none"
	for (var i = 1; i <= divCount; i++) {
		if (i != theDiv)
			document.getElementById("event"+i).style.display = "none"
	}
}

function zoomPic(theEvent,thePic) {
	document.getElementById(theEvent+"Photo").innerHTML = "<IMG SRC=\"/careers/events/"+theEvent+"/"+thePic+"\">"
}


// PR EVENT SELECT

function goEvent(theDiv,divCount) {
	if (document.getElementById("event"+theDiv).style.display == "none")
		document.getElementById("event"+theDiv).style.display = ""
	else
		document.getElementById("event"+theDiv).style.display = "none"
	for (var i = 1; i <= divCount; i++) {
		if (i != theDiv)
			document.getElementById("event"+i).style.display = "none"
	}
}


// COMMON FUNCTIONS

function showHide(theDiv) {
	if (document.getElementById(theDiv).style.display == "none") {
		document.getElementById(theDiv+"Title").style.display = "none";
		document.getElementById(theDiv).style.display = "";
	}
	else {
		document.getElementById(theDiv+"Title").className = "body";
		document.getElementById(theDiv+"Title").style.display = "";
		document.getElementById(theDiv).style.display = "none";
	}
}
