﻿function getPos(e)
{
	var top 	= 0;
	var left 	= 0;
	if(e.offsetParent)
		while(1)
		{
		  top += e.offsetTop;
		  left += e.offsetLeft;
		  if(!e.offsetParent)
			break;
		  e = e.offsetParent;
		}
	else if(e.y && e.x)
	{
		top += e.y;
		left += e.x;
	}
	return {top:top, left:left};
}

function bindEvent(element, event, func, cancelBubble, detach)
{
	cancelBubble = cancelBubble ? true : false;
	if(document.documentElement.attachEvent)
	{
		event = "on" + event;
		if (detach)
			element.detachEvent( event, func);
		else
			element.attachEvent( event, func);
	}
	else
	{
		if (detach)
			element.removeEventListener(event, func, cancelBubble);
		else
			element.addEventListener(event, func, cancelBubble);
	}
}

function showDropDown(e)
{
	var href 	= e.href;			
	//href 		= href.substr(href.lastIndexOf('/')+1);
	
	var targetDropdownId;
	
	//alert(href);
//	if (href.search(/about-davao.htm/i) != -1)
	if (href.search("/about-davao.htm") != -1)
		targetDropdownId = 'fpAnimswapListFP6';
//	else if (href.search(/DCIPC\/index.htm/i) != -1)
    else if (href.search("/DCIPC\/index.htm") != -1)
		targetDropdownId = 'fpAnimswapListFP2';
//	else if (href.search(/cityguide.htm/i) != -1)
    else if (href.search("/cityguide.htm") != -1)
		targetDropdownId = 'fpAnimswapImgFP3';
	else
		throw 'Object not supported!';
	
	var menu = document.getElementById(targetDropdownId);
	
//	if (isHide)
//	{
//		window.lastDropdownTimeoutId = setTimeout(function(){menu.style.display = 'none';}, 500);
//	}
//	else
//	{			
		var pos = getPos(e);		
		menu.style.left		= pos.left + 'px';
		menu.style.top		= e.offsetHeight + pos.top + 'px';
		menu.style.display 	= 'block';
		
		var hidePopup = function()
						{
							window.lastDropdownTimeoutId = setTimeout(function(){menu.style.display = 'none';}, 1000);				
							bindEvent(e, 'mouseout', hidePopup, false, true);
						}
		
		bindEvent(e, 'mouseout', hidePopup);
//	}
}

function cancelTimeout(e)
{
	clearInterval(window.lastDropdownTimeoutId);
	e.style.display	='block';
	e.onmouseout	= 
		function()
		{
			window.lastDropdownTimeoutId = setTimeout(function(){e.style.display = 'none';}, 500);
		}
}

document.write('\
<style>\n\
	ul.dropdown\n\
	{\n\
		margin:0;\n\
		padding:5px;\n\
		list-style-type:none;\n\
		position:absolute;\n\
		display:none;\n\
		background-color:#8E8F70;\n\
		border:double 3px #535340;\n\
		z-index:100;\n\
	}\n\
	ul.dropdown a,ul.dropdown a:visited\n\
	{\n\
		color:#602618;\n\
		text-decoration:none;\n\
		font-size: 9px;\n\
		font-weight:bold;\n\
	}\n\
	ul.dropdown a:hover,ul.dropdown a:active\n\
	{\n\
		text-decoration:underline;\n\
		color:#D2DEB8;\n\
	}\n\
</style>\n\
<ul id="fpAnimswapListFP6" class="dropdown" onmouseover="cancelTimeout(this);">\n\
<li><a href="/about/index.htm">General Information</a></li>\n\
<li><a href="/theeconomy/overview.htm">The Economy</a></li>\n\
<li><a href="/doingbusiness/index.htm">Doing Business in Davao</a></li>\n\
<li><a href="/localgovernment/index.htm">The Local Government</a></li>\n\
</ul>\n\
<ul id="fpAnimswapListFP2" class="dropdown" onmouseover="cancelTimeout(this);">\n\
	<li><a href="/DCIPC/DCIPChistory.htm">History of DCIPC</a></li>\n\
	<li><a href="/DCIPC/DCIPCfunctions.htm">Legal Basis, Mandates, and Functions</a></li>\n\
	<li><a href="/DCIPC/People.aspx">People of the Organization</a></li>\n\
	<li><a href="/DCIPC/DCIPCqualification.htm">Qualifications of an Enterprise</a></li>\n\
</ul>\n\
<ul id="fpAnimswapImgFP3" class="dropdown" onmouseover="cancelTimeout(this);">\n\
	<li><a href="/Downloads.aspx?cid=10">Maps</a></li>\n\
	<li><a href="/localgovernment/holidays.htm">Special Public Holidays</a></li>\n\
	<li><a href="/localgovernment/cinemas.aspx">Cinemas</a></li>\n\
	<li><a href="/localgovernment/events.aspx">Events</a></li>\n\
	<li><a href="/localgovernment/performances.aspx">Shows and Performances</a></li>\n\
	<li><a href="/localgovernment/schedule.aspx?id=1">Flight Schedule</a></li>\n\
	<li><a href="/localgovernment/schedule.aspx?id=2">Ship Schedule</a></li>\n\
</ul>');
/*
document.write('\
<ul id="fpAnimswapListFP6" style="position:absolute; display:none; background-color: #FFF;z-index:100;" onmouseover="cancelTimeout(this);">\n\
<li><a href="/about/index.htm">General Information</a></li>\n\
<li><a href="/theeconomy/overview.htm">The Economy</a></li>\n\
<li><a href="/doingbusiness/index.htm">Doing Business in Davao</a></li>\n\
<li><a href="/localgovernment/index.htm">The Local Government</a></li>\n\
</ul>\n\
<ul id="fpAnimswapListFP2" style="position:absolute; display:none; background-color: #FFF;z-index:100;" onmouseover="cancelTimeout(this);">\n\
	<li><a href="/DCIPC/DCIPChistory.htm">History of DCIPC</a></li>\n\
	<li><a href="/DCIPC/DCIPCfunctions.htm">Legal Basis, Mandates, and Functions</a></li>\n\
	<li><a href="/DCIPC/People.aspx">People of the Organization</a></li>\n\
	<li><a href="/DCIPC/DCIPCqualification.htm">Qualifications of an Enterprise</a></li>\n\
</ul>\n\
<ul id="fpAnimswapImgFP3" style="position:absolute; display:none; background-color: #FFF;z-index:100;" onmouseover="cancelTimeout(this);">\n\
	<li><a href="/Downloads.aspx?cid=10">Maps</a></li>\n\
	<li><a href="/localgovernment/holidays.htm">Special Public Holidays</a></li>\n\
	<li><a href="/localgovernment/cinemas.aspx">Cinemas</a></li>\n\
	<li><a href="/localgovernment/events.aspx">Events</a></li>\n\
	<li><a href="/localgovernment/performances.aspx">Shows and Performances</a></li>\n\
	<li><a href="/localgovernment/schedule.aspx?id=1">Flight Schedule</a></li>\n\
	<li><a href="/localgovernment/schedule.aspx?id=2">Ship Schedule</a></li>\n\
</ul>');
*/