/**

AtomWorks Javascript

jQuery powered Twitter Feed outputter. 

v.0.2

**/

/** CONFIGURATION **/

//var twitterFeed = 'twitterSample.xml' ;
var twitterFeed = 'http://twitter.com/status/user_timeline/atomworks.json?count=3&callback=?' ;

// Tool Tips Setup

var useToolTips = 1 ; // 0 = Off - 1 = On
var ToolTipClass = '.TBWhatIs' ; // Class used that triggers tips







/** Functions **/

function latestTwitter(){
	
	if(useToolTips==1){ tooltip(ToolTipClass) ; } ;
	
	$.getJSON(twitterFeed, function(data){
				
				var desc ;
				var date ;
				
				desc = data[0].text ;
				date = data[0].created_at ;
				
				$("#TBDesc").append(desc) ;
				$("#TBDate").append(date) ;
				
	}) ;
	
}

/** Uses this code pasted into template - Commented TBWhatIs class div used for tooltips and requires tooltips script -->

<div id="aw-twitter"><div class="awTwitterBox"><div class="TBLogo"></div><!--<div class="TBWhatIs"><img class="trigger" src="images/qm.png"><div class="popup"><p>Twitter integration can be used to keep visitors up to date on news, special offers or just to say hello!</p></div>--></div><div class="TBDDWrap"><div class="TBDesc" id="TBDesc"></div><div class="TBDate" id="TBDate"></div></div></div></div>

**/
/**

AtomWorks Javascript

jQuery powered Twitter Feed outputter. 

v.0.1

**/

/** CONFIGURATION **/

//var twitterFeed = 'twitterSample.xml' ;
var twitterFeed = 'http://twitter.com/status/user_timeline/atomworks.json?count=3&callback=?' ;





/** Functions... do not edit! **/


function latestTwitter(){
	
	jQuery.getJSON(twitterFeed, function(data){
				
				var desc ;
				var date ;
				
				desc = data[0].text ;
				//desc = data[0].user.screen_name + ": " + data[0].text ;
				
				date = relative_time(data[0].created_at) ;
				
				jQuery("#TBDesc p").append(desc) ;
				jQuery("#TBDate").append(date) ;
				
				
	}) ;
				
}

// 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 {
			
		return "Posted: " + C ;
		//return(parseInt(E/86400)).toString()+" days ago"
	
	}
				
				
			
		
	
};



