
google.load('search', '1');

GoogleSiteSearch = function(options) {
    $(function(){
        var $popup = $('#' + options['popupBoxID']);
        if($popup.length == 0){
            $popup = $('<div id="' + options['popupBoxID'] + '" title="' + options['title'] + '"></div>').appendTo(document.body);
        }

        // Dialog			
        $popup.dialog({
            autoOpen: false,
            width: options['width'],
            position: 'top',
            resizable: false,
            draggable: true,
	    closeOnEscape: true
        });

        // Create a custom search control
        var customSearchControl = new google.search.CustomSearchControl('017665260709826710947:4fdbgoc44bg');

    
        // Set the Search Control to get the most number of results
        customSearchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
        var searchoptions = new google.search.DrawOptions();
        searchoptions.setAutoComplete(false);
        
        // have links open in the same window
        customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);

        // tell the searcher to draw itself and tell it where to attach
        customSearchControl.draw(document.getElementById(options['popupBoxID']),searchoptions);
				

        $('#' + options['openSearchID']).click(function(){
            $('#' + options['popupBoxID']).dialog('open');
         });

    });
}

