/* !Begin Custom Functions */

// Define an empty function for browsers that don't support console.log
if("undefined" === typeof console) {

	console = { log: function() { } };
}

// Define custom function to return posts from a Facebook user
$.facebook = function (options, callback) {

	// Fail if the options arguemnt isn't set
	if (!options) {
		return false;
	}
	
	// Initialize variables
	var	defaultOptions	= {limit: 5, from: null},
		options			= $.extend(true, defaultOptions, options),
		url				= "http://graph.facebook.com/" + options.from + "/feed?limit=" + options.limit + "&callback=?";

	// Call Facebook JSONP
	$.getJSON(url, function (json) { 
	
		// Execute the callback
		callback(json);
	});	
};


/* End Custom Functions */

/* !Begin Event Handlers */
/* End Event Handlers */


$(document).ready(function(){

	// Display the current year in the copyright notice

	var currentYear = (new Date).getFullYear();

	$(".year").text(currentYear);

if($(".openLightbox").length){
	$(".openLightbox").colorbox({
		height:		"100%",
		iframe:		true, 
		innerWidth:	"90%"
	});
}

// Return latest 4 blog posts
        $('#footer').rssfeed('http://caoperationlifesaver.wordpress.com/?feed=rss', {
		limit: 4, header:false, date:false
	});

// Return latest tweet and post on Twitter and Facebook
	$.twitter({from: 'caoplifesaver', limit: 1, replies: false, retweets: true}, function (tweets) {

		if (0 != tweets["results"].length)
			$("div.twitter").html("<span class='tweet'>" + tweets["results"][0]["text"] + "</span><br /><a href='http://www.twitter.com/CAOpLifeSaver/status/" + tweets["results"][0]["id"] + "' target='_blank'>View on Twitter</a>");
	});

	$.facebook({from: "146896235346882", limit: 10}, function (json) {

		$("div.facebook").html("<span class='post'>" + json["data"][0]["message"] + "</span><br /><a href='http://www.facebook.com/home.php?ref=home#!/pages/California-Operation-Lifesaver/146896235346882' target='_blank'>View on Facebook</a>");
	});



});
