google.load('search', '1', {"language" : "es"});

// the cse class encapsulates a left and right search control
// both controls are driven by a shared search form
function cse( busqueda_defecto ) {
	
	// create a custom search form
	var sFormDiv = document.getElementById("be_googlecse_searchForm");
	this.searchForm = new google.search.SearchForm(false, sFormDiv);
	
	// bind clear and submit functions
	this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
	//this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
	
	
	
	// configure left control
	var options_opened = new google.search.SearcherOptions();
	options_opened.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	
	var options_closed = new google.search.SearcherOptions();
	options_closed.setExpandMode(GSearchControl.EXPAND_MODE_CLOSED);
	
	var options_partial = new google.search.SearcherOptions();
	options_partial.setExpandMode(GSearchControl.EXPAND_MODE_PARTIAL);
	
	
	
	// create a left search results
	var leftScDiv = document.getElementById("be_googlecse_leftSearchControl");
	this.leftControl = new google.search.SearchControl();
	this.leftControl.setResultSetSize(google.search.Search.LARGE_RESULTSET); // set up for small result sets
	this.leftControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING); // no results string
	
	var leftSearchs = false;
	
	// -- cse for comparisons
	leftSearchs = new google.search.WebSearch();
	leftSearchs.setUserDefinedLabel("Resultados de b&uacute;squeda");
	leftSearchs.setUserDefinedClassSuffix("velneoESSearch");
	leftSearchs.setSiteRestriction("velneo.es");
	this.leftControl.addSearcher(leftSearchs, options_opened);
	
	// -- cse for community			
	/*
	leftSearchs = new google.search.WebSearch();
	leftSearchs.setUserDefinedLabel("En Ingl&eacute;s");
	leftSearchs.setUserDefinedClassSuffix("velneoENSearch");
	leftSearchs.setSiteRestriction("velneo.com");
	this.leftControl.addSearcher(leftSearchs, options_closed);
	*/
	
	// -- cse for shopping
	/*
	leftSearchs = new google.search.WebSearch();
	leftSearchs.setUserDefinedLabel("En Chino");
	leftSearchs.setUserDefinedClassSuffix("velneoENSearch");
	leftSearchs.setSiteRestriction("velneo.net");
	this.leftControl.addSearcher(leftSearchs, options_closed);
	*/
	
	
	// Create a right search results
	var rightScDiv = document.getElementById("be_googlecse_rightSearchControl");
	this.rightControl = new google.search.SearchControl();
	this.rightControl.setResultSetSize(google.search.Search.LARGE_RESULTSET); // set up for small result sets
	this.rightControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING); // no results string
	
	var rightSearchs = false;
	/*
	// -- blog search
	rightSearchs = new google.search.BlogSearch();
	rightSearchs.setUserDefinedLabel("La Blogosfera");
	rightSearchs.setSiteRestriction("velneo.es");
	this.rightControl.addSearcher(rightSearchs, options_partial);
	// -- web search
	rightSearchs = new google.search.WebSearch();
	rightSearchs.setUserDefinedLabel("Internet");
	rightSearchs.setSiteRestriction("velneo.es");
	this.rightControl.addSearcher(rightSearchs, options_partial);
	// -- news search
	rightSearchs = new google.search.NewsSearch();
	rightSearchs.setUserDefinedLabel("Noticias");
	rightSearchs.setSiteRestriction("velneo.es");
	this.rightControl.addSearcher(rightSearchs, options_partial);
	*/
	
	// -- Videos search
	rightSearchs = new google.search.VideoSearch();
	rightSearchs.setUserDefinedLabel("Videos");
	this.rightControl.addSearcher(rightSearchs, options_partial);
	
	// -- images search
	rightSearchs = new google.search.ImageSearch();
	rightSearchs.setUserDefinedLabel("Im&aacute;genes");
	rightSearchs.setSiteRestriction("velneo.es");
	this.rightControl.addSearcher(rightSearchs, options_partial);
	
	
	
	// RIGHT CONTROL TABBED
	var drawRightOptions = new google.search.DrawOptions();
	//drawRightOptions.setSearchFormRoot(sFormDiv);
	drawRightOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
	this.rightControl.draw(rightScDiv, drawRightOptions);
	
	// draw left CONTROL
	var drawLeftOptions = new google.search.DrawOptions();
	drawLeftOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
	//drawLeftOptions.setSearchFormRoot(sFormDiv);
	this.leftControl.draw(leftScDiv, drawLeftOptions);
	
	
	
	// bind in a videobar
	/*var videoBarDiv = document.getElementById("be_googlecse_videoBar");
	var videoPlayerDiv = document.getElementById("be_googlecse_videoPlayer")
	var vboptions = {
		largeResultSet : true,
		horizontal : true,
		thumbnailSize : GSvideoBar.THUMBNAILS_MEDIUM
	}
	
	this.videoBar = new GSvideoBar(videoBarDiv, videoPlayerDiv, vboptions);	
	*/
	
	// execute a starter search
	this.searchForm.execute(busqueda_defecto);

}


var cse_general_title = '';

// 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!= "") {
		if ( cse_general_title == '' ) cse_general_title = document.title;
		document.title = cse_general_title;
		
		this.leftControl.execute(q);
		this.rightControl.execute( "velneo " + q );
		//this.videoBar.execute( 'velneo ' + q);
		
		document.title = cse_general_title + " - " + q;
	}
	
	return false;
}

// when the form fires a clear, call the left and right control
cse.prototype.onClear = function(form) {
	this.leftControl.clearAllResults();
	this.rightControl.clearAllResults();
	//this.videoBar.clearAllResults();
	
	form.input.value = "";
	return false;
}