
// additions to the Array Object from dithered.com to allow for the inability of IE 5 and lower to handle all ECMA Array recommendations

var undefined;
function isUndefined(property) {
  return (typeof property == 'undefined');
}

// Array.pop() - Remove the last element of an array and return it
if (isUndefined(Array.prototype.pop) == true) {
  Array.prototype.pop = function() {
  	var lastItem = undefined;
    if ( this.length > 0 ) {
        lastItem = this[this.length - 1];
        this.length--;
    }
    return lastItem;
  };
}

//preload images

function preLoad()
{
	if (!document.getElementById('minimenu') && document.images)
	{
		loadedImg = new Image();
		var menuImg = new Array('home', 'gallery', 'pstips', 'mactips', 'contact', 'blog', 'cv');
		for(var i = 0; i < menuImg.length; i++) 
		{
			loadedImg.src = toRoot + "images/"+menuImg[i]+"_over.gif";
		}
	}
}


var crntMnu = new Array();
var subMenuItems = new Array("ga_list","pslist","aplist");//"ps_open","ap_open"
var bool = null;




/*

all menus are open when the page loads. This allows googlebot and other crawlers to follow what are essentially NOSCRIPT anchors. The following function closes the open menus

*/

// called first to hide all the open menu
function onloadHide()
{
	for(var i = 0; i < subMenuItems.length; i++)
	{
		hide(subMenuItems[i],'none');
	}
	
}

// the main function that's referenced a lot to change the visibility
function hide(IDvalue, visState)
{
	document.getElementById(IDvalue).style.display = visState;	
}


/*
This is the function called by the mouseover and mouseout. It checks if the current menu has been clicked
If it has been clicked, the mouse events don't work
*/
function mouseEvent(menuHeaderID, mHbC, mHtC)
{
	var crntMnuFnd = 0;
	for(var i = 0; i < crntMnu.length; i++)
	{
		if (crntMnu[i] == menuHeaderID)
			crntMnuFnd = 1;
	}
	if (crntMnuFnd != 1)
		colorChange(menuHeaderID, mHbC, mHtC);
}

// This changes the background colour and the text colour of the targeted menu 
function colorChange(menuHeaderID, mHbC, mHtC)
{	
		document.getElementById(menuHeaderID).style.backgroundColor = mHbC;
		document.getElementById(menuHeaderID).style.color = mHtC;
}

/*

1. Assign the current selected ID to the flag value for the mouse events
2. Reveal the subMenu's contents by changing its display value to the opposite of what it is now
3. Change the background-color and color styles of the current selected ID
ie: showMenu2('gallery', 'galist', '#4f0005', '#ffdada')
*/

function showMenu2(menuHeaderID, subMenuHeaderID, mHbC, mHtC)
{
	bool = arrayShorten(menuHeaderID);
	selectMenu(menuHeaderID, subMenuHeaderID, mHbC, mHtC, bool);
}

/* 
This function loads an array with the id value of the clicked menu
The menu item is added to the array if it is not already in there. If it IS already in there, it is taken out.
This works in tandem with the mouseEvent function
*/
function arrayShorten(menuHeaderID)
{
	for(var i = 0; i < crntMnu.length; i++)
	{
		if(crntMnu[i] == menuHeaderID)
		{
			for(var j = i; j < crntMnu.length; j++)
			{
				if(j == (crntMnu.length-1))
				{
					crntMnu.pop();
				}else{
					crntMnu[j] = crntMnu[(j+1)];
				}
			}
		return(true);
		}	
	}
	return(false);
}

/* 
called by test2
If bool returned falseadd the current menu id to the checkable array
call the switchHide function
then the colorChange function
*/
function selectMenu(menuHeaderID, subMenuHeaderID, mHbC, mHtC, bool)
{
	if (!bool)
		crntMnu[crntMnu.length] = menuHeaderID;
	switchHide(subMenuHeaderID);
	colorChange(menuHeaderID, mHbC, mHtC);
}

/*
checks the string of the id for an underscore - as this means it should appear as inline instead of block

If the display is presently set to 'none' it changes it to the value inBlock and sends that to the hide function
If it is set to inline or block, it changes it to none by calling the hide function
It also changes the class of the subMenu
*/
function switchHide(subMenuHeaderID)
{	
	var inBlock = 'block';
	if (subMenuHeaderID.indexOf('_') != -1)
	{
		inBlock = 'inline';
	}	
	if (document.getElementById(subMenuHeaderID).style.display == 'none')
	{
		hide(subMenuHeaderID, inBlock);
		document.getElementById(subMenuHeaderID).className = 'subMenuClass';
	}else{
		hide(subMenuHeaderID, 'none');
	}
}

/*
=========================================================
*/



function chngImgDown(imgName)
{
	document[imgName].src = toRoot + 'images/'+imgName+'_over.gif';
}

function chngImgOut(imgName)
{
	document[imgName].src = toRoot + 'images/'+imgName+'_off.gif';
}

function chngOS() 
{
	var b = document.getElementsByTagName('span');
	if(!b) 
		return;
	if(/Mac/i.test(navigator.userAgent)){
		var os = 'pc';
	}else{
		var os = 'mac';
	}
	
	for(var i = 0; i<b.length; i++)
	{
		var c = b[i];
		if( c.className == os || c.className == 'or')
			c.style.display = 'none';
	}
	
}