// remap jQuery to $
(function($){
	
	// Copyright script - found in the plugins.js file
	// To use, replace the '#copyright' id with the
	// id of the element that holds your copyright date
	$('#copyright').copyright();
	
	// Email defuscator - found in the plugins.js file
	$('.email').defuscate();	
	
	// User defined functions go here
	$('#newsletter label, #inside label, #searchform label').inFieldLabels();
	
	$('.accordion').tabs('.accordion p',{tabs:'h4',effect:'slide',initialIndex:null});
	
	// Fill the two blog teasers with the most recent 2 entries
	$.jGFeed('http://www.beatitudehouse.com/blog/?feed=rss2',function(feeds) {
		if(!feeds) {
			var error = $('<p/>',{
				className: 'postExcerpt',
				html: 'There seems to be an error with the blog RSS feed. Please <a href="/blog/">click here to read our blog</a>.'
			});
			$('.entries').append(error);
			return false;	
		}
		
		for(var i=0;i<feeds.entries.length;i++) {
			var entry = feeds.entries[i];
			var post = $('<p/>');
			var postTitle = $('<a/>',{
				className: 'postTitle',
				href: entry.link,
				text: entry.title
			});
			var date = new Date(entry.publishedDate);
			var mos = ['January','February','March','April','May','June','July','August','September','October','November','December']
			var datestring = mos[date.getMonth()];
			datestring+=' ';
			datestring+=date.getDate();
			datestring+=', ';
			datestring+=date.getFullYear();
			datestring+=' — ';
			var hours;
			var abbrev = "AM";
			if (date.getHours()>=12) {
				var hours = parseInt(date.getHours())-11;
				datestring+=hours;
				abbrev = "PM";
			} else {
				var hours = parseInt(date.getHours())+1;
				datestring+=hours;
			}
			datestring+=':';
			if (date.getMinutes()<10) {
				datestring+='0';
				datestring+=date.getMinutes();
			} else {
				datestring+=date.getMinutes();
			}
			datestring+=' ';
			datestring+=abbrev;
			var postDate = $('<span/>',{
				className: 'postDate',
				text: datestring
			});
			var postExcerpt = $('<span/>',{
				className: 'postExcerpt',
				html: entry.contentSnippet
			});
			var moreLink = $('<a/>',{
				href: entry.link,
				text: "Read more"
			});
			var br = $('<br/>');
			postExcerpt.append(br,moreLink);
			post.append(postTitle,postDate,postExcerpt);
			$('.entries').append(post);
		}
	},2);
	
})(this.jQuery);
