
google.load("jquery", "1.4");
google.setOnLoadCallback(function()
{      
	 var $ =jQuery; 
   $("#SearchForm_SearchForm_Search").attr("autocomplete", "off"); 
	 $("#SearchForm_SearchForm_Search").blur(
	   function() {                
	     var v =   $("#SearchForm_SearchForm_Search").val();
	     $("#SearchForm_SearchForm_Search").val((v=="")?"Search":v);
	     $('#search_results').fadeOut(); 
	     index = 0;
 	   });
	 $("#SearchForm_SearchForm_Search").focus(
	   function() {       
	     var v =   $("#SearchForm_SearchForm_Search").val();
	     if(v !="Search")
	     {
	       showResults() ;
	     } 
	     else
	     {
	        $("#SearchForm_SearchForm_Search").val("");  
	     } 
	   });                                      
	 $("#SearchForm_SearchForm_Search").keyup(lookup);    
	 $("#SearchForm_SearchForm").submit(  
	    function() {
        var a = $('#search_results li.active a'); 
        if((a.length + index)>1)
        {
            window.location = a.attr("href"); 
            return false; 
        }           
	      return true;
	    } );
	    



 

		 $("#PageGallery").each(function(){
		    var gallery = $(this);  
            
		    $(".MainGalleryImage", gallery).click(function () {
	          var next = $("#PageGallery li.active").next() ; 
	          next = (next.size())?next:$("li", gallery).first();
	          makeActiveImage($("img",next ),gallery);    
	  	  });



		    $("ul img", gallery).each(function() {
	        $(this).hover(function () {
	          makeActiveImage(this,gallery);
	        });
					$(this).click(function () {
	          makeActiveImage(this,gallery);  
						return false; 
	        });         
		    }); 	   
		 }) ;
	     
});
  

	function makeActiveImage(img, gallery)
	{
     var $ =jQuery; 
	   $("ul li", gallery).removeClass("active"); 
   
	   $(".MainGalleryImage", gallery).attr("src", $(img).parent().attr("banner"));  
	   $(".MainGalleryImage", gallery).attr("title", $(img).parent().attr("title")); 
   
	   $("h4", gallery).html($(img).attr("title"));   
	   $("p",gallery).html($(img).parent().attr("title"));   
   
   
      
	   $(img).parents("li").addClass("active") ;    

 
	}


  function showResults()
  {   
			var $ =jQuery; 
      $('#search_results').fadeIn(); 
  }      
  
          
    function moveSelection(key)
    {   
			var $ =jQuery; 
      var a = $('#search_results li.active');
      if(a.length )
      {    var all = $('#search_results li'); 
           a.removeClass("active");     
           var inc = (key == 38)?-1:1;  
     
           index = (index+inc) % all.length;
           $(all.get(index)).addClass("active"); 
      } 
      else if($('#search_results li').length)
      {    
        index = 0;
        $('#search_results li:first').addClass("active"); 
      }     

      
    }              
        
  
  var index = 0;
  function lookup(key) 
  {   
			var $ =jQuery; 
      if(key.which == 38 || key.which == 40)
      {      
          moveSelection(key.which);
          return false;
      } 
      index = 0;    
      var inputString = this.value;
    	if(inputString.length < 3) {
    		$('#search_results').fadeOut(); // Hide the suggestions box
    	} else {    

    		$.post($("#SearchForm_SearchForm").attr("action"),{Search:inputString,action_ajaxResults: "Search"}, function(data) { // Do an AJAX call
    			showResults();  // Show the suggestions box
    			$('#search_results').html(data); // Fill the suggestions box
    		});
    	} 
	              
	
	
  }     
