
//http://slonik.eu/blog/?feed=rss2

jQuery(document).ready(function() {
	function dat(dat) {
		return String(dat.getDay()).replace(/^(\d)$/, '0$1') + "-" + dat.getMonth() + '-' + dat.getFullYear() +
			' ' + dat.getHours() + ":" + dat.getMinutes();
	}
	function tpl(title, link, pubDate) {
		return '<div class="post">' +
			'<p class="content"><a href="' + link + '" '+
				'title="'+title+" (" + dat(pubDate) + ')">' + title + '</a></p>' +
			'</div>';
	}

	jQuery.get("blog/", {feed:"rss2"}, function(msg) {
		var html = [];
		var items = jQuery('item', msg);
		items.slice(0,8).each(function() {
			var link = jQuery('link', this).text();
			var title = jQuery('title', this).text();
			var pubDate = new Date(jQuery('pubDate', this).text());
			html.push(tpl(title, link, pubDate));
		});
		html = '<div class="blog"><h5>Ostatnio na blogu</h5>'+html.join('')+"</div>";
		jQuery('body section').before(html);
	});

});

