// Navigation System
$(document).ready(function(){
	// Hide all Menu Sub-Navs
	$('ul#nav div.sub-nav').css('display','none');
	
	// Set Selected Menu Item
	$('body#home a#mnu-home > span').addClass('selected').css('background-color', '#f19120');
	$('body#products a#mnu-products > span').addClass('selected').css('background-color', '#f19120');
	$('body#services a#mnu-services > span').addClass('selected').css('background-color', '#f19120');
	$('body#customers a#mnu-customers > span').addClass('selected').css('background-color', '#f19120');
	$('body#newsevents a#mnu-newsevents > span').addClass('selected').css('background-color', '#f19120');
	$('body#resources a#mnu-resources > span').addClass('selected').css('background-color', '#f19120');
	$('body#about a#mnu-about > span').addClass('selected').css('background-color', '#f19120');

	$('ul#nav a.nav-link').mouseenter(function() {
		// Reset all Menu BG Colors
		$('ul#nav a.nav-link span').stop(true, true).css('background-color', '#005596');
		$('ul#nav a.nav-link span.selected').stop(true, true).css('background-color', '#f19120');
		// Set the hovered Menu Item's BG-Color
		$(this).children('span').stop(true, true).css('background-color', '#00aaef');
		$(this).children('span.selected').stop(true, true).css('background-color', '#f19120');
		// Hide all
		$('ul#nav div.sub-nav').stop(true, true).fadeOut('slow');		
		// Non Standards
		$(this).children('.sub-nav').css('left', ((($(this).children('.sub-nav').width() / 2) * (-1)) + ($(this).children('span').width() / 2) -10)); //((($(this).siblings('.sub-nav').width() / 2) * (-1)) + ($(this).width() / 2) -20)
		$(this).children('.sub-nav').stop(true, true).fadeIn('fast');
		// Standards
		$(this).siblings('.sub-nav').css('left', ((($(this).siblings('.sub-nav').width() / 2) * (-1)) + ($(this).children('span').width() / 2) -10)); //((($(this).siblings('.sub-nav').width() / 2) * (-1)) + ($(this).width() / 2) -20)
		$(this).siblings('.sub-nav').stop(true, true).fadeIn('fast');
	});

	function navCloseAll() {
		// Hide all Sub-Navs
		$('ul#nav div.sub-nav').stop(true, true).fadeOut('fast');
		// Reset all Menu BG Colors
		$('ul#nav a.nav-link span').css('background-color', '#005596');
		$('ul#nav a.nav-link span.selected').css('background-color', '#f19120');
	};
	
	//Trigger close Nav
	$('div#top').mouseenter(function() {navCloseAll()});
	$('div#head').mouseenter(function() {navCloseAll()});
	$('div#top').mouseenter(function() {navCloseAll()});
	$('div#banners').mouseenter(function() {navCloseAll()});
	$('div#mainbody').mouseenter(function() {navCloseAll()});
    
	
	//This jQuery below makes the roll over nav clickable to make the drop downs accessable for mobile devises -->
  	$('ul#nav a.nav-link').click(function(e) {
		if ($(this).attr('href') == '#'){
		e.preventDefault();}
		// Reset all Menu BG Colors
		$('ul#nav a.nav-link span').stop(true, true).css('background-color', '#005596');
		$('ul#nav a.nav-link span.selected').stop(true, true).css('background-color', '#f19120');
		// Set the hovered Menu Item's BG-Color
		$(this).children('span').stop(true, true).css('background-color', '#00aaef');
		$(this).children('span.selected').stop(true, true).css('background-color', '#f19120');
		// Hide all
		$('ul#nav div.sub-nav').stop(true, true).fadeOut('slow');		
		// Non Standards
		$(this).children('.sub-nav').css('left', ((($(this).children('.sub-nav').width() / 2) * (-1)) + ($(this).children('span').width() / 2) -10)); //((($(this).siblings('.sub-nav').width() / 2) * (-1)) + ($(this).width() / 2) -20)
		$(this).children('.sub-nav').stop(true, true).fadeIn('fast');
		// Standards
		$(this).siblings('.sub-nav').css('left', ((($(this).siblings('.sub-nav').width() / 2) * (-1)) + ($(this).children('span').width() / 2) -10)); //((($(this).siblings('.sub-nav').width() / 2) * (-1)) + ($(this).width() / 2) -20)
		$(this).siblings('.sub-nav').stop(true, true).fadeIn('fast');
	});
});
