window.onload = function() {
	// Calls generic function that can be placed in page
	try{pageLoaded()}catch(e){}
	//
	setCurrentButton();
	//
	toggleBreadcrumb();
}
// Function is called everytime a new page is loaded
// Add a class of "first" to the first element in the secondar_navigation ID
function gTrimSecondaryNav() {
	try{
		document.getElementById("secondary_navigation").getElementsByTagName('a')[0].className = "first";
	}catch(e){
		return;
	}
}
// If there is only one item in the breadcrumb, might as well hide it.
function toggleBreadcrumb() {
	var _bc = document.getElementById('breadcrumb')
	var _div = _bc.getElementsByTagName('div');
	if(_div.length <= 1) _bc.style.display = "none";
}
// ------------------------------------------------------- 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()",10);
}
// 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
// ------------------------------------------------------- Start Reset footer after dynamic change in page contents
function gRefreshFooter() {
	if(document.getElementById('footer')) {
		var gFoot = document.getElementById('footer')
		gFoot.style.display = "none";
		gFoot.style.display = "block";
	}
}
// ------------------------------------------------------- End Reset footer after dynamic change in page contents
// The folowing 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;
	}
	gRefreshFooter()
}
// Global debug function. Writes debug text to common popup window
function debug(txt) {
	if(gDebug) {
		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";
	}
}

function setEmail(arg){
	return '<a class="email" href="mailto:'+ arg+ '@seertechsolutions.com">' + arg + '@seertechsolutions.com</a>';
}
//
var lastButton;
function showDetails(obj) {
	if(typeof lastButton != 'undefined') lastButton.className = '';
	obj.className = 'active';
	lastButton = obj;
	_html = '<h2>'+obj.firstChild.nodeValue+'</h2>';
	_div = obj.parentNode.nextSibling;
	if(_div.nodeName != 'DIV') { // Firefox reads white space
		_div = getNode(_div,'DIV');
	}
	_html += _div.innerHTML;
	document.getElementById("displayContainer").innerHTML = _html;
	gRefreshFooter();
}
//
function getNode(_obj,_node) {
	_newNode = _obj.nextSibling
	if(_newNode.nodeName != _node) {
		getNode(_newNode,_node)
	}else{
		return _newNode;
	}
}