/**
*
*	simpleTooltip jQuery plugin, by Marius ILIE
*	visit http://dev.mariusilie.net for details
*
**/
(function($){ $.fn.simpletooltip = function(){
	return this.each(function() {
		var text = $(this).attr("title");
		$(this).attr("title", "");
		if(text != undefined) {
			$(this).hover(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
				if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
				else var tipWidth = $("#simpleTooltip").width()
				$("#simpleTooltip").width(tipWidth);
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			}, function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});
			$(this).mousemove(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				var tipWidth = $("#simpleTooltip").outerWidth(true);
				var tipHeight = $("#simpleTooltip").outerHeight(true);
				if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
				if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			});
		}
	});
}})(jQuery);



$(document).ready(function() { 
	
	$.get("rss.php", function(data){
		    $('div.widget-zocalo-orange-papers div.widget-content').html(data);
		});
	var hideDropdownTimer = null;
	var whoWeAre = $("div#who-we-are-nav", this);
	var womDoneRight =  $("div#wom-done-right-nav", this);
	var howWeHelp = $("div#how-we-help-nav", this);
	var contactUs = $("div#contact-us-nav", this);
	var zocaloNet = $("div#zocalonet-nav", this);

	var whoWeAreNav = $("li#who-we-are", this);
	var womDoneRightNav = $("li#wom-done-right", this);
	var howWeHelpNav = $("li#how-we-help", this);
	var contactUsNav = $("li#contact-us", this);
	var zocaloNetNav = $("li#zocalo-net", this);
	
	
	whoWeAre.hide();
	womDoneRight.hide();
	howWeHelp.hide();
	contactUs.hide();
	zocaloNet.hide();
	
	//$(".essential").simpletooltip();
	$([zocaloNet[0], zocaloNetNav[0]]).hover( function() {
		if (hideDropdownTimer)
	    	clearTimeout(hideDropdownTimer);
			womDoneRight.hide();
			howWeHelp.hide();
			contactUs.hide();
	      	whoWeAre.hide();
			zocaloNet.show();
			$('li a').removeClass('selected');
			$('li#zocalo-net a').addClass('selected');
	},
		function() {
		if (hideDropdownTimer)
        	clearTimeout(hideDropdownTimer);

      		hideDropdownTimer = setTimeout(function() {
				zocaloNet.hide();
				$('li#zocalo-net a').removeClass('selected');
			if (intpage) {
				shownav(intpage);
			}
	}, 300)
	
	});


	$([whoWeAre[0], whoWeAreNav[0]]).hover( function() {
		if (hideDropdownTimer)
	    	clearTimeout(hideDropdownTimer);
			$('li#home a').removeClass('selected');
			$('li#how-we-help a').removeClass('selected');
			$('li#wom-done-right a').removeClass('selected');
			$('li#contact-us a').removeClass('selected');
			$('li#zocalo-net a').removeClass('selected');
			$('li#who-we-are a').addClass('selected');
			womDoneRight.hide();
			howWeHelp.hide();
			contactUs.hide();
			zocaloNet.hide();
	      	whoWeAre.show();
	    },
	    function() {
	    	if (hideDropdownTimer)
	        	clearTimeout(hideDropdownTimer);

	      	hideDropdownTimer = setTimeout(function() {
	        whoWeAre.hide();
			$('li#who-we-are a').removeClass('selected');
			if (intpage) {
				shownav(intpage);
			}
		}, 300)
	
	});
	
	$([womDoneRight[0], womDoneRightNav[0]]).hover( function() {
		if (hideDropdownTimer)
	    	clearTimeout(hideDropdownTimer);
			$('li#home a').removeClass('selected');
			$('li#how-we-help a').removeClass('selected');
			$('li#who-we-are a').removeClass('selected');
			$('li#contact-us a').removeClass('selected');
			$('li#zocalo-net a').removeClass('selected');
			$('li#wom-done-right a').addClass('selected');
			howWeHelp.hide();
			contactUs.hide();
	      	whoWeAre.hide();
			zocaloNet.hide();
			womDoneRight.show();
	    },
	    function() {
	    	if (hideDropdownTimer)
	        	clearTimeout(hideDropdownTimer);

	      	hideDropdownTimer = setTimeout(function() {
	        womDoneRight.hide();
			$('li#wom-done-right a').removeClass('selected');
			if (intpage) {
				shownav(intpage);
			}
		}, 300)
	
	});
	
	$([howWeHelp[0], howWeHelpNav[0]]).hover( function() {
		if (hideDropdownTimer)
	    	clearTimeout(hideDropdownTimer);
			$('li#home a').removeClass('selected');
			$('li#wom-done-right a').removeClass('selected');
			$('li#who-we-are a').removeClass('selected');
			$('li#zocalo-net a').removeClass('selected');
			$('li#contact-us a').removeClass('selected');
			$('li#how-we-help a').addClass('selected');
			contactUs.hide();
	      	whoWeAre.hide();
			womDoneRight.hide();
			zocaloNet.hide();
			howWeHelp.show();
	    },
	    function() {
	    	if (hideDropdownTimer)
	        	clearTimeout(hideDropdownTimer);

	      	hideDropdownTimer = setTimeout(function() {
	        howWeHelp.hide();
			$('li#how-we-help a').removeClass('selected');
			if (intpage) {
				shownav(intpage);
			}
		}, 300)
	
	});
	
	$([contactUs[0], contactUsNav[0]]).hover( function() {
		if (hideDropdownTimer)
	    	clearTimeout(hideDropdownTimer);
			$('li#home a').removeClass('selected');
			$('li#wom-done-right a').removeClass('selected');
			$('li#how-we-help a').removeClass('selected');
			$('li#who-we-are a').removeClass('selected');
			$('li#zocalo-net a').removeClass('selected');
			$('li#contact-us a').addClass('selected');		
			howWeHelp.hide();
	      	whoWeAre.hide();
			womDoneRight.hide();
			zocaloNet.hide();
			contactUs.show();
	    },
	    function() {
	    	if (hideDropdownTimer)
	        	clearTimeout(hideDropdownTimer);

	      	hideDropdownTimer = setTimeout(function() {
	        contactUs.hide();
			$('li#contact-us a').removeClass('selected');
			if (intpage) {
				shownav(intpage);
			}
		}, 300)
	
	});
	
	
	var path = window.location.pathname;
	var page = path.substring(path.lastIndexOf('/') + 1);
	var path = 'http://www.blueyepreview.net/zocalo/';
	$('.navbar ul li a[href='+ path + page +']').addClass('selected');
	var intpage = null;
	switch (page) {
		
		case 'about.html':
		case 'leadership.html':
		case 'code-of-ethics.html':
		case 'news.html':
        case 'orange-papers.html':
		case 'zocalos.html':
			$('li#who-we-are a').addClass('selected');
	      	whoWeAre.show();
			intpage = 'whoWeAre';
		break;
		case 'power-of-wom.html':
		case 'influencer-ecosystem.html':
		case 'eight-essentials.html':
		
			$('li#wom-done-right a').addClass('selected');
			womDoneRight.show();
			intpage = 'womDoneRight';
		break;
		case 'when-should-you-implement-wom.html':
		case 'approach-capabilities.html':
		case 'measurement-and-roi.html':
			$('li#how-we-help a').addClass('selected');
			howWeHelp.show();
			intpage = 'howWeHelp';
		break;
		case 'contact.html':
		case 'careers.html':
			contactUs.show();
			$('li#contact-us a').addClass('selected');
			intpage = 'contactUs';
		break;
		default:
		break;
	}
	
	
	
	});

function shownav(intpage) {
	switch (intpage) {
		case 'whoWeAre':
			$('li#who-we-are a').addClass('selected');
	      	document.getElementById('who-we-are-nav').style.display = 'block';
		break;
		case 'womDoneRight':
			$('li#wom-done-right a').addClass('selected');
			document.getElementById('wom-done-right-nav').style.display = 'block';
		break;
		case 'howWeHelp':
			$('li#how-we-help a').addClass('selected');
			document.getElementById('how-we-help-nav').style.display = 'block';
		break;
		case 'contactUs':
			$('li#contact-us a').addClass('selected');
			document.getElementById('contact-us-nav').style.display = 'block';
		break;
	}
}

function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
		e.style.display = 'block';
}
