(function($) {

	$.rss = function(o) {
		o = $.extend({}, $.rss.defaults, o || {});
		if(o.urlCode && $.rss.urls[o.urlCode]) o.url = $.rss.urls[o.urlCode];
		$.get(o.url, function(data) {
			var items = [];
			$data = $(data);
			$.each($data.find("item"), function(i) {
				$this = $(this);
				if(i >= o.maxItems) return false;
				items.push({
					title: $this.find("title").text(),
					link: $this.find("link").text(),
					guid: $this.find("guid").text(),
					category: $this.find("category").text(),
					date: $this.find("pubDate").text().substring(5, 16),
					time: $this.find("pubDate").text().substring(17, 22),
					description: $this.find("description").text()
				});				
			});
			o.callback.call(o.scope, items);
		});
	};	
	
	$.rss.urls = {
		tg24: "/rss/tg24.xml",
		mag: "/rss/mag.xml",
		sport: "/rss/sport.xml"
	};
	
	$.rss.defaults = {
		maxItems: 15,
		url: $.rss.urls.tg24,
		urlCode: null,
		callback: null,
		scope: window
	};	

})(jQuery)

