// mouseover preloads
var mouseovers = new Array();
if (document.images) {
	var mouseoversList = new Array('about_rolyn', 'services', 'license', 'contact_us', 'news', 'report_an_emergency', 'project_login','button-homepage-10_things','button-homepage-priority_service','case_study-next','case_study-back', 'submitbtn', 'resetbtn');
	for (var i=0; i<mouseoversList.length; i++) {
		mouseovers[mouseoversList[i]+'Off'] = new Image();
		mouseovers[mouseoversList[i]+'Off'].src = "/images/navigation/"+mouseoversList[i]+'-off.gif';
		mouseovers[mouseoversList[i]+'On'] = new Image();
		mouseovers[mouseoversList[i]+'On'].src = "/images/navigation/"+mouseoversList[i]+'-on.gif';
	}
}

// mouseover image functions
function imgOn(parent) {
	// don't turn on current page's nav link
	imgName = parent.firstChild.name;
	if (document.images && (imgName != (convertToId(primaryPage)))) { document[imgName].src = mouseovers[imgName+'On'].src; }
}

function imgOff(parent) {
    // don't turn off current page's nav link
	imgName = parent.firstChild.name;
	if (document.images && (imgName != (convertToId(primaryPage)))) { document[imgName].src = mouseovers[imgName+'Off'].src; }
}

// menu init
var inMenu = 0;
var curLayer = "";
var menuTimeout = null;

// mouseover image functions for menu item images
function menuItemOn(el,parentImage) {
    clearTimeout(menuTimeout);
    inMenu = 1;
	parentImage = parentImage.id;
	parentImage = parentImage.replace("Menu","");
	if (document.images && (parentImage != (convertToId(primaryPage)))) { document[parentImage].src = mouseovers[parentImage+'On'].src; }
}

function menuItemOff(el,parentImage) {
    inMenu = 0;
	menuTimeout = setTimeout("hideMenu(curLayer)", 50);
	parentImage = parentImage.id;
	parentImage = parentImage.replace("Menu","");
    if (document.images && (parentImage != (convertToId(primaryPage)))) { document[parentImage].src = mouseovers[parentImage+'Off'].src; }
}

// show menu
function showMenu(layerName,parent) {
	if (menuTimeout != null) {
		clearTimeout(menuTimeout);
		hideMenu(curLayer);
	}
	eval('document.getElementById("'+layerName+'").style.visibility = "visible"');
	curLayer = layerName;
	imgOn(parent);
}

// hide menu
function hideMenu(layerName) {
	if (inMenu == 0) {
		eval('document.getElementById("'+layerName+'").style.visibility = "hidden"');
    }
}

// mouse out timer
function setTimer(parent) {
    // time after mouse moves away from menu heading before menu is hidden
    menuTimeout = setTimeout("timeUp()",150);
	imgOff(parent);
}

// check menu status and see if we should hide the last menu
function timeUp() {
    if (inMenu == 0) {
        hideMenu(curLayer);
    }
}

function setBreadcrumbLinks() {
	link1 = convertToLink(primaryPage);
	link2 = convertToLink(secondaryPage);
	link3 = convertToLink(tertiaryPage);
	link4 = convertToLink(quaternaryPage);

	//document.getElementById('bcl1').href = "/"+link1+"/index.html";
	if (link2 != "") {
		document.getElementById('bcl2').href = "/"+link1+"/"+link2+"/index.html";
		if (link3 != "") { 
			//special case because capabilities isnt a page
			if (link3 == "capabilities") {
				document.getElementById('bcl3').href = "#";
				document.getElementById('bcl3').style.cursor = "text";
				document.getElementById('bcl3').onclick = function() { return false };
			} else { 
				document.getElementById('bcl3').href = "/"+link1+"/"+link2+"/"+link3+"/index.html";
			}
		}
		if (link4 != "") { document.getElementById('bcl4').href = "/"+link1+"/"+link2+"/"+link3+"/"+link4+".html"; }
	} else {
		if (link3 != "") { document.getElementById('bcl3').href = "/"+link1+"/"+link3+"/index.html"; }
		if (link4 != "") { document.getElementById('bcl4').href = "/"+link1+"/"+link3+"/"+link4+".html"; }
	}
}

function convertToLink(val) {
	//strip out "& "
	//then convert spaces to dashes
	//then convert slashes to dashes
	//then convert to all lowercase
	val = val.replace(/& /g,"");
	val = val.replace(/\//g,"-");
	val = val.replace(/ /g,"-");
	val = val.toLowerCase();
	return val;
}

function convertToId(val) {
	//strip out "& "
	//then convert spaces to dashes
	//then convert slashes to dashes
	//then convert to all lowercase
	val = val.replace(/& /g,"");
	val = val.replace(/\//g,"_");
	val = val.replace(/ /g,"_");
	val = val.toLowerCase();
	return val;
}
