jQuery(document).ready(function() {
	
	jQuery("#searchContentBox").fancybox();
	

});


function doSearch()
  {
  // set title of search fancybox link  - this title will be
  // displayed under the fancybox popup
  jQuery("#searchContentBox").attr("title","Search results for '"+
    jQuery('#searchtxt').val()+"'");
  // clear the contents of the google search results
  jQuery(".gsc-results").html("");
  // transfer our search keys to the google search box
  jQuery('input.gsc-input').val(jQuery('#searchtxt').val());
  // activate the google site search
  jQuery('input.gsc-search-button').click();
  // go and wait for the google search results to show up
  checkGResults();
}

function checkGResults(noclick)
{
  jQueryres = jQuery(".gsc-results").html();
  if (jQueryres!="")
    prepareSearchResults(noclick);
  else
    window.setTimeout("checkGResults("+noclick+")",500);
}

function prepareSearchResults(noclick)
{
  // get all page cursor links (DIV) into an array
  var pages = jQuery("#search .gsc-results .gsc-cursor-page");
  // transfer (copy) search results to our fancybox DIV
  jQuery("#results").html(jQuery(".gsc-results").html());
  // hide spelling
  jQuery(".gs-spelling").css("display","none");
  if (pages.length>0)
  {
    // paging was found so go and bind a click handler that
    //  will activate the right paging link when clicked
    var newpages = jQuery("#results .gsc-cursor-page");
    for (var p=0; p<newpages.length; p++)
    {
      // loop all pages and bind a click handler
      // provide the index (p) for paging lookup
      jQuery(newpages[p]).bind('click',{idx: p},
        function(event)
        {
          // activate the right paging link
          jQuery(jQuery("#search .gsc-results .gsc-cursor-page")
             [event.data.idx]).click();
          // clear search results
          jQuery(".gsc-results").html("");
          // start checking for results and do not popup!
          checkGResults(true);
        });
     }
  }
  if (!noclick)
    jQuery("#searchContentBox").click();
}
