/*
Contextual Navigation
*/

// Image preload
if (document.images) {
	arrowOff = new Image(10,9);
	arrowOff.src = "/images/nav/contextual/arrowspacer.gif";
	bulletOff = new Image(6,9);
	bulletOff.src = "/images/nav/contextual/bulletspacer.gif";	
    bluerightOn = new Image(9,10);
	bluerightOn.src = "/images/nav/contextual/bluearrow_right.gif";
    bluedownOn = new Image(10,9);
	bluedownOn.src = "/images/nav/contextual/bluearrow_down.gif";
    bluesquareOn = new Image(6,9);
	bluesquareOn.src = "/images/nav/contextual/bluesquare.gif";
    bluedownOn = new Image(6,9);
	bluedownOn.src = "/images/nav/contextual/bluearrow_down.gif";	
}

// Image swap functions
function switchOn(imgName,imgFile) {
    if (document.images) { 
		imgOn = eval(imgFile + "On.src");
        document [imgName].src = imgOn;
	}
}

function switchOff(imgName,imgFile) {
    if (document.images) { 
        imgOn = eval(imgFile + "Off.src");
        document [imgName].src = imgOn;
	}
}

function switchOffPrimary(imgName) {
	if (document.images) {
        document [imgName].src = eval("bluedownOn.src");
	}
}

var blnSub = false;
var strNav = '<table border="0" cellpadding="0" cellspacing="1" width="116"><tr><td width="10" nowrap><spacer type="block" width="1" height="1"></td><td width="6" nowrap><spacer type="block" width="1" height="1"></td><td width="80" nowrap><spacer type="block" width="1" height="1"></td><td width="10" nowrap><spacer type="block" width="1" height="1"></td></tr><tr><td colspan="4" valign="top"><div class="greyline"><img src="/images/nav/contextual/graypixel.gif" width="116" height="1" alt=""></div></td></tr>';

function buildNav(strPrimary,strSecondary,aSecArray,aSecArrayImg,aSecArrayUrl) {
	for (var i = 0; i < aPrimary.length; i++) {
		if (aPrimary[i] == 'Lavorare in Sapient' || aPrimary[i] == 'Eventi di Recruiting' || aPrimary[i] == 'Ufficio stampa' || aPrimary[i] == 'Investor relations' || aPrimary[i] == 'Industries' || aPrimary[i] == 'Clienti' || aPrimary[i] == 'Eventi') { blnSub = true } else { blnSub = false }; 
		if (aPrimary[i] == strPrimary) {
			if (strSecondary) {
				strNav = strNav + '<tr><td height="10" nowrap><spacer type="block" width="1" height="10"></td><td colspan="2" class="sidenav"><a href="' + aPrimaryUrl[i] + '" onmouseover="switchOn(\'' + aPrimaryImg[i] + '\',\'blueright\')" onmouseout="switchOffPrimary(\'' + aPrimaryImg[i] + '\',\'arrow\');">' + aPrimary[i] + '</a></td><td nowrap><img src="/images/nav/contextual/bluearrow_down.gif" width="10" height="9" alt="" border="0" name="' + aPrimaryImg[i] + '"></td></tr>';
			} else {
				strNav = strNav + '<tr><td height="10" nowrap><spacer type="block" width="1" height="10"></td><td colspan="2" class="sidenav">' + aPrimary[i] + '</td><td nowrap valign="top">';
				if (blnSub) {
					strNav = strNav + '<div class="greyline"><img src="/images/nav/contextual/blackarrow_down.gif" width="10" height="9" alt="" border="0"></div></td></tr>';
				} else {
					strNav = strNav + '<div class="greyline"><img src="/images/nav/contextual/blackarrow_right.gif" width="10" height="9" alt="" border="0"></div></td></tr>';
				}
			}
		} else {
			strNav = strNav + '<tr><td height="10" nowrap><spacer type="block" width="1" height="10"></td><td colspan="2" class="sidenav"><a href="' + aPrimaryUrl[i] + '" onmouseover="switchOn(\'' + aPrimaryImg[i] + '\',';
			if (blnSub) {
				strNav = strNav + '\'bluedown\'';
			} else {
				strNav = strNav + '\'blueright\'';
			}
		strNav = strNav + ');" onmouseout="switchOff(\'' + aPrimaryImg[i] + '\',\'arrow\');">' + aPrimary[i] + '</a></td><td nowrap valign="top"><div class="greyline"><img src="/images/nav/contextual/arrowspacer.gif" width="10" height="9" alt="" border="0" name="' + aPrimaryImg[i] + '"></div></td></tr>';
		}
		if (aPrimary[i] == strPrimary && blnSub) {
			strNav = strNav + '<tr><td colspan="4" height="10" nowrap><spacer type="block" width="1" height="10"></td></tr>';		
			for (var j = 0; j < aSecArray.length; j++) {
				if (aSecArray[j] == strSecondary) {
					strNav = strNav + '<tr><td height="10" nowrap><spacer type="block" width="1" height="10"></td><td valign="top"><img src="/images/nav/contextual/blacksquare.gif" width="6" height="9" alt="" border="0"></td><td colspan="2" class="smnav">' + aSecArray[j] + '</td></tr><tr><td colspan="3" height="10" nowrap><spacer type="block" width="1" height="10"></td></tr>';
				} else {
					strNav = strNav + '<tr><td height="10" nowrap><spacer type="block" width="1" height="10"></td><td valign="top"><img src="/images/nav/contextual/bulletspacer.gif" width="6" height="9" alt="" border="0" name="' + aSecArrayImg[j] + '"></td><td colspan="2" class="smnav"><a href="' + aSecArrayUrl[j] + '" onmouseover="switchOn(\'' + aSecArrayImg[j] + '\',\'bluesquare\');" onmouseout="switchOff(\'' + aSecArrayImg[j] + '\',\'bullet\');">' + aSecArray[j] + '</a></td></tr><tr><td colspan="3" height="6" nowrap><spacer type="block" width="1" height="6"></td></tr>';
				}
			}		
		}
		strNav = strNav + '<tr><td colspan="4"><div class="greyline"><img src="/images/nav/contextual/graypixel.gif" width="116" height="1" alt=""></div></td></tr>';
	}
	strNav = strNav + '</table>'
	return strNav;
}
