// Global window onload function
// Anything that needs to happen onload goes in here
window.onload = function() {
	// Calls generic function that can be placed in page
	try{pageLoaded()}catch(e){}
	setCurrentButton();
setSubCurrentButton();
}

// Start Drop Down Menu Functions - Sam 240209
var _curr_dd;
// Opens the sub menu – Called from menu button
function gOpen_dd(_dd,_obj){
	if(_curr_dd) {
		if(_curr_dd.id != _dd) gClose_dd(true);
	}
	_curr_dd = _obj.nextSibling;
	_curr_dd._btn =  _obj;
	_curr_dd._btn.className = "active";
	// If innerHTML is empty, populate from store
	if(_curr_dd.innerHTML == '<!-- EMPTY -->') {
		_curr_dd.innerHTML = document.getElementById(_dd).innerHTML;
	}
	_curr_dd._active = true;
	gSetDisplay(_curr_dd,'block');
	
}
// Waits to see if menu button and submenu has been moved away from – Called from menu and submenu buttons
function gWait_dd() {
	_curr_dd._active = false;
	setTimeout("gClose_dd()",100);
}
// Sets the current menu button and submenu to active – Called from submenu buttons
function gActive_dd() {
	_curr_dd._active = true;;
}
// Closes the submenu when it and the menu button are no longer active. – Private function.
function gClose_dd(_force){
	if(_force) {
		gSetDisplay(_curr_dd,'none');
		_curr_dd._btn.className = "";
	}else{
		if(!_curr_dd._active) {
			gSetDisplay(_curr_dd,'none');
			_curr_dd._btn.className = "";
		}
	}
}
// End Drop Down Menu Functions
// This function simply changes the display of an object on screen.
// I’m channeling the calls through here to prevent issues with the
// footer overlapping DIVs when they switched on/off as it always 
// calls gRefreshFooter() after changing the display.
// Channel any change in display through here to allow a footer refresh
function gSetDisplay(_var,_display) {
	if(typeof _var == 'object') {
		_var.style.display = _display;
	}else{
		document.getElementById(_var).style.display = _display;
	}
}
// Turn on/off global debug using a key combination

// Global debug function. Writes debug text to common popup window
function debug(txt) {
		if(typeof debugWindow == 'undefined') {
			debugWindow =  window.open('about:blank','debugWindow','width=400,height=800,top=0,left=0,scrollbars=yes,resize=yes');
			txt = '<p><a href="javascript:void(0)" onclick="toggleDebug()">Toggle debug On/Off</a></p>'+txt;
		}
		debugWindow.document.write(txt+'<BR>')
}
// Set current button with "current" class
function setCurrentButton() {
	if(typeof gCurrent != "undefined") {
		var _index = gCurrent - 1;
		document.getElementById("primary_navigation").getElementsByTagName("li")[_index].className = "current";
	}
}
// Set current button with "sub_current" class
function setSubCurrentButton() {
	if(typeof gSubCurrent != "undefined") {
		var _Subindex = gSubCurrent - 1;
		document.getElementById("sub_primary_navigation").getElementsByTagName("li")[_Subindex].className = "sub_current";
	}
}
