
/******************************************************************
* Apax Software Development LLC. (http://www.apaxsoftware.com)
* Google Site Search - Popup Google site search the uses jquery,
*  jquery ui, and the AJAX Google search API to easily add
*  dynamic site search capability to any site
* UI: Uses jQuery UI, use their themeroller to customize 
*      (http://jqueryui.com/themeroller/)
* NOTICE: This notice must stay intact for legal use
* HELP: If you need any help implementing or modifying this
*  site search solution, please contact
*  Apax Software Development LLC at:
*      http://www.apaxsoftware.com
******************************************************************/


if(typeof(APAX_BASE) == 'undefined'){
    function APAX_BASE(){ }
}

if(APAX == null) {
    var APAX = new APAX_BASE();
}

google.load('search', '1');

APAX_BASE.prototype.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: false
        });

        // Create a search control
        var searchControl = new google.search.SearchControl();

        // Add in a full set of searchers
        var siteSearch = new google.search.WebSearch();
    
        // Set the Search Control to get the most number of results
        searchControl.setResultSetSize(google.search.Search.MEDIUM_RESULTSET);
        var searchOptions = new google.search.SearcherOptions();
        searchOptions.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
        siteSearch.setUserDefinedLabel("Search Sacred-Geometry.com");
        siteSearch.setSiteRestriction(options['site']);
        searchControl.addSearcher(siteSearch, searchOptions);

        // tell the searcher to draw itself and tell it where to attach
        searchControl.draw(document.getElementById(options['popupBoxID']));
		x="#" + options['term'];
		

        $('#' + options['openSearchID']).click(function(){
            $('#' + options['popupBoxID']).dialog('open');
			searchControl.execute($(x).val());
         });

    });
}

