
var is_out=true;
var is_on;
var menuid;

function get_offset(el,type)
{
    var i = 0;
		var nde = el;
    while (nde != document.body)
    {
        try { 
    			i += (type=='left') ? nde.offsetLeft:nde.offsetTop;
					nde = nde.offsetParent;
        } catch (ex) {
        	break;
        }
    }
    return i;
}

// dd-menu
function menuInitialize()
{
	$(menuid+":visible").hide();	
}

function initMenu(){
	$("li.tab")
	.hover(function(){		
		var pop_text = $(this).get(0); //$(this).find('li').get(0);
		var pop_left = get_offset(pop_text,'left');
		var pop_top	 = get_offset(pop_text,'top');		
		lname = $(this).find('a').get(0).rel;
		if(lname=="contactmenu"){
			pop_left	-= 45;
		}
		if(lname){
			menuid	= "#"+lname;
			$(menuid)
				.css({
					"top": (pop_top+30) +"px",
					"left":(pop_left) +"px"
				})
				.show()
				.hover(function(){
					$(this).show();
				},function(){
					$(this).hide();
				});
		}	
	},function(){
		menuInitialize();
	});
	
	$("li.tab-selected")
	.hover(function(){		
		var pop_text = $(this).get(0); //$(this).find('li').get(0);
		var pop_left = get_offset(pop_text,'left');
		var pop_top	 = get_offset(pop_text,'top');
		lname = $(this).find('a').get(0).rel;
		if(lname){
			menuid	= "#"+lname;
			$(menuid)
				.css({
					"top": (pop_top+30) +"px",
					"left":(pop_left) +"px"
				})
				.show()
				.hover(function(){
					$(this).show();
				},function(){
					$(this).hide();
				});
		}	
	},function(){
		menuInitialize();
	});
}

$(document).ready(function()
{
	initMenu();
})