 $(document).ready(function() {
    $("#searchImageOption1").click(function(){        
        $("#catalogSearchOption1").attr("checked",true);        
        updateSearchBox();
    });    
    $("#searchImageOption2").click(function(){        
        $("#catalogSearchOption2").attr("checked",true);        
        updateSearchBox();
    });    
    $("#catalogSearchOption1").change(function(){
        updateSearchBox();
    });
    $("#catalogSearchOption2").change(function(){
        updateSearchBox();
    });
    
    $(document).click(function(){
    	$(".footerLinksPopout").hide();
    	$("#howdoImenu ul").hide();
    });
    
    $("h2.noteworthy-header").click(function(){
    	window.location.href="/news/index.php";
    })
    $("h2.calendar-header").click(function(){
    	window.location.href="/events/index.php";
    })
        
    $("#howdoImenu a").click(function(){ 
    	$("#howdoImenu ul").slideToggle("fast");
    
    });
    
    $("#wtvlFooter").click(function(){
    	$("#communityLinks").hide();
    	$("#educationLinks").hide();
    	$("#governmentLinks").hide();
    	$("#wtvlLinks").slideToggle();
    	return false;
    });
    
    $("#communityFooter").click(function(){
	    $("#wtvlLinks").hide();
	    $("#educationLinks").hide();
    	$("#governmentLinks").hide();
    	$("#communityLinks").slideToggle();
    	return false;
    });
    
    $("#educationFooter").click(function(){
	    $("#communityLinks").hide();
    	$("#wtvlLinks").hide();
    	$("#governmentLinks").hide();
    	$("#educationLinks").slideToggle();
    	return false;
    });

 	$("#governmentFooter").click(function(){
	 	$("#communityLinks").hide();
    	$("#educationLinks").hide();
    	$("#wtvlLinks").hide();

    	$("#governmentLinks").slideToggle();
    	return false;
    });
    
    
    
    $("#cse-search-box-top").submit(function(){
       if($("#searchbox").val()=='Enter search term' || $("#searchbox").val()=='Find books, movies, music, and more'){
            alert('A search term must be entered.');
            $("#searchbox").focus();
            return false;    
       }
       
    });
    
    $("#newsletterSubscribe").submit(function(){
    	if($(".newsltr-email").val()=='E-mail Address' || $(".newsltr-email").val()=='' ){
    		alert('Please enter your e-mail address');
    		$(".newsltr-email").focus();
    		return false;
    	}
    	return true;    	
    });
    
    function updateSearchBox(){
        if(!$("#catalogSearchOption1").attr("checked")){
            $("#cse-search-box-top").attr("action","/searchresults.php");
            $("#searchbox").val("Enter search term"); 
            $("#searchbox").unbind("change");
            $("#searchbox").unbind("blur");
            $("#searchbox").unbind("focus");
            $("#searchbox").change(function(){
                if(this.value=='Enter search term'){
                    this.value='';
                    this.style.color='#000';
                };
            });
            $("#searchbox").blur(function(){
                if(this.value==''){
                    this.value='Enter search term';
                    this.style.color='#888';}
                
            });
            $("#searchbox").focus(function(){
                if(this.value=='Enter search term'){
                    this.value='';
                    this.style.color='#000';
                }    
            });      
        }   
        else{
            // Catalog Search...
            $("#cse-search-box-top").attr("action","/catalog/index.php");
            $("#searchbox").val("Find books, movies, music, and more");
            $("#searchbox").unbind("change");
            $("#searchbox").unbind("blur");
            $("#searchbox").unbind("focus");
            $("#searchbox").change(function(){
                if(this.value=='Find books, movies, music, and more'){
                    this.value='';
                    this.style.color='#000';
                };
            });
            $("#searchbox").blur(function(){
                if(this.value==''){
                    this.value='Find books, movies, music, and more';
                    this.style.color='#888';}
                
            });
            $("#searchbox").focus(function(){
                if(this.value=='Find books, movies, music, and more'){
                    this.value='';
                    this.style.color='#000';
                }    
            });
        } 
    };
    
    $("#main-slideshowPages ul li").click(function(){
        $("#main-slideshowPages ul li").removeClass("selected");
        $("#page"+$(this).attr("id").substring(4)).addClass("selected");                        
    });
    
    updateSearchBox();
    
});                

        var timeout    = 350;
        var closetimer = 900;
        var ddmenuitem = 0;

        function jsddm_open(passeditem)
        {  //jsddm_canceltimer();
           //jsddm_close();
           $(passeditem).parent().find('ul').slideToggle();
           $(passeditem).parent().find('ul li a').unbind();
           return false;  
         }

        function jsddm_close()
        {  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}
                                                                                                                
        function jsddm_timer()
        {
            closetimer = window.setTimeout(jsddm_close, timeout);
        }

        function jsddm_canceltimer()
        {  if(closetimer)
           {  window.clearTimeout(closetimer);
              closetimer = null;}}

        $(document).ready(function()
            {  $('#menu-top > ul > li').bind('mouseover', jsddm_open);
               $('#menu-top > ul > li').bind('mouseout',  jsddm_timer);
               $('.expandable a').click(function(){
               		jsddm_open(this);
               		return false;
               });
               //$('.nav-right > ul > li').bind('mouseout',  jsddm_timer)
            });


