
	/**
	 * Firebug disabling console.log() :-)
	 * @link http://davidwalsh.name/how-to-sniff-firebug-disable
	*/ 
	if (! ('console' in window) || !('firebug' in console)) {
	    var names = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd'];
	    window.console = {};
	    for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() {};
	}
	
	
	function rand(minVal,maxVal)
	{
		var randVal = minVal+(Math.random()*(maxVal-minVal));
		return Math.round(randVal);
	}
	
		
		$(document).ready(function(){
			
		
	  	
	 	$("#header_search").mouseover(function(){
	 		$("#hint").show();
	  	});
	  	
	  	$("#header_search").mouseleave(function(){
	   		$("#hint").hide();
	  	});		
	  
		
		  	
		$.getJSON("http://twittospheric.com/cache.php?callback=?&t=1", function(json){ 
	        $.each(json.trends, function(i, val) {    
	        	if (i <= 6) 
	            	$("#trends_list").append(val.name+' - '); 
	        }); 
	        
	        $("#trends_list").append('Twitter');   
	      }); 
	        
	        
	        	
		function runIt() {	  	
		  			
	
			var index = rand(0,14);
			
			$.getJSON(url,
	        function(data){
	        	var count = 0;
	  			var data_to_parse = data;
	  			
	        	if (mode == "search")
	        		data_to_parse = data.results;
	        		
				$(data_to_parse).each(function(i, item) {
				
				
				if (i > index && i <= (index+6))
				{
					count = count+1;
		
					if (mode == "search")
						var username = item.from_user;
					else var username = item.user['screen_name'];
					
					if (mode == "search")
						var avatar = item.profile_image_url;	
					else var avatar = item.user['profile_image_url'];
					
					var txt = item.text.replace(
					  /(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig,
					  '<a href="$1" target="_blank">$1</a>'
					).replace(
					  /@+([_A-Za-z0-9-]+)/ig, 
					  '<a href="http://twittospheric.com/$1">@$1</a>'
					).replace(
					  /#+([_A-Za-z0-9-]+)/ig,
					  '<a href="http://twittospheric.com/s/$1">#$1</a>'
					);
				 
		
					$("#tweet"+parseInt(count)).children("#bubble").children("#msg").replaceWith(	
						'<div id="msg"><a href="http://twittospheric.com/'+username+'" class="username">'+username+'</a> ' + txt + '</div>' );
										
					$("#tweet"+parseInt(count)).children("#bubble").children("#avatar").replaceWith(
						'<div id="avatar"><a href="http://twitter.com/'+username+'" target="_blank"><img src="'+avatar+'" width="48" /></a></div>');
				}					
					
				});
	        });			
	
		  			
			var maxX = window.innerWidth;
			var maxY = window.innerHeight-207;
			
		  	$("#tweet1").css({left: rand(0,parseInt(maxX/2))+"px", top: rand(50,maxY)+"px", opacity:0});	
		  	$("#tweet2").css({left: rand(0,parseInt(maxX/4))+"px", top: rand(100,maxY)+"px", opacity:0});	
		  	$("#tweet3").css({left: rand(0,parseInt(maxX/5))+"px", top: rand(200,maxY)+"px", opacity:0});
		  	$("#tweet4").css({left: rand(0,parseInt(maxX/6))+"px", top: rand(350,maxY)+"px", opacity:0});	
			$("#tweet5").css({left: rand(0,parseInt(maxX/3))+"px", top: rand(400,maxY)+"px", opacity:0});	  		  	
		  	
		  	if (rand(0,3) > 2)
		  	{	
			  	var minLeft = $("#tweet1").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;	
			  	var length = rand(8,25)*1000;
			  	$("#tweet1").animate({ opacity: 0.9}, { queue:false, duration: length } )
			  		.animate({ left: rand(minLeft,maxX)+"px"}, length - 200 )
			  		.animate({ opacity: 0}, 200 );
		  	}
		  	
		  	if (rand(0,3) > 2)
		  	{		  	
			  	var minLeft = $("#tweet2").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;		
			  	var length = rand(5,15)*1000;
			  	$("#tweet2").animate({ opacity: 0.95}, { queue:false, duration: length } )
			  		.animate({ left: rand(minLeft,maxX)+"px"}, length - 200 )
			  		.animate({ opacity: 0}, 200 );
		  	}	
		  	var minLeft = $("#tweet3").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;		
		  	var length = rand(4,12)*1000;
		  	$("#tweet3").animate({ opacity: 0.85}, { queue:false, duration: length } )
		  		.animate({ left: rand(minLeft,maxX)+"px"}, length - 200 )
		  		.animate({ opacity: 0}, 200 );	 
		  		
	
		  			  		
		  	var minLeft = $("#tweet4").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;	
		  	var length = rand(5,15)*1000;
		  	$("#tweet4").animate({ opacity: 0.95}, { queue:false, duration: length } )
		  		.animate({ left: rand(minLeft,maxX)+"px"}, length - 200 )
		  		.animate({ opacity: 0}, 200 );
		  		
		  	var minLeft = $("#tweet5").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;	
		  	var length = rand(5,15)*1000;
		  	$("#tweet5").animate({ opacity: 0.95}, { queue:false, duration: length } )
		  		.animate({ left: rand(minLeft,maxX)+"px"}, length - 200 )
		  		.animate({ opacity: 0}, 200, runIt );		  		 		
		  			  				  			  			  			  				      
		}
		
		
		
		function runIt2() {
			var maxX = window.innerWidth;
			var maxY = window.innerHeight-207;
		
		
		
		  	$("#tweet6").css({left: rand(0,parseInt(maxX/3))+"px", top: rand(80,maxY)+"px", opacity:0});	
				  		
		  	var minLeft = $("#tweet6").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;	
		  	var length = rand(5,20)*1000;
		  	$("#tweet6").animate({ opacity: 0.97}, 300 )
		  		.animate({ left: rand(minLeft,maxX)+"px"}, length )
		  		.animate({ opacity: 0}, 200, runIt2 );
		  					  			  			  			  				      
		}	
		
		function runIt3() {
			var maxX = window.innerWidth;
			var maxY = window.innerHeight-207;
			
		  	$("#bird1").css({left: rand(0,parseInt(maxX/2))+"px", top: rand(80,maxY)+"px", opacity:0});	
				  		
		  	var minLeft = $("#bird1").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;	
		  	var length = rand(1,5)*1000;
		  	$("#bird1").animate({ opacity: 0.77}, 300 )
		  		.animate({ left: rand(minLeft,maxX)+"px"}, length )
		  		.animate({ opacity: 0}, 200);
		  		
		  	$("#bird2").css({left: rand(0,parseInt(maxX/2))+"px", top: rand(80,maxY)+"px", opacity:0});	
				  		
		  	var minLeft = $("#bird2").css("left"); minLeft = minLeft.replace("px",""); minLeft = parseInt(minLeft) + 1;	
		  	var length = rand(5,30)*1000;
		  	$("#bird2").animate({ opacity: 0.67}, 300 )
		  		.animate({ left: rand(minLeft,maxX)+"px"}, length )
		  		.animate({ opacity: 0}, 200, runIt3 );		  			  		
		  					  			  			  			  				      
		}	
		
		
		
		runIt(); 
		runIt2();
		runIt3();
		
				  			  		 		
		 			  	
});
	
