var startingImage = 0;

jQuery(document).ready(homepageInit);

function homepageInit(){
	gallerySetup();
	accordionSetup();
	calendarSetup();
}

function gallerySetup(){
	var numOfImages = jQuery("#photo-rotator .image-container").size();
	for(var i=1; i<=numOfImages; i++){
		jQuery("#square-indicator").append("<li>Image "+i+"</li>");
	}
	if(numOfImages > 0){
		jQuery("#square-indicator li").click(function(){
			var squareIndex = jQuery(this).index();
			if(!jQuery("#photo-rotator .image-container:eq("+squareIndex+")").is(":visible")){
				jQuery('#photo-rotator').cycle('stop');
				jQuery("#photo-rotator .image-container:visible").fadeTo(600, 0, function(){jQuery(this).hide();});
				jQuery("#photo-rotator .image-container:eq("+squareIndex+")").fadeTo(600, 1, function(){jQuery(this).show();});
				jQuery("#square-indicator .at").removeClass("at");
				jQuery(this).addClass("at");
			}
		});
	}

	jQuery('#photo-rotator').cycle({
		fx		: 	'fade',
		speed	: 	600,
		timeout	:	7000,
		after	:   function(){
			jQuery("#square-indicator .at").removeClass("at");
			jQuery("#square-indicator li:eq("+startingImage+")").addClass("at");
			startingImage++;
			if(startingImage > numOfImages-1)
				startingImage = 0;
		}
	});
}

function accordionSetup(){
	jQuery("#accordion-container").accordion({ autoHeight: false }); 
}

function calendarSetup(){
	jQuery("#wp-calendar a").each(function(){
		var content = jQuery(this).html();
		jQuery(this).replaceWith(content);
	});
}
