
(function($){
	var current=null;
	$.fn.rssfeed=function(url,options){
		var defaults={limit:10,header:true,titletag:'h4',date:true,content:true,snippet:true,showerror:true,errormsg:'',key:null};
		var options=$.extend(defaults,options);
		return 	this.each(function(i,e){
			var $e=$(e);
			if(!$e.hasClass('rssFeed'))$e.addClass('rssFeed');
			if(url==null)return false;
			var api="http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q="+url; if(options.limit!=null)api+="&num="+options.limit;if(options.key!=null)api+="&key="+options.key;
			$.getJSON(api,function(data){if(data.responseStatus==200){_callback(e,data.responseData.feed,options);}else{if(options.showerror)
if(options.errormsg!=''){var msg=options.errormsg;}else{var msg=data.responseDetails;};$(e).html('<div class="rssError"><p>'+msg+'</p></div>');};});});};var _callback=function(e,feeds,options){if(!feeds){return false;}
var html='';var row='odd';
if(options.header)
html+='<div class="rssHeader">'+'<a href='+feeds.link+'" title="'+feeds.description+'">'+feeds.title+'</a>'+'</div>';
html+='<div class="rssBody">'+'<ul>';

for(var i=0;i<feeds.entries.length;i++){
	var entry=feeds.entries[i];
	var entryDate=new Date(entry.publishedDate);
	var m_names = new Array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
	var curr_date = entryDate.getDate();
	var curr_month = entryDate.getMonth();
	var curr_year = entryDate.getFullYear();
	var curr_hour = entryDate.getHours();
	var curr_min = entryDate.getMinutes();
	curr_min = curr_min + "";
	if (curr_min.length == 1){  curr_min = "0" + curr_min }
	var currentDate=new Date();
	var currentYear = currentDate.getFullYear();
	if (currentYear == curr_year){curr_year = "" }
	var pubDate = curr_date+" "+ m_names[curr_month] +" "+curr_year+" в "+curr_hour+":"+curr_min;

html+='<li class="imgList rssRow '+row+'">';
if(options.date)html+='<div class="date">'+pubDate+'</div>'

var findFacebook = entry.link.search(/facebook.com/i);
if (findFacebook != 11){ var facebookURL = "http://facebook.com"  }else{facebookURL = "" }
html+='<'+options.titletag+'><a href="'+facebookURL+entry.link+'" title="'+feeds.title+'">'+entry.title+'</a></'+options.titletag+'>'

if(options.content){if(options.snippet&&entry.contentSnippet!=''){var content=entry.contentSnippet;}else{var content=entry.content;}
html+='<p>'+content+'</p>'}
html+='</li>';if(row=='odd'){row='even';}else{row='odd';}}
html+='</ul>'+'</div>'
$(e).html(html);};})(jQuery);

