


var seekdom = ['google-pagerank','google-results','google-images','google-blogs','alexa-rank','bing-results'];
jQuery("document").ready(function(){
	jQuery("#theSearch > input[type='submit']").bind("click",function(){		
		performSearch();
	});
});

function performSearch(){
	var ritardo = new Array();
	var formInput = jQuery("#theSearch > input[name='theQuery']").val() ? jQuery("#theSearch > input[name='theQuery']").val() : 'http://kifulab.net';
	var element = false;
	for(i = 0; i < seekdom.length; i++){
		element = seekdom[i];
		eval("fetchData('"+formInput+"', '"+element+"')");		
	}
	plink = 'http://www.kifulab.net/tools/kiffu/site/';
	domain = formInput.replace('http://','');
	plink+=domain;
	
	jQuery("#permalink").html('Permalink to this search: <a href="'+plink+'" title="Permalink to this statistics">'+plink+'</a>');
	//jQuery("#results-wrap").append('<a href="#history" id="history">History</a>');
	//jQuery("#history").animate({right:"-60px"},1500);
	//jQuery("#history").bind("click",function(){
	//	printHistory(formInput);
	//});
}

function fetchData(formInput, element){
	jQuery("#results > #"+element+' > .result').html("*");
	jQuery.get('http://www.kifulab.net/tools/kiffu/api/getter.php',{q: formInput, w: element},function(data){
		jQuery("#results > #"+element+' > .result').html(data);
	});
}

function printHistory(formInput){
	jQuery.get('http://www.kifulab.net/tools/kiffu/api/history.php',{q: formInput},function(data){
		jQuery("#results").html(data);
	});
}


