// addThis share button definitions
var addthis_config = {
   addthis_pub: "quodis",
   services_exclude: 'backflip,ballhype,email,fark,faves,diigo,kaboodle,kirtsy,linkagogo,live,netvouz,nujij,hatena,meneme,plaxo,print,segnalo,spurl,simpy,stylehive,thisnext,twitter,yardbarker'
}

var default_search = "twitpic";

// define array for bird queue
var ToriQueue = new Array(0);
var currentQueueIndex = 0;



// Cloud Types: CSS name, Speed, Initial Speed
CloudTypes = new Array(3)
CloudTypes[0] = ["L", 62000, 65000];
CloudTypes[1] = ["M", 57000, 60000];
CloudTypes[2] = ["S", 77000, 80000];



$(document).ready(function(){

	// facebox for about tori's eye
	$('a[rel*=facebox]').facebox();
	
	// History
	function pageload(hash) {
/* 		hash = encodeURIComponent(hash); */
		if(hash) {
			fetchFeed('search.twitter.com/search', 'callback=?&rpp=40&', hash);
		} else {
			fetchFeed('search.twitter.com/search', 'callback=?&rpp=40&', default_search);
		}
	}

	$.historyInit(pageload);

	$("form:first").submit(function(){
		var hash = $("#search").val();	
		$.historyLoad(hash);
		return false;
	});

	// Start the never-ending spawn cycle
	spawnTori();
	
	// Start the cloud movement
	for (i = 0; i < CloudTypes.length; ++ i) {
		moveCloud(CloudTypes[i][0], CloudTypes[i][1], CloudTypes[i][2]);
	}
	
	// Search input listener to update submit button icon
	$("#search").keyup( function() {
		$("#sendBttn").removeClass("error");
		$("#sendBttn").addClass("standby");
	});

});

// Cloud movement
function moveCloud(id, speed, initialspeed) {
	if (parseInt($("#cloud" + id).css("left")) == 100) {
		// Second or + movement, final speed
		$("#cloud" + id).css("left", "-220px");
		thisspeed = speed;
	} else {
		// First time it's moving, so start at initial speed
		thisspeed = initialspeed;
	}
		
	$("#cloud" + id).animate({left:"100%"}, thisspeed, "linear");
	setTimeout("moveCloud('" + id + "', "+speed+")", thisspeed+100);
}




/* define function to spawn tories */
function spawnTori(){
	if ((ToriQueue.length >= currentQueueIndex) && (ToriQueue[currentQueueIndex] != undefined)) {
		
		
		
	
		
	
	
	//} else if(currentQueueIndex > 0)  {
		//RESTART, REQUERY
		
	}
	
	// Go to try next in queue, in 2000 to 4000 ms
	setTimeout("spawnTori()",2000 + parseInt(Math.random()*2000));
}




function fetchFeed(type, parameters, torisQuery) {



	

		}  
	
