/*
* addEvent()
* usage: addEvent(event, function);
* note: only targets window events!
*
*/
function addEvent(_event, _function) {
	var _current_event = window[_event];
	if (typeof window[_event] != 'function') {
		window[_event] = _function;
	} else {
		window[_event] = function() {
			_current_event();
			_function();
		};
	}
} 
/*
 * 
 */
function attachMenu(id){
	var menuNode = document.getElementById(id);
	var menuChildren = menuNode.getElementsByTagName("div");
	var childLi = null;
	for(var i = 0; i < menuChildren.length; i++){ //find all a tags that are respopnsible expanding/collapsing submenu
		if(menuChildren.item(i).nodeName != 'DIV' || menuChildren.item(i).parentNode != menuNode){			
			continue;
		}				
		var submenuChildren = menuChildren.item(i).getElementsByTagName("div");
		for(var j = 0; j < submenuChildren.length; j++){
			if(submenuChildren.item(j).nodeName != 'DIV' || submenuChildren.item(j).parentNode != menuChildren.item(i)){ //ul
				continue;
			}
			//let's append expand/collapse
			var expandNode = document.createElement("span");
			expandNode.setAttribute("class", "imz_expand");
			expandNode.appendChild(document.createTextNode(""));
			expandNode.onclick = function() {
				if(this.getAttribute("class") == "imz_expand"){
					var children = this.parentNode.getElementsByTagName("div");					
					for(var i = 0; i < children.length; i++){						
						if(children.item(i).parentNode == this.parentNode){							
							children.item(i).setAttribute("style", "display: block");
						}
					}
					this.setAttribute("class","imz_collapse");
//					this.firstChild.nodeValue = "-";
				} else {					
					var children = this.parentNode.getElementsByTagName("div");					
					for(var i = 0; i < children.length; i++){					
						if(children.item(i).parentNode == this.parentNode){
							children.item(i).setAttribute("style", "display: none;");
						}
					}					
					this.setAttribute("class","imz_expand");
//					this.firstChild.nodeValue = "+";				
				}
			}
			menuChildren.item(i).insertBefore(expandNode, menuChildren.item(i).firstChild);
		}
		
	}
}
