var menu_tmr;
var hide_delay = 500;
var cur_sub = null;
var cur_menu = null;

function ShowMenu(element, sub_menu){
	if(cur_sub != null && cur_sub != sub_menu){
		hideMenuNow();
	}	

	cur_menu = element;
	
	highLightElementOn(element);

	var position = $(element).position();
	
	cancelHide();
	cur_sub = document.getElementById(sub_menu);
	cur_sub.style.left = position.left + GetLeftAmendment() + 'px';		
	cur_sub.style.top = position.top + GetTopAmendment() + 'px';
	cur_sub.style.display="block";
}

function highLightElementOn(element)
{
    if (element.className != 'active') {
        element.style.background = '#a81e3d url(/img/template/bg_top_menu_a_hover.gif) no-repeat right bottom';
        element.style.color = '#fff';
    }
}

function highLightElementOff(element)
{
    if (element.className != 'active') {
        element.style.background = 'none';
        element.style.color = '#000';
    }
}

function GetTopAmendment(){
	if(navigator.appName.substring(0,2) == "Mi"){
    	//for ie
    	return +90;
	}
	else if(navigator.appName == 'Opera'){
		//for opera
		return +90;
	}
	else{
		//for other
		return +90;
	}
}
function GetLeftAmendment(){
	if(navigator.appName.substring(0,2) == "Mi"){
        if ($.browser.version == '6.0' || $.browser.version == '4.10') {
    		return 0;
        } else {
    		//for ie
    		return +20;        
        }
	}
	else if(navigator.appName == 'Opera'){
		//for opera
		return +20;
	}
	else{
		//for other
		return +20;
	}
}

function hideMenuNow()
{
    if (null === cur_sub || null === cur_menu) {
        return;
    }
    
    cur_sub.style.display = 'none';
    highLightElementOff(cur_menu);
    
    cur_sub = null;
    cur_menu = null;
}

function hideMenu(){menu_tmr =setTimeout("hideMenuNow()",hide_delay)}

function cancelHide(){
	clearTimeout(menu_tmr);
}

function GetAbsoluteTop(obj){
   var result = 0;
   while(obj.tagName != 'BODY'){
     result += obj.offsetTop;
     obj = obj.offsetParent;
   }
   
   return result;
}

function GetAbsoluteLeft(obj){
   var result = 0;
   while(obj.tagName != 'BODY'){
     result += obj.offsetLeft;
     obj = obj.offsetParent;
   }
   
   return result;
}
