// Add listener to create a var when window is fully loaded
var window_init = false ;
var lockHide = false;
var lockShow = false;
Event.observe(window, 'load', function() { window_init = true ; }, false);

// OnMouseOverBtn
function _onMouseOver_btn(obj, ulist, ref_control) {
	// Transform Button to selected
	_dispMenu(obj, ulist, ref_control) ;
}

// OnMouseOutBtn
function _onMouseOut_btn(obj, ulist, ref_control) {
	// Transform Button to selected
	_hideMenu(obj, ulist, ref_control) ;
}

// Close all expanded submenus
function _do_hide_subMenus(obj) {
	if ( obj == null ) {
		lockHide = true;
		setTimeout("_do_hide_subMenusAll()", 300) ;	
		return true ;
	}
	var ullist=getElementsByClass(document,'submenu_expanded','*');
	for (var i=0; i<ullist.length; i++) {
		ullist[i].style.display = 'none' ;  //hide all tabs
	}	
	var ullist=getElementsByClass(document,'menu_btn_expand_selected','*');
	for (var i=0; i<ullist.length; i++) {
		if ( obj != null ) if ( obj.id != ullist[i].id ) 		ullist[i].className='menu_btn_expand' ;
	}			
}

// Close all submenus
function _do_hide_subMenusAll() {
	if ( lockHide == true ) {
		var ullist=getElementsByClass(document,'submenu_expanded','*');
		for (var i=0; i<ullist.length; i++) {
			ullist[i].style.display = 'none' ;  //hide all tabs
		}	
		var ullist=getElementsByClass(document,'menu_btn_expand_selected','*');
		for (var i=0; i<ullist.length; i++) {
			ullist[i].className='menu_btn_expand' ;
		}		
		
		// Reinit lock
		lockShow = false ;
	}
}

// Disp menu 
function _dispMenu(obj, ulist, ref_control) {
		// Flag to protect bug
		lockHide = false;
		if ( lockShow != obj ) {
			// Hide all menus
			_do_hide_subMenus(obj);
			// Transform Button to selected
			if (obj.childNodes[1].className == "menu_btn_expand"){
				obj.childNodes[1].className='menu_btn_expand_selected' ;
				// PLace menu
				$(ulist).style.left = ($(ref_control).offsetLeft - 10) + 'px';
				// Show menu
				$(ulist).style.display = 'block';			
			}
		}
		// Set a flag to avoid FireFox 1.5 bug
		lockShow = obj;		
}

// Hide menu 
function _hideMenu(obj, ulist, ref_control) {
	_do_hide_subMenus();
//	if ( obj.className == 'menu_btn_expand_selected' ) {	
		// Transform Button to not selected
//		obj.className='menu_btn_expand' ;
		if (obj.childNodes[1].className == "menu_btn_expand_selected"){
			obj.childNodes[1].className='menu_btn_expand' ;
		}
		// PLace menu
		$(ulist).style.left = ($(ref_control).offsetLeft - 10) + 'px';	
		// Hide menu
		$(ulist).style.display = 'none';	
//	}	
}