/* Activate dynamic menu */
/* Requires prototype 1.6 and dom.js */
menu_id = 'menu';

function activateMenu() {
	
	var menu = $(menu_id);

	for(i = 0; i < menu.childNodes.length; i++) {
		
		if(menu.childNodes[i].tagName == 'LI') {

			var option = menu.childNodes[i];
			Element.extend(option);

			var link = option.firstDescendant();
			var submenu = link.next();

			if(submenu) {
			
				//Hide submenu
				hide(submenu);
				
				//Show on mouseover
				submenu.onmouseover = function() {
					show(this)
					link = this.previous();
					link.style.backgroundImage = link.getStyle('backgroundImage').replace('_off', '_on');
				}
				
				submenu.onmouseout = function() {
					hide(this);
					link = this.previous();
					link.style.backgroundImage = link.getStyle('backgroundImage').replace('_on', '_off');
				}
				
				link.onmouseover = function () {
					show(this.next());
					Element.extend(this);
					this.style.backgroundImage = this.getStyle('backgroundImage').replace('_off', '_on');
				}
				
				link.onmouseout = function () {
					hide(this.next());
					Element.extend(this);
					this.style.backgroundImage = this.getStyle('backgroundImage').replace('_on', '_off');
				}
			
			}
		}
		
	}
	
}

function show(el) {
	if(el)
		el.style.display = 'block';
}

function hide(el) {
	if(el)
		el.style.display = 'none';
}

Event.observe(window, 'load', activateMenu);