var jQueryPopTimeout = false;
var POP_NAV_OPENER = false;
$.fn.jqueryPop = function() {
	this.mouseover(function(e){
		if(POP_NAV_OPENER!=false && POP_NAV_OPENER.id==this.id){return false;}
		var popNav = getPopNavigation(this.id);
		if(popNav.length>0){
			window.clearTimeout(jQueryPopTimeout);
			$("#jQueryPopNav").remove();
			POP_NAV_OPENER = this;
			var html = '<div id="jQueryPopNav"><ul>';
			for(var i=0;i<popNav.length;i++){html += '<li><a href="'+popNav[i][0]+'">'+popNav[i][1]+'</a></li>';}
			html += '</ul></div>';
			$("body").append(html);
			var pos = function(){var obj = POP_NAV_OPENER;var curleft = curtop = 0;
				if (obj.offsetParent){curleft = obj.offsetLeft;	curtop = obj.offsetTop;
					while (obj = obj.offsetParent){ curleft += obj.offsetLeft;	curtop += obj.offsetTop}}
					return [curleft,curtop];};
			$("#jQueryPopNav").css({position:"absolute",left:pos()[0]+"px",top:pos()[1]+POP_NAV_OPENER.offsetHeight+"px"});
			$("#jQueryPopNav li").hover(
				function(){$(this).addClass("jQueryPopNavHover");},
				function(){$(this).removeClass("jQueryPopNavHover");});
			$("#jQueryPopNav li").bind("click",
				function(){var href = $(this).children("a").attr("href");window.location = href;});
			$("#jQueryPopNav").fadeIn("fast",function(){jQueryPopTimeout = window.setTimeout(function(){$("body").bind("mouseover",jQueryPopNavClose);},1000);});
			function jQueryPopNavClose(e){var l = $(e.target).parents("#jQueryPopNav").length;
				if(l==0 && e.target.parentNode.id!=POP_NAV_OPENER.id && e.target.id!=POP_NAV_OPENER.id && e.target.id!='jQueryPopNav'){
					$("#jQueryPopNav").fadeOut("fast",function(){$("#jQueryPopNav").remove();
						$("body").unbind("mouseover",jQueryPopNavClose);window.clearTimeout(jQueryPopTimeout);
						POP_NAV_OPENER = false;});}}
		}
	});
};

/// SET UP POP MENU'S HERE RELATED TO THE ID OF THE ELEMENT
function getPopNavigation(id){
	popNav = new Array();
	switch(id){
		/// CASE = THE id OF THE ELEMENT AND THE POPNAV ARRAY TO ASSOCIATE IT TO.
		case "navVisit":
		//	popNav[0] = new Array('url', 'Text to Display');
			popNav[0] = new Array('short_video.html','VIDEO SHORT');
			popNav[1] = new Array('visit.html','VISIT OAKLAND');
			popNav[2] = new Array('directionsMap.html','DIRECTIONS &amp; MAP');
			popNav[3] = new Array('calendar.html','CALENDAR OF EVENTS');
			popNav[4] = new Array('guidedTours.html','GUIDED WALKING TOURS');
			popNav[5] = new Array('museumShop.html','MUSEUM SHOP');
			popNav[6] = new Array('twilightTours.html','TWILIGHT TOURS');
			popNav[7] = new Array('specialEvents.html','SPECIAL EVENTS');			
			popNav[8] = new Array('speakers.html','SPEAKERS BUREAU');
			popNav[9] = new Array('slideshow.html','PHOTO GALLERY');
			//popNav[6] = new Array('sundayPark.html','SUNDAY IN THE PARK');
			//popNav[7] = new Array('capturingHalloween.html','CAPTURING THE HALLOWEEN SPIRIT');
			//popNav[2] = new Array('#','Museum Shop');
		break;
		case "navAbout":
			popNav[0] = new Array('about.html','ABOUT OAKLAND');
			popNav[1] = new Array('history.html','HISTORY');
			popNav[2] = new Array('layout.html','LAYOUT');
			popNav[3] = new Array('notableResidents.html','NOTABLE RESIDENTS');			
			popNav[4] = new Array('burialRecords.html','BURIAL RECORDS');
			popNav[5] = new Array('press.html','PRESS &amp; NEWS');
			popNav[6] = new Array('mission_vision.html','MISSION AND VISION');
		break;
		case "navRestoration":
			popNav[0] = new Array('restoration.html','RESTORATION AT OAKLAND');
		break;
		case "navParticipate":
			popNav[0] = new Array('volunteer.html','TOURS, MUSEUM SHOP &amp; EVENTS');
			popNav[1] = new Array('volunteer_second_saturdays.html','2ND SATURDAYS PROJECT');
		break;
		case "navSupport":
			popNav[0] = new Array('membership.html','BECOME A FOUNDATION MEMBER');
		break;
		case "navContact":
			popNav[0] = new Array('faqs.html','FREQUENTLY ASKED QUESTIONS');
		break;
		default:
		//	popNav[0] = new Array('url', 'Text to Display');
		break;
	}
	return popNav;
}

