﻿/// <reference path="../jquery/jquery-1.5.2-vsdoc.js"/>

$(document).ready(function() {
	setTimeout(function() {
		/*
		Extend the left menu div to the bottom of the page
		*/
		var bottom = $('#body').offset().top + $('#body').height();
		$('#menuStrut').width(1).height(bottom + 7 - $('#menuStrut').offset().top);
		/*
		For the home page, make the motto section the same height as the picture
		*/
		$('#teaser').height($('#crossRoad').height());
		setMenuEvents();
	}, 100);
});

function setMenuEvents() {
	$('.parentMenu').hover(
	//Enter
		function(ev) {
			if (!$(this).hasClass("selected")) {	//No cascade for selected menu item
				/*
				Hide the popup menu if it is showing
				*/
				$('#popMenu').css('visibility', 'hidden');
				/*
				Figure out what child menu to show
				*/
				var childId = $(this).attr('id');
				var pos = $(this).offset();
				if (theMenuHooks[childId]) {
					var myParent = $(this);
					/*
					Show it
					*/
					$('#popMenu').
					html(theMenuHooks[childId].replace(/&amp;#39;/g, "&#39;")).
					css({
						'visibility': 'visible',
						'top': pos.top,
						'left': pos.left + $(this).width() - 10
					}).fadeIn("slow")
					.mouseenter(function() {
						/*
							Mouse over the popup menu, clear timeout that will hide this menu.
						*/
						clearTimeout($(this).data('ToID'));
					}).mouseleave(function() {
						$(this).css('visibility', 'hidden');
					})
				}
			}
		},
	//Out
		function(ev) {
			/*
				Hide the popup menu if it is showing and if the mouse is not over it.
			*/
			var timeOutID = setTimeout(function() {
				$('#popMenu').fadeOut('slow').css('visibility', 'hidden');
			}, 200);
			$('#popMenu').data('ToID', timeOutID);
		});

	$('#backBody').mouseenter(null, function() {
		$('#popMenu').css('visibility', 'hidden');
	});
}


