/* Code for the navigation bar only

By Chris Venturini - 9/29/10

*/


$(document).ready(function(){
	$('.VerNav').hide();
	
	// Mouse Enters the the title bar
    $('.HorNav').mouseenter(function(){
			var HorEl = $(this).attr('id');
			var VerEl = ""
			
			// We only want the link element 
			if(HorEl.indexOf("Hor") > 0){
				
				idtype = HorEl.replace('Hor', '');		
				VerEl = "#" + HorEl.replace('Hor', 'Ver');
				
				
				//  slides in all other visiable eliments
				// 		if the eliment is already visible, we don't want to hav it slide in
				if('#' + $('ul.VerNav:visible').attr('id') != VerEl){
					$('ul.VerNav:visible').slideUp('300');
					$(VerEl).slideDown('300');
					
				} else{
					$(VerEl).stop(true,true).show();
				};
				
				$(this).ChgHor(idtype, 'T');
			
			}
		}
		
   	);
	
	// Mouse Leaves the the title bar
	$('.HorNav').mouseleave(function(){
			var HorEl = $(this).attr('id');
			
			
			if(HorEl.indexOf("Hor") > 0){
				
				idtype = HorEl.replace('Hor', '');		
				
				//Calls the ChgHor Function Below
				$(this).ChgHor(idtype, 'F');
				
				$('ul.VerNav:visible').slideUp('300');
			
			}
			
	});
		
	$('ul.VerNav').mouseleave(function(){
			var VerEl = $(this).attr('id');
			var HorEl = "";
			var idtype = ""
			
			
			idtype = VerEl.replace('Ver', '');
			VerEl = '#' + VerEl
			
			//Calls the ChgHor Function Below
			$(this).ChgHor(idtype, 'F');
			
			$(VerEl).slideUp('300');
			
	});
	$('ul.VerNav').mouseenter(function(){
			var VerEl = $(this).attr('id');
			
			var idtype = ""
			
			idtype = VerEl.replace('Ver', '');
			
			/*If the title bar is left it closes the menu, except if the mouse 
			Has entered it */
            $(this).stop(true, true).show();
			
			//Calls the ChgHor Function Below
			$(this).ChgHor(idtype, 'T');
	
	});
	/*The ChgHor Function
	
	It adjusts the background of the title bar elimiate to give the highlight
	
	*/
	jQuery.fn.ChgHor = function( id, boolon ) {
			var type = id;
			var x = '';
			var y = '';
			var HorEl = '#' + id + 'Hor';
			
					
			if(boolon == 'T'){
				y = ' -35px'
			}
			else{
				y = ' 0'
			};
			
			
			switch(type)
			{
				case "Equip": x = "-153px";
					break;
				case "Locat": x = "-288px";
					break;
				case "Cust": x = "-417px";
					break;
				case "Proj": x = "-555px";
					break;
				case "Sales": x = "-761px";
					break;
				case "About": x = "-901px";
					break;
				default: x = "-0"
			}
			
			$(HorEl + " a.HorNav").css("background-position", x + y);
	
		}
 })
