/*
* tweetable 1.6 - jQuery twitter feed generator plugin
*
* Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* With modifications from Philipp Robbel (http://www.robbel.com/) and Patrick DW (stackoverflow)
* for IE compatibility.
*
* And further modifications by engage interactive
*
* Revision: $Id: jquery.tweetable.js 2011-01-06 $ 
*
*/

(function($){

	//define the tweetable plugin
	$.fn.tweet = function(options){

		//specify the plugins defauls
		var defaults = {
			limit: 2,					//number of tweets to show
			username: 'stradatweet',    //@username tweets to display
			replies:false		
		};

		//overwrite the defaults
		var options = $.extend(defaults, options);
		
		//loop through each instance
		return this.each(function (options) {
		
			//assign our initial vars
			var act = $(this);
			var $tweetList;
			var tweetMonth = '';
			var shortMonths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
			var api = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=";
			var count = "&count=100";
			var oddEven = 'odd';
			
			//do a JSON request to twitters API
			$.getJSON(api + defaults.username + count + "&include_rts=1&callback=?", act, function (data) {

				//create an unordered list to store tweets in
				$tweetList = act;
				
				// Bird html
				var bird = '<span class="birdy"></span>';
				
				var realLimit=1;
				
			
				//loop through twitters response
				$.each(data,function(i, item){
				
					if (defaults.replies === false) {
						
                        if (item.in_reply_to_status_id_str === null && realLimit<=defaults.limit ) {
                        	realLimit++;
                            $tweetList.append('<div class="tweet_content_' + i + ' ' + oddEven + '"><p class="tweet_link_' + i + '">' + item.text.replace(/#(.*?)(\s|$)/g, '<span class="hash">#$1 </span>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&">$&</a> ').replace(/@(.*?)(\:|\s|\(|\)|$)/g, '<a href="http://twitter.com/$1">@$1</a>$2') + '</p>' + bird + '</div>');
					
							oddEven = oddEven == 'even' ? 'odd' : 'even';
                        }
                    } else {
                        
                    
					
					}
				
					
					
				});

			});
			
		});

	}

})(jQuery);
