/*

pirean.menus.js
Created prior to 01.11.2010

Description:
	Controls the top navigation menu dropdown. Any changes to the top level navigation will effect this menu.

Requirements:
	jQuery

Changelog:
	2011.02.02 - Started commenting/documenting external javascript files by Ben Leveritt (BSL)
	2010.11.01 - Created by Simon Hagger (SH)
	
*/

var menuOption = null;
var targetPopover = null;
var currentPopover = null;
var isOver = false;	

function checkHover() {
	if (!isOver && currentPopover!=null) {
		currentPopover.fadeOut('slow');
		//menuOption.switchClass('tabOn','noClass',500);
		menuOption.removeClass('tabOn').addClass('noClass');
		currentPopover = null;
		menuOption = null;
		targetPopover = null;
	} 
};

function addMouseEffect(theTrigger,theMenu) {
	theTrigger.hover(
		function() {
			if ($(window).width() > 480){
				if (menuOption != null && menuOption != theTrigger) {
					menuOption.removeClass('tabOn').addClass('noClass');
				}
				targetPopover = theMenu;
				if (currentPopover != null && currentPopover != targetPopover) {
					if(currentPopover.is(':visible') ) {
						currentPopover.fadeOut('fast');
					}
				}
				if (targetPopover.is(':visible') ) {
					// it's visible, do nothing
				} else {
					if(currentPopover!=null) {
						targetPopover.fadeIn('fast');
					} else {
						targetPopover.fadeIn('slow');
					}
				}
				menuOption = theTrigger;
				menuOption.removeClass('noClass').addClass('tabOn');
				currentPopover = targetPopover;
				lastMenu = theTrigger;
				isOver = true;
			}
		},
		function() {w
			isOver = false;
			setTimeout("checkHover()",	500);
		});

}; //addMouseEffect

function addMenuEffect(theMenu) {
	theMenu.hover(
		function() {
			isOver = true;
		},
		function() {
			isOver = false;
			setTimeout("checkHover()",	500);
		});

}; //addMenuEffect

$(function() {
			
	// Name each of the top nav items for the mouseover menu
	$("div#topNavigation ul#nav").find("li").eq(0).attr("id","menuAboutPirean").find("a").addClass('noClass');
	$("div#topNavigation ul#nav").find("li").eq(1).attr("id","menuConsulting").find("a").addClass('noClass');
	$("div#topNavigation ul#nav").find("li").eq(2).attr("id","menuTechnology").find("a").addClass('noClass');
	$("div#topNavigation ul#nav").find("li").eq(3).attr("id","menuOutsourcing").find("a").addClass('noClass');
	$("div#topNavigation ul#nav").find("li").eq(4).attr("id","menuIndustryInsight").find("a").addClass('noClass');

	addMouseEffect($('#menuAboutPirean a'),$('#dropdownAboutPirean'));
	addMenuEffect($('#dropdownAboutPirean'));
	addMouseEffect($('#menuConsulting a'),$('#dropdownConsulting'));
	addMenuEffect($('#dropdownConsulting'));
	addMouseEffect($('#menuTechnology a'),$('#dropdownTechnology'));
	addMenuEffect($('#dropdownTechnology'));
	addMouseEffect($('#menuOutsourcing a'),$('#dropdownOutsourcing'));
	addMenuEffect($('#dropdownOutsourcing'));
	addMouseEffect($('#menuIndustryInsight a'),$('#dropdownIndustryInsight'));
	addMenuEffect($('#dropdownIndustryInsight'));
});

/*function displayModal(modal){
	modal.show();
	displacement = modal.position().left - modal.offset().left;
	modal.css('left', displacement + $(window).width()/2);
	return true;
}*/
