function ClearSearch() {
	try {
		var element = window.document.getElementById('SearchKeywords');
		if(element.value=='Search'){
			element.value='';
		}else{}
	} catch(e) {}
}

function WriteSearch() {
	try {
		var element = window.document.getElementById('SearchKeywords');
		if(element.value==''){
			element.value='Search';
		}else{}
	} catch(e) {}
}


ReplaceSearch = function() {
	try {
		var elements = window.document.getElementById('SearchKeywords');
		if(window.addEventListener){	
			elements.addEventListener('focus', ClearSearch, true);
			elements.addEventListener('blur', WriteSearch, true);	
		}else{
			elements.attachEvent("onfocus",ClearSearch);
			elements.attachEvent("onblur",WriteSearch);
		}
	} catch(e) {}
}


if(window.addEventListener) window.addEventListener('load', ReplaceSearch, false); // gecko, safari, konqueror and standard
else if(document.addEventListener) document.addEventListener('load', ReplaceSearch, false); // opera 7
else if(window.attachEvent) { // win/ie
	window.attachEvent('onload', ReplaceSearch);
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			existing();
			ReplaceSearch();
		}
	} else {
		window.onload = function() {
			ReplaceSearch();
		}
	}
}

function SetDropDowns(elmID){
	
	currDropDown = elmID;
	document.getElementById(currDropDown).style.left = "auto";
	
}

function landingPageRotator(direction){
	try{
		
		var parentElm = document.getElementById("Images");
		var numImages = document.getElementById("Images").getElementsByTagName("img").length;
		for(var i=0; i < numImages; i++){
			parentElm.getElementsByTagName("img")[i].style.display = "none";
		}
		if(!direction){
			parentElm.getElementsByTagName("img")[currImg].style.display = "block";
			if(timeout != 0){
				interval = setInterval("landingPageRotator('next')",timeout);
			}
		}
		else if(direction == 'next'){
			parentElm.getElementsByTagName("img")[updateCurrImg(direction,numImages)].style.display = "block";
			clearInterval(interval);
			interval = setInterval("landingPageRotator('next')",timeout);
		}
		else if(direction == 'prev'){
			parentElm.getElementsByTagName("img")[updateCurrImg(direction,numImages)].style.display = "block";
			clearInterval(interval);
			interval = setInterval("landingPageRotator('next')",timeout);
		}
	}catch(e){}
}

function updateCurrImg(direction, numImages){
	try{
		if(direction == 'next'){
			if(currImg < numImages-1){
				currImg++;
			}else{
				currImg = 0;
			}
		}else if(direction == 'prev'){
			if(currImg != 0){
				currImg--;
			}else{
				currImg = numImages-1;
			}
		}
		return currImg;
	}catch(e){}
}
var AltText = "";
var DriversAltText = "";
var TradeAltText = "";
var OEMAltText = "";

function showHideHomeFeature(pos, show, section){
	try{
		if(show == "links"){
			if(document.getElementById("IntroText"+pos).getElementsByTagName("p")[0]){
				document.getElementById("IntroText"+pos).getElementsByTagName("p")[0].style.display = "none";
			}
			if(document.getElementById("IntroText"+pos).getElementsByTagName("ul")[0]){
				document.getElementById("IntroText"+pos).getElementsByTagName("ul")[0].style.display = "block";
			}
			if(document.getElementById("Nav"+pos).getElementsByTagName("a")[0]){
				document.getElementById("Nav"+pos).getElementsByTagName("a")[0].className = "hover";
			}
			for(var i=1; i<=3; i++){
				document.getElementById("Image"+i).src="/files/images/home_images/"+section+"_"+i+".jpg";
				document.getElementById("Image"+(i)).alt = eval(section+"AltText");
			}
			switch(pos){
				case 1:
					document.getElementById("IntroText1").className = "IntroText hover";
					document.getElementById("IntroText2").className = "IntroText right";
					document.getElementById("IntroText3").className = "IntroText";
				break;
				case 2:
					document.getElementById("IntroText1").className = "IntroText left";
					document.getElementById("IntroText2").className = "IntroText hover";
					document.getElementById("IntroText3").className = "IntroText right";
				break;
				case 3:
					document.getElementById("IntroText1").className = "IntroText";
					document.getElementById("IntroText2").className = "IntroText left";
					document.getElementById("IntroText3").className = "IntroText hover";
				break;
			}
		}else if (show == "text"){
			if(document.getElementById("IntroText"+pos).getElementsByTagName("p")[0]){
				document.getElementById("IntroText"+pos).getElementsByTagName("p")[0].style.display = "block";
			}
			if(document.getElementById("IntroText"+pos).getElementsByTagName("ul")[0]){
				document.getElementById("IntroText"+pos).getElementsByTagName("ul")[0].style.display = "none";
			}
			if(document.getElementById("Nav"+pos).getElementsByTagName("a")[0]){
				document.getElementById("Nav"+pos).getElementsByTagName("a")[0].className = "";
			}
			for(var i=0; i<3; i++){
				document.getElementById("Image"+(i+1)).src="/files/images/home_images/default_"+(i+1)+".jpg";
				document.getElementById("Image"+(i+1)).alt = AltText;
				document.getElementById("IntroText"+(i+1)).className = "IntroText";
				document.getElementById("IntroText"+(i+1)).className = "IntroText";
				document.getElementById("IntroText"+(i+1)).className = "IntroText";
			}
		}
	}catch(e){}
}

/*
function showHideNews(elm){
	try{
		if(elm.style.display == "none"){
			elm.style.display = "block";
		}else{
			elm.style.display = "none";
		}
	}catch(e){}
}
*/


var head = document.getElementsByTagName('head')[0],
    style = document.createElement('style'),
    rules = document.createTextNode('ol.Dropdown li:hover ol, ol.Global li:hover ol {	left: -999em; }'),
    open = false,
    currImg = 0,
    currDropDown = "",
    currOpen = "";

style.type = 'text/css';
if(style.styleSheet)
    style.styleSheet.cssText = rules.nodeValue;
else style.appendChild(rules);
head.appendChild(style);

function DrawOverlay(elemID,ContentID,noCenter) {
    try {
		var x;
		var y;
		var obj = document.getElementById(elemID);
		var contentObj = document.getElementById(ContentID);
		
		windowProperties = GetWindowProperties();

		if(windowProperties[1] >= windowProperties[3] && navigator.appName != "Microsoft Internet Explorer"){
			obj.style.width = windowProperties[2]-17 + "px";
		} else {
			obj.style.width = windowProperties[2] + "px";
		}
		
		if(windowProperties[1] < windowProperties[3]){
			obj.style.height = windowProperties[3] + "px";
		} else {
			obj.style.height = windowProperties[1] + "px";
		}
		obj.style.display = "block";
		contentObj.style.display = "block";
		
		if(!noCenter){
			CenterOverlay(elemID,ContentID);
		}
		
	} catch(e) {}
}

function CenterOverlay(elemID,ContentID) {
	try{
		windowProperties = GetWindowProperties();
		
		elementStyle = document.getElementById("FadeContent").style;
		elementStyle.display = "block";
		overlayWidth = document.getElementById("FadeContent").clientWidth;
		overlayHeight = document.getElementById("FadeContent").clientHeight;
		overlayH = Math.round(((windowProperties[2] - overlayWidth)/2));
		overlayV = Math.round(windowProperties[3]*.1);
		overlayV2 = Math.round(windowProperties[4]+(windowProperties[3]*.1));
		if(overlayV < 10){
			overlayV = overlayV2;
		}
		if(overlayV < windowProperties[4]){
			overlayV = windowProperties[4]+(windowProperties[3]*.1); 
		}
		if(overlayH < 10){
			overlayH = 10;
		}
		
		elementStyle.left = overlayH+"px";
		elementStyle.top = overlayV+"px";
		
		if(overlayHeight >= windowProperties[3]){
			DrawOverlay(elemID,ContentID,'true');
		}

	}catch(e){}
}

function GetWindowProperties() {
	try{
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ 
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {	
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		
		if(typeof(window.pageYOffset) == 'number') {
			yOffset = window.pageYOffset;
		} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			yOffset = document.body.scrollTop;
		} else if(document.documentElement) {
			yOffset = document.documentElement.scrollTop;
     	 	}
     	 	
		return Array(xScroll,yScroll,windowWidth,windowHeight,yOffset);
		
	}catch(e){}
}



function CloseOverlay(videoPlayer){

    try {
		var obj = document.getElementById("FadePage");
		var contentObj = document.getElementById("FadeContent");

		obj.style.display = "none";
		contentObj.style.display = "none";

		if(videoPlayer != null){
			videoPlayer.style.visibility = "visible";
		}

		document.getElementById("Overlay").getElementsByTagName("object")[0].sendEvent('STOP','true');

	}catch(e){}
}


function ShowHide(elmID) {
	try{
		var elm = document.getElementById(elmID);
		if(elm.style.display == "none" || elm.style.display == ""){
			elm.style.display = "block";
		}else if(elm.style.display == "block"){
			elm.style.display = "none";
		}			
	}catch(e){}
}


function redirectPage(url){
	try{
		window.location = url;
	}catch(e){}
}
