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

var cs;
$(document).ready(function() {
	cs = new cse();
});

function OnLoad() {
}

function cse() {
	if(document.getElementById("searchForm") != null) {
	    this.searchForm = new google.search.SearchForm(true, document.getElementById("searchForm"));
	    $(this.searchForm.userDefinedCell).html($('#hiddenfields input').clone());
	}
	if(document.getElementById("searchForm2") != null) {
	    this.searchForm2 = new google.search.SearchForm(true, document.getElementById("searchForm2"));
    }
    
    if(document.getElementById("ext_search_form") != null) {
    	var tmp = $('#ext_search_form').clone();
    	$('#ext_search_form').remove();
    	tmp.insertAfter('table.gsc-branding')
    	initExtSearch();
    }
    
    //$('#hiddenfields .exsearch-link').clone().insertAfter('table.gsc-branding');
    $('#hiddenfields').remove()
    $('input.gsc-input').attr('name','query'); 
    $('#searchForm form.gsc-search-box').attr('action',"index.php");

    $('#searchForm input.gsc-input').val(getCompleteQuerystring());
    $('#searchForm input.gsc-input').focus();
    $("#searchForm input.gsc-input").setCursorPosition( $("#searchForm input.gsc-input").val().length );
    
	var query = $('#vquery').val();
    
	this.searchControl2 = new google.search.CustomSearchControl('partner-pub-1971681382042532:6otfqdjyn78');
    this.searchControl2.setResultSetSize(google.search.Search.LARGE_RESULTSET);
    this.searchControl2.setSearchCompleteCallback(this,cse.prototype.onSearchComplete2);
        
 /*   books = new google.search.WebSearch();
    books.setUserDefinedLabel('BÜCHER');
    books.setSiteRestriction('amazon.de');
    this.searchControl2.addSearcher(books);
   */ 
    
    this.searchControl2.draw(document.getElementById("searchArea"));
    this.searchControl2.execute(getCompleteQuerystring());
    
    $('#searchArea form').remove();
}

cse.prototype.onSearchComplete2 = function (a, response) {
	  
    this.searchControl 	= new google.search.SearchControl();//new google.search.CustomSearchControl('partner-pub-1971681382042532:6otfqdjyn78');
    this.searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
    
    var options = new google.search.SearcherOptions();
    options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
    this.blogSearcher = new google.search.BlogSearch();
    this.blogSearcher.setResultOrder(google.search.Search.ORDER_BY_DATE);
   
    this.blogSearcher.setUserDefinedLabel('Kampfsport-Blogs');
    options.setRoot(document.getElementById("blogSearch"));
    this.searchControl.addSearcher(this.blogSearcher, options);
    
    var options = new google.search.SearcherOptions();
    options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
    this.newsSearcher = new google.search.NewsSearch();
    this.newsSearcher.setUserDefinedLabel('Kampfsport-News');
    this.newsSearcher.setResultOrder(google.search.Search.ORDER_BY_DATE);
    options.setRoot(document.getElementById("newsSearch_inner"));
    this.searchControl.addSearcher(this.newsSearcher, options);
    
    var options = new google.search.SearcherOptions();
    options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
    this.imageSearcher = new google.search.ImageSearch();
    this.imageSearcher.setUserDefinedLabel('Kampfsport-Bilder');
    options.setRoot(document.getElementById("imageSearch_inner"));
    this.searchControl.addSearcher(this.imageSearcher, options);
    
    
    var options = new google.search.SearcherOptions();
    options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
    this.videoSearcher = new google.search.VideoSearch();
    this.videoSearcher.setUserDefinedLabel('Kampfsport-Videos');
    options.setRoot(document.getElementById("videoSearch_inner"));
    this.searchControl.addSearcher(this.videoSearcher, options);
    
    var options = new google.search.DrawOptions();
    options.setSearchFormRoot(document.getElementById("searchForm2"));
    this.searchControl.draw(document.getElementById("searchArea1"),options);
    
    this.searchControl.execute(getCompleteQuerystring());
    
    $('.thumb').remove();
    $('a.gs-title').each(function(index) {
    	var result_url = $(this).attr('href');
    	
    
		 p = $(this).parent().parent();
		 var e_long_url = p.find(".gs-visibleUrl-long");
		 e_short_url = p.find(".gs-visibleUrl-short");
		 
		 try { e_long_url.html(decodeURIComponent(e_long_url.html())); }
		 catch(error) {}
		  
		 
		 if(result_url != '') {
			 $('<a class="thumb" href="'+result_url+'"><img style="height:75px; float:left; margin-right:10px;border:1px solid #ccc; padding:3px;" src="http://open.thumbshots.org/image.aspx?url='+result_url+'" /></a>').insertBefore($(this).parent());
		 }
	  });
    
    $('#searchForm2').remove();
}


