/*  ================================
     Sitewide JavaScript
    ================================ */

	var isIE6;
	var homePics = new Array();  
	var curImage = 0;  //current image the homebanner is set to
	var homeVideo = "<object width='480' height='270'><param name='movie' value='http://www.youtube.com/v/gdNTCaobZPk&hl=en_US&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/gdNTCaobZPk&hl=en_US&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' wmode='transparent' width='480' height='270'></embed></object>"
	isIE6 = false;
	
	homePics[0] = "<object width='480' height='270'><param name='movie' wmode='transparent' value='http://www.youtube.com/v/fyKtVmK5YKE&hl=en_US&fs=1&'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><param name='wmode' value='opaque'></param><embed src='http://www.youtube.com/v/fyKtVmK5YKE&hl=en_US&fs=1&' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='270' wmode='opaque'></embed></object>";
	homePics[1] = "<object width='480' height='270' wmode='transparent'><param name='movie' value='http://www.youtube.com/v/3giQMgNdyXg&hl=en_US&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='wmode' value='opaque'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/3giQMgNdyXg&hl=en_US&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='270' wmode='opaque'></embed></object>";
	//homePics[2] = "<a href='sustainability.asp' title='Lube Stop Sustainability Program'><img src='images/home_rotate2.jpg'></a>";
	homePics[2] = "<object width='480' height='270'><param name='movie' wmode='transparent' value='http://www.youtube.com/v/l01pA33rCzY&hl=en_US&fs=1&'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><param name='wmode' value='opaque'></param><embed src='http://www.youtube.com/v/l01pA33rCzY&hl=en_US&fs=1&' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='270' wmode='opaque'></embed></object>";
	homePics[3] = "<object width='480' height='270'><param name='movie' value='http://www.youtube.com/v/mz1p4Z7Eqbk&hl=en_US&fs=1&rel=0'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><param name='wmode' value='opaque'></param><embed src='http://www.youtube.com/v/mz1p4Z7Eqbk&hl=en_US&fs=1&rel=0' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='480' height='270' wmode='opaque'></embed></object>";
	
	function sitewidePageLoaded()
	{
		// All pages on load
		init();
	}
	
/*  ================================
     Template 1 JavaScript
    ================================ */

	function template1Loaded()
	{
		// Per template on load
		sitewidePageLoaded();
	}
	
function navOn(temp) {	
	//safe function to show an element with a specified id
	var x=temp.getElementsByTagName('ul');
	if(x[0]){x[0].style.display = 'block';}
	
	var y=temp.getElementsByTagName('a');
	y[0].style.backgroundColor = '#E4E4E4';
	y[0].style.color = '#777';
	y[0].style.backgroundImage = 'none';
	$(temp).prev('li').find('a:first').css("backgroundImage","none");
	//alert($(temp).prev('li').id());
}

//displays the first ul in the container when called in rollover script init()
function navOff(temp) {
    //safe function to hide an element with a specified id
	var x=temp.getElementsByTagName('ul');
	if(x[0]){x[0].style.display = 'none';}
	
	var y=temp.getElementsByTagName('a');
	y[0].style.backgroundColor = "";
	y[0].style.color = '#FFF';
	if($(y[0]).attr("class") != "endbtn"){y[0].style.backgroundImage = 'url(images/nav_divider.png)';}
	$(temp).prev('li').find('a:first').css("backgroundImage","url(images/nav_divider.png)");
}

//loads the onmouseover/onmouseout actions onto all the nav elements
function init(){
    //var x = document.getElementById('topnav').getElementsByTagName('li');
//    for (var i=0;i<x.length;i++)
//	{
//	    $(x[i]).mouseenter(function () {navOn(this);});
//		$(x[i]).mouseleave(function () {navOff(this);});
//	}
	$(".firstlvl").mouseenter(function () {navOn(this);});
	$(".firstlvl").mouseleave(function () {navOff(this);});
	
}

$(document).ready(function(){
	$("#search").find(".txtbox").focus(function() {if (this.value == "Enter zip code"){this.value = "";}});
	$("#search").find(".txtbox").blur(function() {if (this.value == ""){this.value = "Enter zip code";}});
	
	$(".newsletter").find(".txtbox").focus(function() {if (this.value == "E-mail Address"){this.value = "";}});
	$(".newsletter").find(".txtbox").blur(function() {if (this.value == ""){this.value = "E-mail Address";}});
	
	$("#zipsearch").focus(function() {if (this.value == "Zip"){this.value = "";}});
	$("#zipsearch").blur(function() {if (this.value == ""){this.value = "Zip";}});
	
	$("#citysearch").focus(function() {if (this.value == "City, State"){this.value = "";}});
	$("#citysearch").blur(function() {if (this.value == ""){this.value = "City, State";}});		
	
});
	
	
	
function changeHomePic(dir){
	
	if(int == ""){ //clicked an arrow while viewing the video
		int = setInterval("changeHomePic('asc')", 8000); 
	} 
	switch (dir){
		case "asc":
			if(curImage < homePics.length-1){ curImage++;}
			else if(curImage >= homePics.length-1){ curImage = 0; }
			break;
		case "desc":
			if(curImage > 0){ curImage--;}
			else if(curImage <= 0){ curImage = homePics.length-1;}
			break;
	}
	$("#home_banner").html(homePics[curImage]);
	if(homePics[curImage].indexOf("</object>") >= 0){clearInterval(int); int = "";}
}

function setHomeVideo(){
		$("#home_banner").html(homeVideo);
		clearInterval(int);
		int = "";
}
	
function validate(theForm){
	var num_of_elements = theForm.length;
	
	for(var i=0; i<num_of_elements; i++){	
			if(theForm.elements[i].type == "text" && theForm.elements[i].alt == "required" && theForm.elements[i].value == ""){
				alert("Please fill out all required fields");	
				return false;
			}
	}
	
	if(document.getElementById("file1")){
		filename = document.getElementById("file1").value.toLowerCase();
		if(filename.indexOf(".doc") < 0 && filename.indexOf(".pdf") < 0 && filename != ""){
			alert("Please convert your resume into one of the appropriate document formats: PDF, DOC, DOCX");
			return false;
		}
	}
}

function validate2(theForm){
	var num_of_elements = theForm.length;
	
	for(var i=0; i<num_of_elements; i++){	
			if(theForm.elements[i].type == "text" && theForm.elements[i].alt == "required" && theForm.elements[i].value == ""){
				alert("Please fill out all required fields");	
				return false;
			}
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var addr = $(".emailTxt").attr("value")
	if(!reg.test(addr)){
		alert("Please provide a valid email address");
		return false;
	}
}