
// the function for the expand/collapse of left navigation
function leftNav() {
	// quit if this function has already been called
	if (arguments.callee.done) return;
	arguments.callee.done = true;

	// extend string obj natively to trim the strings
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}
	
	// select all the neccessary divs
	var allDiv = document.getElementById("scLeftNav").getElementsByTagName("div");
	var selDiv = new Array();
	for (var i=0; i<allDiv.length; i++) {
		if (allDiv[i].className == "navHead")
			selDiv.push(allDiv[i]);
	}
	
	if (selDiv.length > 0) {
		// expand initial menus
		if (Get_Cookie('navigation')) {
				var openNav = Get_Cookie('navigation'); // string of all open navs
				var explosion = openNav.split("|"); //array of all open navs
				var openNav =''; // empty var for reuse
				for (var i=0; i< explosion.length-1; i++) {
					for (var j=0; j<selDiv.length; j++) {
						if (selDiv[j].innerHTML.trim() == explosion[i])
							selDiv[j].parentNode.className = "navGroup selected";
					}
				}
			}
		
		for (var i=0; i<selDiv.length; i++) {
			
			selDiv[i].onmouseover =function(){
				var x = this.parentNode;
				if (x.className != "navGroup selected") {
					this.className = "navHead hoverHead"
				}
			};
			
			selDiv[i].onmouseout =function(){
				this.className = "navHead"
			};
			
			selDiv[i].onclick = function() {
				var x = this.parentNode;
				//alert(this.innerHTML.trim());
				// expand menus
				if (x.className == "navGroup selected") {
					x.className = "navGroup";
					if (Get_Cookie('navigation')) {
						var openNav = Get_Cookie('navigation'); // string of all open navs
						var explosion = openNav.split("|"); //array of all open navs
						openNav = ""; //set empty for variable reuse
						for (var i=0; i< explosion.length; i++) {
							// if matching the current collapse don't add into string. "|" is the delimiter
							//alert(explosion[i]);
							//alert(this.nodeValue);
							if ( explosion[i] != this.innerHTML.trim() && explosion[i]!='')
								openNav += explosion[i]+"|";
						}
						//alert (openNav);
						//now we got the string, let' set the cookie
						Set_Cookie( 'navigation', openNav, 300, '/', '', '' );
					}
					
				}
				// collapse menus
				else {
					x.className = "navGroup selected";
					
					var currentNav = this.innerHTML.trim();
					
					if (Get_Cookie('navigation')) {
						var openNav = Get_Cookie('navigation');
						//alert(openNav+currentNav+"|");
						Set_Cookie( 'navigation', openNav+currentNav+"|", 300, '/', '', '' );
					}
					else {
						//alert(currentNav+"|");
						Set_Cookie( 'navigation', currentNav+"|", 300, '/', '', '' );
					}
				}
			}
		}
	}
	// no leftNav is detected
	else {
		document.getElementById("leftNav").parentNode.setAttribute("width", 0);
		document.getElementById("leftNav").style.width = 0;
	}
}

function addEventMenuMin(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn); // this is for internet explorer events are Onload , Onclick etc. 
		return r;
	} else {
		return false;
	}
}

function init() {
	this.n = typeof this.n == 'undefined' ? 0 : this.n + 1;

	// flag this function so we don't do the same thing twice
	if (typeof document.getElementsByTagName != 'undefined' 
		&& (document.getElementsByTagName('body')[0] != null || document.body != null)
		) {
		try {
			leftNav();
		} catch(e) {};
	} else if (this.n < 240) { // 240 --> 1 minute time-out...
		setTimeout('init()', 250);
	} else {
		if (!addEventMenuMin(window, 'load', leftNav)) {
			if (document.body.onload) {
				var originalFunction = document.body.onload;

				document.body.onload = function () {
					try {
						leftNav();
					} catch(e) {};
					originalFunction();
				}
			} else {
				document.body.onload = leftNav;
			}
		}
	}
}

init();
