/**
 * CJ Latest News - get latest news
 *
 * Copyright (c) 2011 Creative Jar
 *
 * Version 0.1
 *
 */

(function ($) {

	jQuery.fn.cjLatestNews = function (options) {
	    options = $.extend({
	        destinationURL: 'http://www.pearsoncpl.com/feed/rss/'
	    }, options || {});
	
	    return this.each(function () {
	    	var oElement = $(this), 
	    	tUrl = 'http://twitter.creative-jar.ru/rss.php?callback=?&url=' + encodeURI(options.destinationURL);
	    	
	    	$.getJSON(tUrl, function(data) {
	    		$('li.loading', oElement).remove();
	    		$.each(data, function(index, newsItem) {
	    			var item = '<li><a href="' + newsItem.link + '">' + newsItem.title + '</a></li>';
	    			$('ul', oElement).prepend(item);
	    		});
	    		
	    		if($(oElement).attr("data-scroll") == "true") {
	    			$(oElement).cjInnerScroll();
	    		}
	    	});
	    });
	};
	
})(jQuery);
