var itemList="", itemCount=0;
var tabToOpen;
var accordion;
var accordionOptions;
var accordionContents;


function preloadRolloverNavImages(){
	var lev2 = new Image()
	lev2.src= "/images/nav/levelTwo_over.jpg";
	
	var gm = new Image();
	gm.src='/images/nav/btn_GM.jpg'
	
	var additional = new Image();
	additional.src='/images/nav/btn_additional.jpg'
	
	var service = new Image();
	service.src='/images/nav/btn_service.jpg'
	
	var contact = new Image();
	contact.src='/images/nav/btn_contact.jpg'
	
	var email = new Image();
	email.src='/images/nav/btn_email.gif'
	
}

function trackLeftMenuLink()
{
	var index = -1;
	var pageURI = window.location.href;
	//small business menu
	if (pageURI.indexOf("/smallbusiness") > -1) {
		index = -1;
		if (pageURI.indexOf("/smallbusiness/vehicles") > -1)
			index = 0;
		else if (pageURI.indexOf("/smallbusiness/finddealer") > -1) 
			index = 1;
		if (pageURI.indexOf("/smallbusiness/incentives") > -1)
			index = 2;
		else if (pageURI.indexOf("/smallbusiness/specialtyvehicles") > -1)
			index = 3;
		else if (pageURI.indexOf("/smallbusiness/maintenance") > -1)
			index = 4;
		else if (pageURI.indexOf("/smallbusiness/incentives") > -1)
			index = 2;
	}
	//fleet menu
	else if (pageURI.indexOf("/fleet") > -1) {
		index = -1;
		if (pageURI.indexOf("/fleet/vehicles") > -1) 
			index = 5;
		else if (pageURI.indexOf("/fleet/finddealer") > -1)
			index = 6;
		else if (pageURI.indexOf("/fleet/incentives") > -1)
			index = 7;
		else if (pageURI.indexOf("/fleet/specialtyvehicles") > -1)
			index = 8;
		else if (pageURI.indexOf("/fleet/maintenance") > -1)
			index = 9
		else if (pageURI.indexOf("/fleet/incentives/businesschoice") > -1)
			index = -1;
		else if (pageURI.indexOf("/fleet/incentives") > -1)
			index = 7;
	}
	// government menu
	else if (pageURI.indexOf("/government") > -1) {
		index = -1;
		if ( (pageURI.indexOf("/government/products") > -1) && (pageURI.indexOf("navSec=products") > -1) )
			index = 11;
		else if (pageURI.indexOf("/government/products") > -1) 
			index = 10;
		else if ( (pageURI.indexOf("/government/ordering") > -1) && (pageURI.indexOf("navSec=ordering") > -1) )
			index = 13;
		else if (pageURI.indexOf("/government/ordering") > -1)
			index = 12;
		else if (pageURI.indexOf("/government/maintenance-info") > -1)
			index = 14;
		else if (pageURI.indexOf("/government/maintenance-tools") > -1)
			index = 15;
	}
	// tools menu
	else if (pageURI.indexOf("/tools") > -1) {
		index = -1;
		if (pageURI.indexOf("tools/help") > -1)
			index = 21;
	}
	// return value - missing pdf links
	return (index);
}

//doing show and hide for the nav dropdowns
function getElemRefs(id) {
  var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
  if (el) el.css = (el.style)? el.style: el;
  return el;
}
var timer;
var divId = "";
var status = "";
function showLayer(id) {
	if(status != "" && status != id){
		var lyrs = getElemRefs(status);
		if (lyrs && lyrs.css) {
			lyrs.css.display = "none";
			lyrs.css.visibility = "hidden";
		}
	}
	status = id;
	var lyr = getElemRefs(id);
	if(timer) clearTimeout(timer);
	if (lyr && lyr.css) {
		lyr.css.display = "block";
		lyr.css.visibility = "visible";
	}
}
function hideLayer(id) {
	if(timer) clearTimeout(timer);
	divId = id;
	timer = setTimeout("hide()", 200);
}
function hide(){
	status = "";
	var lyr = getElemRefs(divId);
	if (lyr && lyr.css) {
		lyr.css.display = "none";
		lyr.css.visibility = "hidden";
	}
}

//global rollover function
function globalOver(img){
  if(document.images){
    document.images[img].src = '/image/nav/'+img+'_on.gif';
  }
}
function globalOut(img){
  if(document.images){
    document.images[img].src = '/image/nav/'+img+'_off.gif';
  }
}

//local rollover function
function localOver(img){
  if(document.images){
    document.images[img].src = 'image/'+img+'_on.gif';
  }
}
function localOut(img){
  if(document.images){
    document.images[img].src = 'image/'+img+'_off.gif';
  }
}

//for FLEET TOOLS table toggle
function sLayer(id) {
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) {
		lyr.css.display = "block";
		lyr.css.visibility = "visible";
	}
}
function hLayer(id) {
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) {
		lyr.css.display = "none";
		lyr.css.visibility = "hidden";
	}
}
function toggle(id, links){
	//console.debug(id + " " + links);
	//console.debug(document.getElementById(id).className);
	
	if (document.getElementById(id).className.indexOf("subItemOn") == -1){
		document.getElementById(id).className="subItemOn";
		document.getElementById(links).style.display="block";
	}else {
		document.getElementById(id).className="subItemOff";
		document.getElementById(links).style.display="none";
	}
	//itemList = links;
}
function switchOver(id, links){
		if (document.getElementById(id).className != "subItemOn")
			document.getElementById(id).className="subItemOver";
}
function switchOut(id, links){
		if (document.getElementById(id).className != "subItemOn")
			document.getElementById(id).className="subItemOff";
}


function show(id, showId){
	id.className="iMenu";
	if (document.getElementById(showId).className == "itemHide"){
		document.getElementById(showId).className="itemShown";
	}else
		document.getElementById(showId).className="itemHide";
	return false;	
}

function  selectNavTab() {
	//tabToOpen = trackLeftMenuLink();
	accordionOptions = document.getElementsByClassName("subItemOff"); 
	accordionContents = document.getElementsByClassName("linksContent");
	
	for (var i = 0; i < accordionOptions.length; i++) {
		accordionOptions[i].className = "subItemOff";
		accordionContents[i].style.display = "none";

		accordionOptions[i].contentId = accordionContents[i].id;
		accordionOptions[i].onclick = function() { toggle(this.id, this.contentId) } ;
	}

};
