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

function OnLoad() {
  var searchControlDiv = document.getElementById("gImageSearchContent");
  var control = new google.search.SearchControl(); // CustomSearchControl
  control.setResultSetSize(GSearch.LARGE_RESULTSET);
  // control.setLinkTarget(GSearch.LINK_TARGET_BLANK);

  var options = new google.search.SearcherOptions();
  options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);

  var isearcher;
  var colors = [
	'ALL',
	google.search.ImageSearch.COLOR_BLUE,
	// google.search.ImageSearch.COLOR_TEAL,
	google.search.ImageSearch.COLOR_GREEN,
	google.search.ImageSearch.COLOR_ORANGE,
	google.search.ImageSearch.COLOR_RED,
	google.search.ImageSearch.COLOR_YELLOW,
	google.search.ImageSearch.COLOR_PURPLE,
	google.search.ImageSearch.COLOR_PINK,
	google.search.ImageSearch.COLOR_WHITE,
	google.search.ImageSearch.COLOR_GRAY,
	google.search.ImageSearch.COLOR_BLACK,
	google.search.ImageSearch.COLOR_BROWN
  ];
  
	for (var i=0; i < colors.length; i++) 
	{
		var colorSearcher = new google.search.ImageSearch();
		colorSearcher.setRestriction(google.search.ImageSearch.RESTRICT_IMAGETYPE, 
									 google.search.ImageSearch.IMAGETYPE_PHOTO)
		colorSearcher.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
									 google.search.ImageSearch.IMAGESIZE_MEDIUM);
		if( colors[i] == 'ALL' )
		{
			colorSearcher.setRestriction(google.search.ImageSearch.RESTRICT_FILETYPE,
										 google.search.ImageSearch.FILETYPE_JPG);
			var colorName = 'All';
		}
		else
		{
			colorSearcher.setRestriction(google.search.ImageSearch.RESTRICT_COLORFILTER,
										 colors[i]);
			var colorName = colors[i].substring(0,1).toUpperCase() + colors[i].substring(1);
		}
		colorSearcher.setUserDefinedLabel(colorName);
		// colorSearcher.setSiteRestriction('003344132374992433815:5qipn6fupl0');
		// colorSearcher.setSiteRestriction('pantip.com');
		control.addSearcher(colorSearcher, options);
	};

	// tell the searcher to draw itself and tell it where to attach
	var drawOptions = new google.search.DrawOptions();
	drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
	control.draw(searchControlDiv, drawOptions);
	
	if( firstImgSearchKeyword )
	{
		control.execute(firstImgSearchKeyword);
	}
}

google.setOnLoadCallback(OnLoad);

