// Array use to preload Global Navigation images
var global_nav = new Array();
var global_nav_hover = new Array();

global_nav[0]=global_nav["home"]="../header/img/home.gif";
global_nav[1]=global_nav["personal"]="../header/img/personal.gif";
global_nav[2]=global_nav["business"]="../header/img/business.gif";
global_nav[3]=global_nav["about"]="../header/img/about.gif";
global_nav[4]=global_nav["help"]="../header/img/help.gif";
global_nav_hover[0]=global_nav_hover["home"]="../header/img/home_hover.gif";
global_nav_hover[1]=global_nav_hover["personal"]="../header/img/personal_hover.gif";
global_nav_hover[2]=global_nav_hover["business"]="../header/img/business_hover.gif";
global_nav_hover[3]=global_nav_hover["about"]="../header/img/about_hover.gif";
global_nav_hover[4]=global_nav_hover["help"]="../header/img/help_hover.gif";
imagePreload(global_nav);
imagePreload(global_nav_hover);

// preload images
function imagePreload(imageArray) {
	var i;
	for(i=0; i<imageArray.length; i++) {
	    imageArray.src=imageArray[i];
	}	
}

function switchSource(which){
	var img = eval("document.images." + which);
	if(img.src.indexOf("active") != -1) return true;
	var ref = which.substring(eval(which.lastIndexOf("_")+1));
	var source = (img.src.indexOf("hover") != -1) ? global_nav[ref] : global_nav_hover[ref];
	img.src = source;
}

function setGlobalNavLinksImage(channelPath) {

	// remove string up to and including first hyphen
	var remove_string_index = channelPath.indexOf("-") + 1;
	channelPath = channelPath.substring(remove_string_index, channelPath.length);

	// get rid of first underscore
	channelPath = channelPath.replace("_","");
	
	var homepageChannelPath = "";
	var personalChannelPath = "personal";
	var businessChannelPath = "business";
	var smallbusinessChannelPath = "smallbusiness";
	var wholesaleChannelPath = "wholesale";
	var aboutoptusChannelPath = "aboutoptus";
	var helpChannelPath = "aboutoptus-help";
	
	var activeHomelink;
	var activeHomelinkImage;
	var activeHomelinkImageSrc;

	if(channelPath == helpChannelPath) {
		// help is selected
		activeHomelink = document.getElementById("help");
		activeHomelinkImage = document.getElementById("global_nav_help");
		activeHomelinkImageSrc = global_nav["help"];

	} else if(channelPath.substring(0, aboutoptusChannelPath.length) == aboutoptusChannelPath) {
		// about optus is selected
		activeHomelink = document.getElementById("aboutoptus");
		activeHomelinkImage = document.getElementById("global_nav_about");
		activeHomelinkImageSrc = global_nav["about"];
		
	} else if(channelPath.substring(0, businessChannelPath.length) == businessChannelPath ||
		  channelPath.substring(0, smallbusinessChannelPath.length) == smallbusinessChannelPath ||
		  channelPath.substring(0, wholesaleChannelPath.length) == wholesaleChannelPath) {
		// business is selected
		activeHomelink = document.getElementById("business");
		activeHomelinkImage = document.getElementById("global_nav_business");
		activeHomelinkImageSrc = global_nav["business"];

	} else if(channelPath.substring(0, personalChannelPath.length) == personalChannelPath) {
		// personal is selected
		activeHomelink = document.getElementById("personal");
		activeHomelinkImage = document.getElementById("global_nav_personal");
		activeHomelinkImageSrc = global_nav["personal"];
		
	} else {
		// homepage is selected
		activeHomelink = document.getElementById("home");
		activeHomelinkImage = document.getElementById("global_nav_home");
		activeHomelinkImageSrc = global_nav["home"];
		
	}

	activeHomelink.id = "global-menu-active";
	activeHomelinkImageSrc = activeHomelinkImageSrc.replace(".gif","_active.gif");
	activeHomelinkImage.src = activeHomelinkImageSrc;
}

function primaryNavSelector(rootChannelName) {
	while(rootChannelName.indexOf(" ") != -1) {
		rootChannelName = rootChannelName.replace(" ", "");
	}

	while(rootChannelName.indexOf("&") != -1) {
		rootChannelName = rootChannelName.replace("&", "");
	}

	rootChannelName = rootChannelName.toLowerCase();

	var pNavObj = document.getElementById(rootChannelName);

	if(pNavObj != null && pNavObj != "undefined") {
		pNavObj.className = "act";
	}
}
