/*
jTwitter.js V3+ (jQuery+rotate)
Revision 1 (30-05-2011)
© Webspacedesign (www.webspacedesign.nl)


options:
- username (required): username on twitter
- limit (optional): maximum number of tweets, default is 1 (integer)
- rotate (optional): rotate through the tweets, default is false (boolean)
- interval (optional): interval for the rotate function in milliseconds, default is 5000 (integer)
- parseURL (optional): parse URL's in tweets, default is true (boolean)
- parseUsername (optional): parse usernames in tweets, default is true (boolean)
- parseHashtag (optional): parse hashtags in tweets, default is true (boolean)
*/


jQuery.fn.wsd_twitter = function(options) {

	var wrapper = $(this[0]).html("");

	if(options.parseURL === undefined) options.parseURL = true;
	if(options.parseUsername === undefined) options.parseUsername = true;
	if(options.parseHashtag === undefined) options.parseHashtag = true;

	$.getJSON("http://twitter.com/status/user_timeline/"+options.username+".json?count="+(!options.limit ? 1 : options.limit)+"&callback=?",function(data) {
		for(var i=0; i<data.length; i++) {
			text = data[i].text;

			if(options.parseURL) {
				text = text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(url) {
					return url.link(url);
				});
			}

			if(options.parseUsername) {
				text = text.replace(/[@]+[A-Za-z0-9-_]+/, function(u) {
					var username = u.replace("@","")
					return u.link("http://twitter.com/"+username);
				});
			}

			if(options.parseHashtag) {
				text = text.replace(/[#]+[A-Za-z0-9-_]+/, function(t) {
					var tag = t.replace("#","%23")
					return t.link("http://search.twitter.com/search?q="+tag);
				});
			}

			wrapper.append("<div style=\"font-size: 10px; \">"+text+"</div>");
		}

	});
};
