/*
 *  createPopupMenu creates the popup menu using two separate elements.
 *    trigger_id: the ID of the element that hides/shows the popup.
 *    menu_id: the ID of the popup menu itself.
 *
 *   Be sure to include this scripting after all menus have been defined in the page layout.
 */
var timer_identifiers={}

// use this function to create a popup menu out of two divs
// the trigger, and the menu to be displayed 
function createPopupMenu (trigger_id, menu_id)
{
	if (document.getElementById(trigger_id) == null) return false;
	timer_identifiers[menu_id] = 0;
	document.getElementById(menu_id).style.display='none';
	document.getElementById(trigger_id).onmouseover = function () { showMenu(menu_id) }
	document.getElementById(trigger_id).onmouseout  = function () { hideMenu(menu_id) }	
	document.getElementById(menu_id).onmouseover = function () { clearTimeout(timer_identifiers[menu_id]) }
	document.getElementById(menu_id).onmouseout  = function () { hideMenu(menu_id) }	

}
function hideMenu (menu_id)
{
	timer_identifiers[menu_id] = setTimeout("document.getElementById('" + menu_id + "').style.display = 'none'", 100);
}


function showMenu (menu_id)
{
	clearTimeout(timer_identifiers[menu_id]); 
	timer_identifiers[menu_id] = 0; 
	document.getElementById(menu_id).style.display = 'block';
}

// similar to the PHP function of the same name.
function basename(spath)
{
	var pagename = spath.substring(spath.lastIndexOf('/') + 1);
	var q = pagename.lastIndexOf('?');
	if (q != -1)
	{
		pagename = pagename.substring(0, q);
	}
	
	if (pagename=='' || pagename=='index.php')
	{
		pagename='index.php';
	}

	else
	{
		pagename = pagename.substring(0, pagename.lastIndexOf('.'));
	}
	return pagename;
}

var pagename = basename(location.pathname);


// applies the CSS class "active" to the hyperlink corresponding to the current page.
// in other words, it hilites the current page in the site menu.
for (var i=0; i< document.links.length; i++)
{
	if (pagename == basename(document.links[i].href) 
	&& document.links[i].parentNode.id != 'link_newsletter' 
	&& document.links[i].parentNode.id != 'logo'
	&& document.links[i].parentNode.id != 'link_activities'
	&& document.links[i].parentNode.id != 'link_seo'
	&& document.links[i].parentNode.id != 'link_thankyous'
	&& document.links[i].parentNode.id != 'link_handbooks'	
	) 
	{				
		document.links[i].className = 'active';
		document.links[i].removeAttribute('href');			
		i = 10000;
	}	
}

// admin section
createPopupMenu ('link_newsletter', 'newletsub');
createPopupMenu ('link_activities', 'actsub');
createPopupMenu ('link_seo', 'seoeditor');	
createPopupMenu ('link_aboutus', 'aboutusmenu');
createPopupMenu ('link_thankyous', 'thankyousub');

// regular site
createPopupMenu ('link_resorts', 'resortsmenu');
createPopupMenu ('link_handbooks', 'handbooksub');

