// JavaScript Document

jQuery(document).ready(function() {

//main Nav rollovereffects
//startup commands preformed when DOM has indicated the documemt is ready

jQuery('#sn_' + currentSN).show();  //shows the current Sub Navigation (sn_) menu based on variable currentSN. Set to TV in CMS
jQuery('#' + current_page).toggleClass("currenttab");     //causes the main section to be highlighted by the variable current_pagae. Toggles CSS clas to .current tab. Set to TV in CMS
var current_tab = '#sn_' + currentSN    //Creates new variable to tell what subnav ID is active based on the CurrentSN 
jQuery("" + (current_tab) + " ul li:nth-child(" + (currentTAB) + ")").toggleClass("activeTAB");  //uses current_tab variable and currentTAB variable to traverse the DOM to the right active page. Highlighs it by setting class to activeTAB. Set CurrentTAB variable as TV in CMS



//Enter Menu effect. Removes class from the current page's tab when entering the Navigation containing DIV. 
$('#navContainer').mouseenter(
  function () {
  	 jQuery("" + (current_tab) + " ul li:nth-child(" + (currentTAB) + ")").removeClass("activeTAB");
  }
);




//rollover effects.
//As the mouse rollsover the main categories. The all subnavs are hidden while the current one is displayed, that links up with the correct main category
var mysubmenu = $('#mainNavtabs a').mouseover(function(){ 
	jQuery('#mainNavtabs a').removeClass("currenttab");	
	jQuery(this).toggleClass("currenttab");
	mysubmenu.index(this);
	jQuery("#sn_" + currentSN).hide();
	jQuery('#sn_' + mysubmenu.index(this) ).show();
	currentSN = mysubmenu.index(this);
 });


//reset effects
//as the mouse leaves the navigation div. All menus are reset back to the initial loading states.
$('#navContainer').mouseleave(
  function () {
    jQuery("#sn_" + currentSN).hide();
	jQuery("#sn_" + defaultSN).show();
	currentSN = defaultSN;
	jQuery('#mainNavtabs a').removeClass("currenttab");	
	jQuery('#' + current_page).toggleClass("currenttab");
	jQuery("" + (current_tab) + " ul li:nth-child(" + (currentTAB) + ")").toggleClass("activeTAB");
  }
);

$('.closeTip').click (
	function() {
	jQuery('.officetip').slideUp();
	jQuery('.officetip').removeClass('selected');
	});

$('.loctip', this).click (
   
   function() {    
	
    if ($(this).is('.selected')) { } else {jQuery('.officetip').slideUp();}
	jQuery('.selected').removeClass('selected');
	jQuery(this).next().slideDown('slow');
	jQuery(this).addClass('selected');
   
   }
  );

$('#timelineControls a', this).click (
   
   function() {    
	
    
	jQuery('.currentTime').removeClass('currentTime');
	jQuery(this).addClass('currentTime');
   
   }
  );


$('#search-clear').show();
$('#search').hide();

$('#search-clear').focus(function() {
    $('#search-clear').hide();
    $('#search').show();
    $('#search').focus();
});
$('#search').blur(function() {
    if($('#search').val() == '') {
        $('#search-clear').show();
        $('#search').hide();
    }
});

$(function(){
    $('input').keydown(function(e){
        if (e.keyCode == 13) {
            $(this).parents('form').submit();
            return false;
        }
    });
});



	
});




