function theRotator() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',4000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

jQuery(document).ready(function($) {
	theRotator();
	
	jQuery.fn.modal = function() {
		return this.each(function(){
		var ah = $(this).height();
	        var wh = $(window).height();
			var dh = $(document).height();
	        var nh = (wh - ah)/2;
	 
	        var aw = $(this).width();
	        var ww = $(window).width();
	        var nw = (ww - aw)/2;
	 
	        // Trim body height, append overlay, and disable scrolling (this can be undone with a custom close button)
	        $("body").append('<div class="overlay"><\/div>');
	        $(".overlay").height(dh).css('overflow','hidden').fadeTo("slow", .8);
	        $(this).css({'top':nh, 'left':nw}).fadeIn("slow");
		});
	};

	$(".home-post .post").hover(
		function(){
			$(this).css({"cursor":"pointer", "background-color":"#60471c"});
		},
		function(){
			$(this).css({"background-color":"#81693E"});
		}
	);
	$('.home-post .post').click(function() {window.location=$(this).find("a").attr("href");});
	
	/*$(".calendar").click(function(){
		$(".modal .inner").load("/events #calendar_wrapLarge");
		$(".modal").modal();
		return false;
	});*/
	$(".contact").click(function(){
		$(".modal .inner").load("/contact #contact");
		$(".modal").modal();
		return false;
	});
	
	$(".close, .overlay").click(function(){
		$(".modal, .overlay, .modal_home").fadeOut("slow");
	});
	$(".close_video").click(function(){
		$("#player").empty();
		$("#player").css("display" , "0");
	});
});