initProductMenu = function() {
	if (document.getElementById) {
		navRoot = document.getElementById("ProductMenu");
		for (i=0; (li = navRoot.getElementsByTagName("LI")[i]); i++) {
			if (li.firstChild.className == "HasItems")
				li.onclick = openSubmenu;
		}
	}
}

function openSubmenu(e) {
	if (typeof e == "undefined") e = window.event;
	
	var source = getSource(e);
	if (source.parentNode.className == "HasItems") // cancel event if a lowest level item has been clicked 
	{
		var ul = this.getElementsByTagName("UL")[0];
		var span = this.firstChild;

		if (this.className == "Open") {
			this.className = "";
			span.style.backgroundImage = "url(../Images/IconPlus.gif)";
			ul.style.display = "none";
		}
		else {
			this.className = "Open";
			span.style.backgroundImage = "url(../Images/IconMinus.gif)";
			ul.style.display = "block";
		}
	}
	
	if (window.event){ e.cancelBubble = true; }
	else if (e.which){ e.stopPropagation(); }
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function getSource(e){
	/* Adapted from http://www.quirksmode.org/js/events_properties.html */
    if (typeof e == 'undefined') {
        var e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else { 
    	return true;
    }
    if (source.nodeType == 3) {
        source = source.parentNode;
    }
    return source;
}

addLoadEvent(initProductMenu);