/**
 *  Plugin which renders the YouTube channel videos list to the page
 *  @author:  H. Yankov (hristo.yankov at gmail dot com)
 *  @version: 1.0.0 (Nov/27/2009)
 *	http://yankov.us
 */

 function __jQueryYouTubeChannelReceiveData(data) {
  var link = data.feed.entry[0].id.$t;
  var codiceVideo = link.substr(43);

  $("#social-brick-content-yt").html('<iframe title="YouTube video player" width="165" height="140" src="http://www.youtube.com/embed/' + codiceVideo + '" frameborder="0" allowfullscreen></iframe>');
  
  }
 
 
				
(function($) {
$.fn.youTubeChannel = function(options) {
	var videoDiv = $(this);

	$.fn.youTubeChannel.defaults = {
		userName: null,
		loadingText: "Loading...",
		linksInNewWindow: true,
		hideVideoLength: false,
		hideFrom: true,
		hideViews: false,
		hideRating: false,
		hideNumberOfRatings: true,
		removeBordersFromImage: true
	}
			
  var  __opts = $.extend({}, $.fn.youTubeChannel.defaults, options);
	
	return this.each(function() {
		if (__opts.userName != null) {			
			
			// TODO: Error handling!
			$.getScript("http://gdata.youtube.com/feeds/base/users/" + __opts.userName + "/uploads?alt=json-in-script&callback=__jQueryYouTubeChannelReceiveData&count=1");
		}
	});
};
})(jQuery);
