google.load('search', '1');
function cse() {
  var scDiv = document.getElementById("searchControl");
  this.Control = new google.search.SearchControl();
  this.Control.setResultSetSize(google.search.Search.LARGE_RESULTSET);
  var searcher;
  var options;
  for (r in scope) {
    searcher = new google.search.WebSearch();
    searcher.setSiteRestriction("006107244075861899220:alzwcnhh6wk",scope[r]);
    searcher.setUserDefinedLabel(r);
    this.Control.addSearcher(searcher);
  }
  var drawOptions = new google.search.DrawOptions();
  drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
  drawOptions.setSearchFormRoot('searchform');
  this.Control.draw(scDiv, drawOptions);
  
  if($.getUrlVar('q')) {
    this.Control.execute(decodeURI($.getUrlVar('q')));
  }
}
cse.prototype.onSubmit = function(form) {
  var q = form.input.value;
  if (q && q!= "") {
    this.Control.execute(q);
  }
  return false;
}
cse.prototype.onClear = function(form) {
  this.Control.clearAllResults();
  form.input.value = "";
  return false;
}
function OnLoad() {
  new cse();
  $("div.gsc-tabHeader").each(function(){
    $(this).wrapInner('<span></span>');
  });
  if(option["AllSearch"]){
    $("div.gsc-tabsArea").append('<p class="arrow"><a href="search/all/?q='+decodeURI($.getUrlVar('q'))+'">'+option["AllSearch"]+'</a></p>');
  }
}
google.setOnLoadCallback(OnLoad, true);
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
