/*
Developed by S3 Group Pty Ltd
Suite 328, Level 3, 368 Sussex Street
Sydney, NSW 2000
www.s3group.com.au

Copyright 2006
Last Modified: 23rd June 2006
*/

// -------------------------------------
// drop down menu variable declaration *
// -------------------------------------

var timeOn = null
var numMenus = 7; // This refers to the number of menu tabs in the navigation, as opposed to the number of menus in the xml file
var menuActive = 0;
var dropDownDelay = 300;
var menuXml = "xml/menu.xml";
document.onmouseover = menuOut;
document.onclick = menuOut;
window.onerror = function () { return true; }


// ------------------------
// drop down menu functions *
// ------------------------

// MENU MOUSE OVER 
function menuOver() {
	clearTimeout(timeOn);
	menuActive = 1;
}// MENU MOUSE OUT 
function menuOut(event) {
	if (menuActive == 1) {
		menuActive = 0 ;	
	 	timeOn = setTimeout("hideAllMenus()", dropDownDelay);
	}
}

function showMenu(menuNumber, eventObj) {
    hideAllMenus();
	
	if(document.layers) {
		img = getImage("img" + menuNumber);
		x = getImagePageLeft(img);
		y = getImagePageTop(img);
		menuTop = y + 10; // LAYER TOP POSITION
		eval('document.layers["menu'+menuNumber+'"].top="'+menuTop+'"');
		eval('document.layers["menu'+menuNumber+'"].left="'+x+'"');
	}
	
	eventObj.cancelBubble = true;

	var link = document.getElementById("link" + menuNumber);
	if (link != undefined) {
		link.className = "on";
	}
	
	var menuId = 'menu' + menuNumber;
	if(changeObjectVisibility(menuId, 'visible')) {
		return true;
	} else {
		return false;
    }
}

function hideAllMenus() {
    for(counter = 1; counter <= numMenus; counter++) {
		changeObjectVisibility('menu' + counter, 'hidden');
    }
	
	resetLinks();
}

function resetLinks() {
	for(counter = 1; counter <= numMenus; counter++) {
		var link = document.getElementById('link' + counter);
		if (link != undefined) {
			link.className = "";	
		}
    }		
}


// -----------------------
// hacks and workarounds *
// ------------------------

// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();

    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

function mClk(src){ 
	if(event.srcElement.tagName=='TD')
		src.children.tags('A')[0].click();
}


// -----------------------
// drop down item events *
// -----------------------

function dropDownItemOver(menuName, itemNumber) {
	var top = document.getElementById(menuName + "_" + itemNumber + "_top");
	var bottom = document.getElementById(menuName + "_" + itemNumber + "_bottom");
	var item = document.getElementById(menuName + "_" + itemNumber + "_item");
	
	top.className = "dropdown_item_top_on";
	bottom.className = "dropdown_item_bottom_on";
	item.className = "dropdown_item_on";
}

function dropDownItemOut(menuName, itemNumber) {
	var top = document.getElementById(menuName + "_" + itemNumber + "_top");
	var bottom = document.getElementById(menuName + "_" + itemNumber + "_bottom");
	var item = document.getElementById(menuName + "_" + itemNumber + "_item");
	
	top.className = "dropdown_item_top";
	bottom.className = "dropdown_item_bottom";
	item.className = "dropdown_item";
}

function cancelBubble(e)
{
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}
