function doMastheadAnimate (mastheadNavigationLink, index)
{
	// Move the the current masthead item	
	$("#mastheadItems").animate({ left: index * -620}, 700);

	// Remove the active class from whoever had it (by removing from all of them.
	$("#mastheadNavigation>ul>li>a").each(function(index) {
		$(this).removeClass("active");
	})

	// Indicate the selected item as active.
	mastheadNavigationLink.addClass("active");
	
	// Remember who is active.
	mastheadCurrentIndex = index;
}

var mastheadCurrentIndex = 0;
var cycleMasthead = true;
var mastheadCycleDuration = 6000;
function automatedMastheadAnimation ()
{
	// If we're still cycling.
	if (cycleMasthead == true)
	{
		// Determine the new index.
		mastheadCurrentIndex = (mastheadCurrentIndex + 1) % $("#mastheadNavigation>ul>li>a").length;
		
		// Animate to the next index.
		doMastheadAnimate ($("#mastheadNavigation>ul>li>a").eq(mastheadCurrentIndex), mastheadCurrentIndex);
		
		// Delay before the next animation.
		setTimeout(automatedMastheadAnimation, mastheadCycleDuration);
	}
}

function stopMastheadCycle ()
{
	cycleMasthead = false;
}

$(document).ready(function() {
	createcssmenu();
	
	$("#searchBox").focus(function() {
		if($("#searchBox").val() == "enter search term") {
			$("#searchBox").val("");	
		};
		
	})
	
	$("#searchBox").blur(function() {
		if($("#searchBox").val() == "") {
			$("#searchBox").val("enter search term");	
		};
	})
	
	// Initialize the click event for the masthead items.
	$("#mastheadNavigation>ul>li>a").each(function(index) {
		
		$(this).click(function(){

			// stop the automatic masthead rotation.
			stopMastheadCycle();
			
			// go to the selected masthead item.
			doMastheadAnimate($(this), index)
		})
	})

	// Initialize the click event for the masthead items.
	$("#mastheadNavigation>ul>li>embed").each(function(index) {
	
		$(this).click(function(){
			// stop the automatic masthead rotation.
			stopMastheadCycle();
		})
	})
	
	// Start scrolling through the masthead items.
	setTimeout(automatedMastheadAnimation, mastheadCycleDuration);
	
	//------------------------------------//
    // Show/Hide Functionality
    //------------------------------------//
    // Hide all div's with the class "shBox"
	$('.shBox').hide();
	
	//$("a.showHide").click(function(){ 
	//    var target = $($(this).attr('href')) 
	//    $("div.shBox:visible").not(target).slideUp(); 
	//    target.slideToggle(); 
	//}); 
	
	// Create show/hide functionality
	// Desc: Basically, this attaches a toggle onClick event to each
	// 'a' tag that has the class 'showHide'
	// The 'a' tag's HREF attribute value is the ID of the
	// element to be shown/hidden.
	// "shTitle" givs us a nice "expand/collapse" arrow right before the 'a' tag
	$('a.showHide').toggle(
	    function(){
		    var e = $(this)
		    if (e.hasClass("shTitle")){
		        e.addClass("shTitleOpen")
		    }
           // Fade in the selected element
			$(e.attr('href')).fadeIn("slow")
		},
		function(){
		    var e = $(this)
		    if (e.hasClass("shTitle")){
		        e.removeClass("shTitleOpen")
		    }
			// Fade out the element
			$(e.attr('href')).fadeOut("fast")
		}
    );
	
//------------------------------------//

	
})




var cssmenuids=["navul"] 
var csssubmenuoffset=0; 

function createcssmenu(){
	var ultags=document.getElementById(cssmenuids[0]).getElementsByTagName("ul");
 
	for (var t=0; t<ultags.length; t++){
		
		ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px";
			
		ultags[t].parentNode.onmouseover=function(){
			this.firstChild.className = this.firstChild.id;
			this.style.zIndex=100
			this.getElementsByTagName("ul")[0].style.visibility="visible"
			this.getElementsByTagName("ul")[0].style.zIndex=10;				
		}
		
		ultags[t].parentNode.onmouseout=function(){
			this.firstChild.className = "";
			this.style.zIndex=5;
			this.getElementsByTagName("ul")[0].style.visibility="hidden";
			this.getElementsByTagName("ul")[0].style.zIndex=100;
		}
	}
  
}
	
	
