﻿/********************************************************************************
 Animate the nav bar upon rollover of top nav link
********************************************************************************/
$(document).ready(function() {
	NavOnInit();
});
/********************************************************************************
 set the position of the bar over the home link and hide it till a nav item is
 rolled over
********************************************************************************/
function NavOnInit(){    
    //starting point + (half of home nav item's width - half of the nav bar's width)
    var x = 21 + (($("#navHome").width()/2) - 6);
    $(".nav-on").attr({"style":"opacity:0; filter:alpha(opacity=0); -moz-opacity:0; left:"+x+"px;"});
}
/********************************************************************************
 slide the bar to selected item 
********************************************************************************/
var navBarActive = false;
var t = 0;
var counter = 3;
var t2 = 0;
var statusCount = 2; //if the user hasn't hovered a nav item within 3 seconds, stop the animation
function SlideBar(item){
    //lets clear everything out to prevent over animation
    clearTimeout(t);
    $(".nav-on").stop(); //stops the bar from animating
    
    //calculate the position of the nav bar
    var itemPos = ($("#"+item).offset().left - (($("body").width() - 900)/2)) + (($("#"+item).width()/2)-6) + 10;
    $(".nav-on").animate({
        opacity: 1,
        left: itemPos
    }, 1000);
}
/********************************************************************************
 hide the bar if there are no menu items in hover state
********************************************************************************/
function HideBar(){
    CheckStatus();            
}
/********************************************************************************
 check to see if the menu items are not active
********************************************************************************/
function CheckStatus(){
    if(counter == 0){
        $(".nav-on").stop(); //stop animation
        $(".nav-on").animate({opacity: 0}, 800); //fade bar out
        counter = 3; //reset counter
    }else{
        counter --; //count down time
        t = setTimeout("CheckStatus()",1500);
    }
}
/********************************************************************************
 swap out image on rollover and highlight background
********************************************************************************/
function SwapImage(path,image){
    $("#"+image).attr({"src":path});
    $("#"+image).addClass("active-menu");
}
function RemoveActive(image){
    $("#"+image).removeClass("active");
}

