(function($) {
	$.fn.twitterFeed = function(options) {
		var twitter = $.extend({}, $.fn.twitterFeed.defaults, options);
		
		// Hide on start
		$(this).hide();
		
		// Create heading parameter
		if (twitter.showHeading) {
			// Append Heading
			$(this).append('<h4>'+twitter.headingText+'</h4>');
		}
		
		// Append Tweets
		$(this).append('<ul id="feedTweets"><li></li></ul>');
		
		// Hide Tweets
		$("ul#feedTweets").hide();
		
		// Create preloader and append it
		var preLoad = $('<p id="'+twitter.preloaderId+'">'+twitter.loaderText+'</p>');
		$(this).append(preLoad);
		
		// Create profile link parameter
		if (twitter.showProfileLink) {
			// Append profile link
			$(this).append('<a id="profileLink" href="http://twitter.com/'+twitter.userName+'">http://twitter.com/'+twitter.userName+'</a>');
		}
		
		// Create a click listener
		$('a#profileLink').click(function(){
			window.open(this.href);
			return false;
		});
		
		// Show this
		$(this).show();
		
		
		var getheight = function() { 
		
			var twitterContainerHeight = $("#recentTwitterPosts").height();
			var twitterPostHeight = $("#recentTwitterPosts ul#feedTweets").height();

			console.log(twitterContainerHeight, twitterPostHeight);
		
		}
		
		// Get the twitter information to be displayed
		$.getScript("http://twitter.com/statuses/user_timeline/"+twitter.userName+".json?callback=twitterCallback2&count="+twitter.numTweets, function(data, getheight) {
			
			// Removove the preLoad variable
			$(preLoad).remove();
			
			// Create sliding boolean parameter
			if (twitter.slideIn) {
				// Slide the ul down on load if true
				$("ul#feedTweets").slideDown(1000);
			}
			else {
				// Just show the ul if set to false
				$("ul#feedTweets").show();
			}
			
			// Add class of firstTweet to beginning of ul
			$("ul#feedTweets li:first").addClass("firstTweet");
			
			// Add class of lastTweet to end of ul
			$("ul#feedTweets li:last").addClass("lastTweet");
		});
	};
	
	$('a#profileLink').click(function(){
		window.open(this.href);
		return false;
	});
	
	// Default Plugin Parameters
	$.fn.twitterFeed.defaults = {
		userName: null,
		numTweets: 5,
		preloaderId: "preloader",
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: true,
		headingText: "Latest Tweets",
		showProfileLink: true
	};
})(jQuery);