﻿(function($){   
 $.fn.GoogleCSE = function(options) {   
  
    var defaults = {           
    };     
  
    var options = $.extend(defaults, options); 
    
    return this.each(function() { 
    
        var obj = $(this);     
        
        var targetUrl = "http://www.heig-vd.ch/search/index.html?cx=014905156093472783283%3Ahcygrfxo3lq&cof=FORID%3A11";      
        
        initialize();
        
        function initialize() {
            
            registerHandlers();            
        }    	    	
       
        function registerHandlers() {             
            
            $('#searchBoxLabel').bind('click', function(e) {  
                
                search();                                    
            });
            
            $('#searchBox').bind('keypress', function(e) {                  
                
                if (e.which == 13) {
                    search(); 
                    e.preventDefault();                                   
                }   
            });        
        }    
        
        function search() {
            
            var val = $('#searchBox').attr('value');
            
            if (val) {            
                location.href = targetUrl + "&q=" + encodeURIComponent(val);                                               
            }
            else
                alert("Pour que la recherche soit efficace, il serait de bon ton d'entrer quelque chose dans le champ de recherche ;-)");
        }
    });   
 };   
})(jQuery);  
 
 
jQuery().ready(function() {   
    jQuery().GoogleCSE();
});   


