/**
 * menu.js
 *
 * @author		Jonathan Pitre
 * @description	This file contains the various JavaScript functions which control the drop-down
 *				menu of the www.builditsoftware.com home page. Modifying this file might result
 *				in the loss of drop-down menu functionality.
 * @changelog
 * --------------------------------------------------------------------------------------------------
 * Jonathan Pitre		13/06/2011	Final release of script.
 * --------------------------------------------------------------------------------------------------
 */

var timeout	= 500;
var closetimer	= 0;
var mainMenuItem	= 0;
var underline	= 0;

var MenuElements = new Object;

// open hidden layer
function mopen(id, pageid)
{	
	// cancel close timer
	mcancelclosetime();
	// close old layer
	if(mainMenuItem) mainMenuItem.style.visibility = 'hidden';
	// get new layer and show it
	mainMenuItem = document.getElementById(id);
	mainMenuItem.style.visibility = 'visible';
	//mainMenuItem.className = "faded";
	
	/* Attempting to retrieve children. */
	var childNodes = mainMenuItem.childNodes;
	var childID = "";
	for (i=0; i < childNodes.length; i++){
		childID = childNodes[i].id;
		if (typeof childID !== 'undefined' && childID.charAt(0) == 'a'){
			MenuElements[childID] = childNodes[i];
			childNodes[i].style.opacity = 0.7;
			childNodes[i].style.filter = 'alpha(opacity=70)';
		}
	}
	
	var img = id+"_img";
	if (underline) underline.style.visibility = 'hidden';
	underline = document.getElementById(img);
	underline.style.visibility = 'visible';
	
	if (pageid != "index") verifyLine(pageid);
}

// Makes an element opaque. Contains a check to make sure nothing becomes opaque which shouldn't.
function makeOpaque(id){
	MenuElements[id].style.opacity = '1.0';
	MenuElements[id].style.filter = 'alpha(opacity=100)';
}

// Makes an element transparent. Contains a check to make sure nothing becomes transparent which shouldn't.
function makeTransparent(id){
	MenuElements[id].style.opacity = '0.7';
	MenuElements[id].style.filter = 'alpha(opacity=70)';
}

// close showed layer
function mclose(pageid)
{
	if(mainMenuItem) mainMenuItem.style.visibility = 'hidden';
	if(underline) underline.style.visibility = 'hidden';
	verifyLine(pageid);
}

// Makes sure that the underline is maintained.
function verifyLine(pageid){
	if (pageid != "index"){
		var under = document.getElementById(pageid + "_img");
		under.style.visibility = 'visible';
	}
}

// go close timer
function mclosetime(pageid)
{
	closetimer = window.setTimeout(function(){mclose(pageid)}, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
//document.onclick = mclose
