// JavaScript Document

$(document).ready(function(){
	
	$("#rootmenu table").hover(function(event){
		
		$this = $(this); // save pointer to current DOM element
		
		// alert('Handler for .click() called.'); // testing...
		//$(".rootmenuitemselected").addClass('rootmenuitem'); // add unselcted class to all currently selected	
		//$(".rootmenuitemselected").removeClass('rootmenuitemselected');  // remove all red classes
		$this.not(".currentpage").addClass('rootmenuitemselected');  // mark clicked as selected
				
	},
	function(event){
		
		$this = $(this); // save pointer to current DOM element
		
		// alert('Handler for .click() called.'); // testing...
		//$(".rootmenuitemselected").addClass('rootmenuitem'); // add unselected class to all currently selected	
		//$(".rootmenuitemselected").removeClass('rootmenuitemselected');  // remove all red classes
		$this.not(".currentpage").removeClass('rootmenuitemselected');  // mark clicked as selected
				
	});
						
});

$(document).ready(function(){
		
			$("#navigation ul li ul").hide();
				$("#navigation ul li").data('vistoggle','hiding');   // mark all dropdowns as hidden
			
		
			$("body").click(function(event){
					
				$(".red").removeClass('red');  // remove all red classes
				$("#navigation ul li ul").hide(); // hide all visible dropdowns	
				$("#navigation ul li").data('vistoggle','hiding');  // mark all dropdowns as hidden
				
			});
		
			$("#navigation ul li").click(function(event){
				
				//event.preventDefault(); // this prevents the default click functionality - unfortunately is is passed down to descendants - don't use!!!
				
				event.stopPropagation(); // prevent the event from bubbling to ancestor elements ... prevents triggering of: $("body").click(function(event){
				
				$this = $(this); // save pointer to current DOM element
				
				$(":animated").stop(true, true); // stop animations
				
				$(".red").removeClass('red');  // remove all red classes
				
				$("#navigation ul li ul").hide(); // hide all dropdowns (note: we have not yet changed the vistoggles!
				
				if($($this).data('vistoggle') == 'hiding'){
					$($this).children("a").addClass('red'); // make this "a" red
					$($this).children("ul").show('slow').children("li").children("a").addClass('red'); // show the dropdown and make the a's red
					$("#navigation ul li").data('vistoggle','hiding');  // mark ***all*** dropdowns as hiding
					$($this).data('vistoggle','showing'); // mark ***this*** dropdown as showing
					}
				else {
					$(".red").removeClass('red');  // remove all red classes
					$("#navigation ul li ul").hide(); // hide all visible dropdowns	
					$("#navigation ul li").data('vistoggle','hiding');  // mark ***all*** dropdowns as hiding
					}
				
			});
							
		});