/*
 * Show your last tweet in real time
 * 
 * http://www.position-absolute.com
 *
 * Copyright (c) 2009 Cedric Dugas
 * Licensed under the MIT license.
 */
	$(document).ready(function() {
		tweetInterval("abettermobileweb")	// Start tweet funciton parameter: twitter username
		 
	});		
	function tweetInterval(twitterName){
		var lastTweet
		// TWEET STYLE
		tweetStyle  =  "<style>\
		#lastTweet:hover{background-color:#222;border:2px solid #fff;}\
		#lastTweet span{display:block;font-size:11px;padding-top:3px;}\
		#lastTweet{position:fixed;\
		top:30px;\
		right:30px;\
		width:200px;\
		z-index:999;\
		background-color:#363636;\
		background-image:url('http://www.position-absolute.com//wp-content/themes/default/images/twitterbird.png');\
		background-position:bottom right;\
		background-repeat:no-repeat;\
		border:2px solid #aaa;\
		color:#fff;\
		border-radius:5px;\
		-webkit-border-radius:5px;\
		-moz-border-radius:5px;\
		box-shadow:0px 0px 8px #000;\
		-webkit-box-shadow:0px 0px 8px #000;\
		-moz-box-shadow:0px 0px 8px #000;\
		text-decoration:none;\
		font-family:helvetica,arial;\
		font-size:12px;\
		padding:8px;\
		padding-right:43px;\
		min-height:64px;}\
		</style>"

		$("head").append(tweetStyle)			// APPLY TWEET TO THE BODY
		 $("body").append('<div id="twitter_script"></div>')
		 setInterval("createJSONtweet('"+twitterName+"')",30000)
		 setTimeout("createJSONtweet('"+twitterName+"')",10000)
		 
		 twitterCallback2 = function(tweet) {		// FUNCTION CALLED WHEN TWITTER SCRIPT IS PARSED
		 	if(tweet){
			 	var updateTweet = tweet.results[0].text		// Tweet text
			 	var updateTweetUser = tweet.results[0].from_user
		 	}
			if(lastTweet != updateTweet){ 				// CREATE AND ANIMATE TWEET
				if(lastTweet){	
					var tweetAppend = '<a target="_blank" href="http://www.twitter.com/'+twitterName+'" id="lastTweet"><strong>'+updateTweetUser+' just tweeted:</strong><span>'+updateTweet+'</span></a>'
					$("body").append(tweetAppend)
					$("#lastTweet").css("opacity",0)
					lastTweet = updateTweet
					$("#lastTweet").animate({opacity:0.95},function(){
						setTimeout('fadeTweetOut()',15000)
					})
					fadeTweetOut = function(){
						$("#lastTweet").animate({opacity:0},function(){
							$("#lastTweet").remove()
						})
					}
				}else{
					lastTweet = updateTweet
				}
			}
		 }
		createJSONtweet = function(twitterName){		// PARSE twitter SCRIPT GET CALLBACK FUNCTION AND JSON 	
			 var getTweet = document.createElement("script");
			 getTweet.src="http://search.twitter.com/search.json?q="+twitterName+"&callback=twitterCallback2&rpp=3";
			 document.getElementById('twitter_script').appendChild(getTweet)
		 }
	}