// blog feed code
function prepDescription(text) {
	text = text.replace(/<script[^>]*>([\s\S]*)<\/script>/ig,"");
	text = text.replace(/(<([^>]+)>)/ig,"");
	text = text.substr(0, text.indexOf(' ',80))+'... ';
	return text;
}
jQuery(document).ready(function(){
	jQuery.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20title%2Cdescription%2Clink%2CpubDate%20from%20feed(0%2C5)%20where%20url%3D'http%3A%2F%2Fblog.spiritclips.com%2Ffeed%2F'&format=json&callback=?",
		function(data){
			if ( ! (data && data.query && data.query.results && (items = data.query.results.item))) {
				// Unexpected response from YQL service
				return;
			}
			jQuery.each(items, function(index, item){
				var tpl = '<li><a class="posttitle" href="%link" target="_blank">%title</a><span class="description">%extract<a href="%link">read more &gt;</a></span></li>';
				var html = tpl.replace(/%link/g, item.link)
						  .replace(/%title/g, item.title)
						  .replace(/%extract/g, prepDescription(item.description) );
				// item.pubDate
				jQuery('#blogentries').append(html);
			});
			jQuery('#blogfeed').show().trigger('contentLoaded');
		}
	);
});
