/*!
 * jQuery Twitter plug-in
 * Created by Leonard Burton with code adapted from the Twitter HTML widget.
 *
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *
 * Date: Wed July 27 12:30 2011
 */


/**
*	Config - Edit!
**/

username = "unltdpotential" ;
count = '3' ;

/**
*	Functions - Do not edit!
**/

// Edit me.
var twitterFeed = 'http://twitter.com/status/user_timeline/'+username+'.json?count='+count+'&callback=?' ;

function makeurl(text){
	textb = text + ' ' ;
	return textb.replace(/(((http\:\/\/)|(www\.)).*(?=[^\.\w\d\/]))/gm,'<a href="$1" target="_blank">$1</a>');

}


function latestTwitter(){
	jQuery.get('http://www.unlimitedpotential.co.uk/index.php/ajax/etweets', function(data){
			jQuery("#tweet-copy ul").html(data);
			jQuery("#tweet-copy").find('li:eq(0)') ;
			jQuery("#tweet-copy").find('li:eq(1)').fadeTo(100,0) ;
			jQuery("#tweet-copy").find('li:eq(2)').fadeTo(100,0) ;
			rotateTweets();
	}) ;			
}

function rotateTweets(){
	//shownTweet = 1;
	rotateMech(1);
	
	$('#tweet-copy').hover(function(){
		clearInterval(tweetInterval);
	},function(){
		rotateMech(1);
	})
	
}
function rotateMech(st){

	shownTweet = st;
	
	tweetInterval = setInterval(function(){
		
		if(shownTweet == 1){
			$('#tweet-copy ul').animate({top: '-68px'}, 1000).find('li:eq(0)').fadeTo(1000,0);
			$('#tweet-copy ul').find('li:eq(1)').fadeTo(1000,1)
			shownTweet = 2 ;
		} else if(shownTweet == 2){
			$('#tweet-copy ul').animate({top: '-150px'}, 1000).find('li:eq(1)').fadeTo(1000,0);
			$('#tweet-copy ul').find('li:eq(2)').fadeTo(1000,1);
			shownTweet = 3 ;
		} else if(shownTweet == 3){
			$('#tweet-copy ul').animate({top: '10px'}, 1000).find('li:eq(2)').fadeTo(1000,0);
			$('#tweet-copy ul').find('li:eq(0)').fadeTo(1000,1);
			shownTweet = 1 ;
		}
	
	
	},5000);
}


// Changes the time into a more friendly reference. NOTE: This was adapted from the Twitter html widget

function relative_time(C){
          
	var B=C.split(" ");
	C=B[1]+" "+B[2]+", "+B[5]+" "+B[3];

	var A=Date.parse(C);
	var D=(arguments.length>1)?arguments[1]:new Date();
	var E=parseInt((D.getTime()-A)/1000);
	E=E+(D.getTimezoneOffset()*60);

	if(E<5){
		
		return "Less then 5 seconds ago" ;
	
	}else if(E<10){
		
		return "Less then 10 seconds ago" ;
	
	}else if(E<20){
		
		return "Less then 20 seconds ago" ;
	
	}else if(E<30){
		
		return "Less then half a minute ago" ;
	
	}else if(E<45){
		
		return "Less then 45 seconds ago" ;
	
	}else if(E<60){
		
		return "less then a minute ago" ;
	
	}else if(E<120){
			
		return "about a minute ago" ;
			
	}else if(E<(60*60)){
			
		return(parseInt(E/60)).toString()+" minutes ago" ;
	
	}else if(E<(120*60)){
				
		return "about an hour ago" ;
				
	}else if(E<(24*60*60)){
		
		return "about "+(parseInt(E/3600)).toString()+" hours ago" ;
				
	} else if(E<(48*60*60)){
				
		return "1 day ago" ;
				
	} else {
		
		if(parseInt(E/86400) > 7){
			return C ;
		} else {
			return(parseInt(E/86400)).toString()+" days ago" ;
		}
	
	}
				
				
			
		
	
};


