// call init function on loading window / webpage loading
window.onload = init;

// function will setup everything we need to do when website finishes loading
function init()
{
	var liArr = document.getElementsByTagName('li');
	for(i=0; i<liArr.length; i++)
	{
		var theLi = liArr[i];
		var imgsArr = theLi.getElementsByTagName('img');
		
		for (j=0; j<imgsArr.length; j++) {
			var theImg = imgsArr[j];
			if(theImg.src.indexOf('_off') != -1) {
				var blankSrc = theImg.src.substr(0, theImg.src.indexOf('_off'));
				
				theImg.rollover = new Image();
				theImg.rollover.src = blankSrc + '_on.png';
				
				theImg.rollout = new Image();
				theImg.rollout.src = blankSrc + '_off.png';
			}	
		}		
		
		if(theLi.className=='flyoutMenu')
		{
			theLi.onmouseover = showMenu;
			theLi.onmouseout = hideMenu;
		}
	}
}

function showRollOver(theImg) {
	theImg.src = theImg.rollover.src;
}

function showRollOut(theImg) {
	if(theImg.rollout) {
		theImg.src = theImg.rollout.src;
	}
}

function showMenu()
{
	var allDivs = this.getElementsByTagName('div');
	var menuDiv = allDivs[0];
	
	if(menuDiv)
		menuDiv.className = 'flyOutMenuEnable';
	
	var imgsArr = this.getElementsByTagName('img');
		
	for (j=0; j<imgsArr.length; j++) {
		var theImg = imgsArr[j];
		if(theImg.src.indexOf('_off') != -1) {
			showRollOver(theImg);
		}	
	}	
}

function hideMenu()
{
	var allDivs = this.getElementsByTagName('div');
	var menuDiv = allDivs[0];
	
	if (menuDiv) {
		menuDiv.className = 'flyOutMenuDisable';
	}
		
	var imgsArr = this.getElementsByTagName('img');
		
	for (j=0; j<imgsArr.length; j++) {
		var theImg = imgsArr[j];
		if(theImg.src.indexOf('_on') != -1) {
			showRollOut(theImg);
		}	
	}	
}
