var activeMenu = null;
var activeButton = null;
var menuTimer = 0;

function getRealLeft(el) {
    xPos = 0;
    if( el.offsetParent ) {
	    do {
	    	xPos += el.offsetLeft;    	
    	} while (el = el.offsetParent ) ;
    }
    return xPos;
}    

function getRealTop(el) {
    yPos = 0;    
    if( el.offsetParent ) {
	    do {	    	
	    	yPos += el.offsetTop;    	 
    	} while (el = el.offsetParent ) ;
    }      
    return yPos;
}

//////////////////////////
// Show top menu item
function onTopButton(button){
	clearTimeout(menuTimer);
	if( activeButton != null )
		 hideMenu();
	activeButton = button.id;
	activeMenu = document.getElementById(activeButton.replace(/top/,"rollover"));
	//if menu here - show it
	if(activeMenu != null){		
		activeMenu.style.left = getRealLeft(button) + "px";
		activeMenu.style.top = getRealTop(button) + 28  + "px";
		activeMenu.style.display="block";
	}
}

function offTopButton(){
	menuTimer = setTimeout("hideMenu()", 1500);
}

function hideMenu(){
	activeButton = null;
	if(activeMenu != null) activeMenu.style.display = "none";
	activeMenu = null;
}

///////////////////////////////
// Menu items functions
function onTopMenuItem(){
	clearTimeout(menuTimer);
}

function offTopMenuItem(){
	menuTimer = setTimeout("hideMenu()", 2000);
}

function gotoTopMenuItem(url){
	document.location = url;
}

//////////////////////////////
// Refine Extended Menus

var current_refine_menu = null;
var refineTimer;

function refine_view_more( menu ) { 	
	clearTimeout( refineTimer );
	if( current_refine_menu != null ) {
		refine_view_hide();
	}
	current_refine_menu = menu;
	rf = document.getElementById( menu );
	rfbox = document.getElementById( menu.replace( /refine/, "refine_full" ) );
	rfbox.style.left = getRealLeft(rf) + "px";
	rfbox.style.top = getRealTop(rf) + 26 +  "px";
	rfbox.style.display = "block";
    //expandMenu(rfbox);
}

function refine_view_less( ) { 
	refineTimer = setTimeout("refine_view_hide()", 1500);
}

function refine_view_hide( ) {
	menu = current_refine_menu;
	menu = menu.replace( /refine/, "refine_full" );
	menu = document.getElementById( menu );
	menu.style.display = "none";
	current_refine_menu = null;	
}

function refine_item_on() {
	clearTimeout( refineTimer );
}

function refine_item_off() { 
	refineTimer = setTimeout("refine_view_hide()", 1500);
}

///////////////////////////////
// Video Category Menu

