function getRandomPerson(){
	var randomUrl = '';
	randomUrl = Math.floor(Math.random()*9);
	var person = "";
	
	switch(randomUrl){
		case 1 :
		person = "http://search.twitter.com/search.json?q=from%3Avincecurve&rpp=5&callback=?";
		break;
		case 2 :
		person = "http://search.twitter.com/search.json?q=from%3Asethcurve&rpp=5&callback=?";
		break;
		case 3 :
		person = "http://search.twitter.com/search.json?q=from%3Aamycurve&rpp=5&callback=?";
		break;
		case 4 :
		person = "http://search.twitter.com/search.json?q=from%3Atomcurve&rpp=5&callback=?";
		break;
		case 5 :
		person = "http://search.twitter.com/search.json?q=from%3Aashleycurve&rpp=5&callback=?";
		break;
		case 6 :
		person = "http://search.twitter.com/search.json?q=from%3Asakocurve&rpp=5&callback=?";
		break;
		case 7 :
		person = "http://search.twitter.com/search.json?q=from%3Achriscurve&rpp=5&callback=?";
		break;
		case 8 :
		person = "http://search.twitter.com/search.json?q=from%3Achriscurve&rpp=5&callback=?";
		break;
		default:
		person = "http://search.twitter.com/search.json?q=from%3Acharliecurve&rpp=5&callback=?";
	}
	
	return person;
}
function la_Tweet(){
	
	$.getJSON('http://search.twitter.com/search.json?q=from%3Acurvedetroit&rpp=5&callback=?', function(json){
		$("#tweetTweet").html('');
		var i = 0;
		var imageUrl = "";
		var user = "";
		var tweet = "";
		var idForURL = "";
		
		if(json.results.length < 1){
			//clearTimeout(tweetTimer);
			la_Tweet();
			return false;
		}
		
		for(i; i < json.results.length; i++){
			if(!json.results[i].to_user){
				$("#tweetTweet").fadeOut('fast');
				user = json.results[i].from_user;
				//tempImageUrl = json.results[i].profile_image_url;
				//imageUrl = tempImageUrl.replace('normal','bigger');
				imageUrl = json.results[i].profile_image_url;
				tweet = json.results[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'" target="_blank">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return '<a href="http://www.twitter.com/'+F+'" target="_blank">'+F+"</a>"});
				idForURL = json.results[i].id_str;
				$("#tweetTweet").prepend('<div style="clear:both;"><a href="http://twitter.com/'+user+'" target="_blank"><img style="float:left;margin:15px 12px 15px 0;" src="'+imageUrl+'" alt="Read our Tweets" title="Read our Tweets" width="48" height="48"/></a><p style="padding-top:15px;"><a href="http://twitter.com/'+user+'" title="Read our Tweets" target="_blank">@'+user+':</a> '+tweet+' - <a href="http://twitter.com/#!/'+user+'/status/'+idForURL+'" title="Read our Tweets" target="_blank">read it on twitter</a></p></div>').fadeIn('slow');
				break;
				
			}
			
		}
		
	});
	
	//la_Tweet2();			
}
function la_Tweet2(){
	
	var person = getRandomPerson();
	
	$.getJSON(person, function(json){
		
		var i = 0;
		var imageUrl = "";
		var user = "";
		var tweet = "";
		var idForURL = "";
		
		if(json.results.length < 1){
			//clearTimeout(tweetTimer);
			la_Tweet2();
			return false;
		}
		
		for(i; i < json.results.length; i++){
			if(!json.results[i].to_user){
				user = json.results[i].from_user;
				//tempImageUrl = json.results[i].profile_image_url;
				//imageUrl = tempImageUrl.replace('normal','bigger');
				imageUrl = json.results[i].profile_image_url;
				tweet = json.results[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'" target="_blank">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return '<a href="http://www.twitter.com/'+F+'" target="_blank">'+F+"</a>"});
				idForURL = json.results[i].id_str;
				$("#tweetTweet").append('<div style="clear:both;"><a href="http://twitter.com/'+user+'" target="_blank"><img style="float:left;margin:15px 12px 15px 0;" src="'+imageUrl+'" alt="Read our Tweets" title="Read our Tweets" width="48" height="48"/></a><p style="padding-top:15px;"><a href="http://twitter.com/'+user+'" title="Read our Tweets" target="_blank">@'+user+':</a> '+tweet+' - <a href="http://twitter.com/#!/'+user+'/status/'+idForURL+'" title="Read our Tweets" target="_blank">read it on twitter</a></p></div>').fadeIn('slow');
				break;
				
			}
			
		}
		
		//la_Tweet3(person,idForURL);
		
	});			
}

function la_Tweet3(person,idTest){
	
	var randomPerson = getRandomPerson();
	
	if(randomPerson == person){
		la_Tweet3(person,idTest);
		return false;
	}
	
	$.getJSON(randomPerson, function(json){
		
		var i = 0;
		var imageUrl = "";
		var user = "";
		var tweet = "";
		var idForURL = "";
		
		if(json.results.length < 1){
			//clearTimeout(tweetTimer);
			la_Tweet3(person,idTest);
			return false;
		}
		
		for(i; i < json.results.length; i++){
			if(!json.results[i].to_user){
				if(idTest == json.results[i].id){
					break;
				}
				user = json.results[i].from_user;
				//tempImageUrl = json.results[i].profile_image_url;
				//imageUrl = tempImageUrl.replace('normal','bigger');
				imageUrl = json.results[i].profile_image_url;
				tweet = json.results[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,function(F){return'<a href="'+F+'" target="_blank">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,function(F){return '<a href="http://www.twitter.com/'+F+'" target="_blank">'+F+"</a>"});
				idForURL = json.results[i].id_str;
				$("#tweetTweet").append('<div style="clear:both;"><a href="http://twitter.com/'+user+'" target="_blank"><img style="float:left;margin:15px 12px 15px 0;" src="'+imageUrl+'" alt="Read our Tweets" title="Read our Tweets" width="48" height="48"/></a><p style="padding-top:15px;"><a href="http://twitter.com/'+user+'" title="Read our Tweets" target="_blank">@'+user+':</a> '+tweet+' - <a href="http://twitter.com/#!/'+user+'/status/'+idForURL+'" title="Read our Tweets" target="_blank">read it on twitter</a></p></div>').fadeIn('slow');
				break;
				
			}
			
		}
		
	});
	//var height = $('#tweetTweet').height();
	//$('#tweetWrapper').height(height);		
}
$(function(){
	la_Tweet();
});
