

if(window.google){
	google.load('search', '1');
}
// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse() {
  var leftScDiv = document.getElementById("searchform");

  // create a left, right search control
  // create a custom search form
  this.leftControl = new google.search.SearchControl();

  // set up for large result sets
  this.leftControl.setResultSetSize(GSearch.SMALL_RESULTSET);
  this.leftControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
  var searcher;
  var options;

  // configure left control
  // Site Restrict to CSE ID for Curriculum Search
  var cseId = "003125691254608490735:4onskqo03ra";
  searcher = new google.search.WebSearch();
  options = new google.search.SearcherOptions();
	options.setRoot(document.getElementById("results"));
  searcher.setSiteRestriction(cseId, null, "http://www.mailchimp.com/page/search-results/?cx=003125691254608490735%3A4onskqo03ra&q=__QUERY__&sa=Search&client=google-coop-np&cof=FORID%3A9%3BCX%3ACurriculum&hl=__HL__&cof=FORID%3A10&ie=UTF-8&sa=Search#1067");
 	options.setNoResultsString("We're sorry, but there were no results.");
  options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
  this.leftControl.addSearcher(searcher, options);
	this.leftControl.setSearchCompleteCallback(cse, cse.prototype.mySearchComplete);
	this.leftControl.setSearchStartingCallback(cse, cse.prototype.mySearchStart);

  // draw the left and right controls
  // the right control is drawn in tabbed mode
  var drawOptions = new google.search.DrawOptions();
  drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

  this.leftControl.draw(leftScDiv);
}


cse.prototype.mySearchComplete = function(sc, searcher){
	//alert($('#searchResults').html());
	//var data = document.getElementById('searchResultsFB').innerHTML;
	//jQuery.facebox('#searchResults');
	showModal();
	return false;
}

cse.prototype.mySearchStart = function(sc, searcher, query){
	//alert("The Query is: " + query);
	urchinTracker('/page/search-results/?q='+query);
	return false;
}

// when the form fires a submit, grab its
// value and call the left and right control
cse.prototype.onSubmit = function(form) {
  var q = form.input.value;
  if (q && q!= "") {
    this.leftControl.execute(q);
  }
  return false;
}

// when the form fires a clear, call the left and right control
cse.prototype.onClear = function(form) {
  this.leftControl.clearAllResults();
  form.input.value = "";
  return false;
}

function OnLoad() {

  new cse();	

	$('#searchResults').hide();
	$('#close_btn').css('opacity', '.3');
	$('#close_btn').click(function(){
		hideModal();
		return false;
	}).mouseover(function(){
		$('#close_btn').css('opacity', '.6');
	}).mouseout(function(){
		$('#close_btn').css('opacity', '.3');
	});
	
	
	//alert($('#searchform').html());
	//$('.gsc-input').attr("value", "Search...");
	$('.gsc-input').css("color", "#666666");
	$('.gsc-input').focus(function(){
		// if($(this).attr('value') == "Search..."){
		// 		$(this).attr('value', '');
		// 	}
		$('.gsc-input').css("color", "#222222");
	}).blur(function(){
			// if($(this).attr('value') == ""){
			// 				$(this).attr('value', 'Search...');
			// 			}
		$('.gsc-input').css("color", "#666666");	
	});

}
google.setOnLoadCallback(OnLoad, true);	

// capture ESC press
document.onkeydown = function(e){
if (e == null) { // ie
  keycode = event.keyCode;
} else { // mozilla
  keycode = e.which;
}
if(keycode == 27){ // escape, close box
	hideModal();
}
};

function showModal(){
	$('document').css('overflow','hidden');
	$('#searchResults').fadeIn();
	$('#interior_white_bg').css({'z-index':'-1', 'position':'relative'});
}

function hideModal(){
	$("#searchResults").fadeOut();
	$('document').css({"overflow":"scroll","overflow-x":"hidden"});
	$('#interior_white_bg').css({'z-index':'1', 'position':'static'});
}