var activeMenu = null;
var activeButton = null;
var menuTimer = 0;

function getRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while(tempEl != null){
        yPos += tempEl.offsetTop;
        tempEl = tempEl.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) + 26 + "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

function refine_view_more( menu ) { 

	rf = document.getElementById( menu );
	rfbox = document.getElementById( menu.replace( /refine/, "refine_full" ) );
	rfbox.style.left = getRealLeft(rf) + "px";
	rfbox.style.top = getRealTop(rf) + 2 +  "px";
	rfbox.style.display = "block";
    //expandMenu(rfbox);
}

function expandMenu(box){
	refinebox = box.clientHeight;
	refinebox = document.getElementById(box);
	expandbox = document.getElementById("bc_expand");
	expandbox.style.height = refinebox + "px";
}

function refine_view_less( menu ) { 
	menu = document.getElementById( menu );
	menu.style.display = "none";
}
