$(document).ready(function(){
	// blog, facebook, and twitter tabs
	$("ul.tabs").tabs("div.panes > div");

	// home page feature slideshow
	$(".slidetabs").tabs("div.images > div", {
		effect: 'fade',
		fadeOutSpeed: "slow",
		rotate: true
	}).slideshow({
		autoplay: true,
		interval: 6000
	});
});

// consume blog feed and insert into blog tab
function consumeBlog(json)
{
	var items = [];

	$.each(json.feed.entry, function(index, post){
		//limit the number of posts to x number
		if (index >= 5){
			return false;
		}
		
		// gather needed post data
		var rawDate = post.published.$t.substring(0, 10).split('-');
		var published = new Date(parseInt(rawDate[0]), parseInt(rawDate[1],10) - 1, parseInt(rawDate[2],10));
		
		var date = (published.getMonth() + 1) + '.' + published.getDate() + '.' + published.getFullYear().toString().substring(2);

		var title = post.title.$t;
		var href = post.link[4].href;

		var summary = $.trim($(post.content.$t).text().substring(0, 200)) + '...';

		// build HTML list of posts
		items.push('<li>' +
			'<p class="date">' + date + '</p>' +
			'<h3><a href="' + href + '">' + title + '</a></h3>' +
			'<p>' + summary + '</p>' +
			'</li>');
	});

	// append 'Read Our Blog' w/ link to blog
	items.push('<li class="more"><a href="' + json.feed.link[2].href + '">Read Our Blog</a></li>');

	// write list of posts to blog tab
	$('#blog').html($('<ul/>', { html: items.join('') }));
}

