/*======================================================================*\
|| #################################################################### ||
|| #  				  Imperial Bulletin Board v1.x                    # ||
|| # ---------------------------------------------------------------- # ||
|| #  For license, version and changelog questions or concerns,       # ||
|| #  navigate to the docs/ folder or visit the forums at the		  # ||
|| #  website, http://www.imperialbb.com/forums. with your questions. # ||
|| # ---------------------------------------------------------------- # ||
|| # Name: js_ddmenu.js                                               # ||
|| # ---------------------------------------------------------------- # ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

var current_menu = "";

function openMenu(element)
{
	var id 	  = element.id;
	var popup = $ ( id+"-popup" );
	if ( current_menu == id )
	{
		closeMenu ( current_menu );
		return false;
	}
	else if ( current_menu )
	{
		closeMenu ( current_menu );
	}
	elemOffsetTop  = IBB.general.offset_top(element);
	elemOffsetLeft = IBB.general.offset_left(element);
	popup.style.position = "absolute";
	popup.style.zIndex = 10;
	popup.style.top = (elemOffsetTop+element.offsetHeight-1)+"px";
	popup.style.left = (elemOffsetLeft)+"px";
	if(popup.style.width)
	{
		menuWidth = parseInt(popup.style.width);
	}
	else
	{
		menuWidth = popup.offsetWidth;
	}
	if(elemOffsetLeft+menuWidth >= document.body.clientWidth)
	{
		popup.style.left = (elemOffsetLeft+element.offsetWidth-menuWidth-2)+"px";
		if( IBB.is_ie )
		{
			popup.style.left = (parseInt(popup.style.left)-6)+"px";
		}
	}
	IBB.event.add_event(popup, "mouseover", handleOverOut);
	IBB.event.add_event(popup, "mouseout", handleOverOut);
	document.onclick = handleOverOut;
	popup.style.display = "block";
	current_menu = id;
	return false;
}

function closeMenu(id)
{
	if(!id && current_menu)
	{
		id = current_menu;
	}
	var element = $ ( id );
	var popup 	= $ ( id+"-popup" );
	popup.style.display = "none";
	IBB.event.remove_event(popup, "mouseout", handleOverOut);
	IBB.event.remove_event(popup, "mouseover", handleOverOut);
	document.onclick = "";
	current_menu = "";
}

function handleOverOut(event)
{
	if(typeof(event) != "undefined" && event.type == "mouseover")
	{
		document.onclick = "";
	}
	else
	{
		document.onclick = handleClick;
	}
}

function handleClick(element)
{
	closeMenu("");
}

function mouse_over ( ) 
{
	var evt = IBB.general.cancel_bubble_all ( window.event );
	if ( evt.srcElement ) 
	{
		evt.srcElement.style.cursor = 'hand';
	} 
	else if ( evt.target ) 
	{
		evt.target.style.cursor = 'pointer';
	}
}

function mouse_hover ( cell, hov, rev ) 
{
	hov = ( ( !hov ) ? false : hov );
	rev = ( ( !rev ) ? false : rev );
	if ( hov == true ) 
	{
		cell.className = ( ( rev == true ) ? 'ddmenu_cell' : 'ddmenu_cell_over' );
		cell.style.cursor = IBB.cursor;
	} 
	else 
	{
		cell.className = ( ( rev == true ) ? 'ddmenu_cell_over' : 'ddmenu_cell' );
	}
}

/*======================================================================*\
|| #################################################################### ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| #################################################################### ||
\*======================================================================*/