


//function for auto rotate images
function image_rotate() {
	
  var new_image = 0;
	
	$("#celebs_rotator_thumbs li").each(function(count){
		if($(this).hasClass('current_image')){
			new_image = count + 1;
			$("#celebs_rotator_thumbs li.current_image").removeClass('current_image');
		}
	});
	
	if(new_image > 3) {
		new_image = 0;
	}
	
	$('#celebs_rotator_thumbs a:eq(' + new_image + ')').trigger('click');
	
}





$(document).ready(function(){
	$("#large_img").css('opacity', 1);

	// set bg opacity on photo caption
	$("#celebs_rotator_caption_bg").css("opacity",0.8);

	// on click on gallery thumbnail, load caption title and content
	$("#celebs_rotator_caption h3").text($("#celebs_rotator_thumbs a").attr("rel"));
	$("#celebs_rotator_caption p").text($("#celebs_rotator_thumbs a").attr("title"));

	// on click on gallery thumbnail, load large img in gallery frame
	$("#celebs_rotator_thumbs a").click(function(){
		//remove the current "current_image" class and add it to the clicked one
		$("#celebs_rotator_thumbs li.current_image").removeClass('current_image');
		$(this).parent("li").addClass('current_image');
		var largePath = "/api/images/celebs/" + $(this).attr("id") + ".jpg";
		var largeAlt = $(this).attr("rel");
		$("#large_img").fadeOut(395);
		$('#celebs_rotator_caption_bg').hide();
		$('#celebs_rotator_caption').hide();
		setTimeout("$('#large_img').attr({ src: '" + largePath + "', alt: '" + largeAlt + "'});$('#celebs_rotator_caption h3').text('" + $(this).attr('rel') + "');$('#celebs_rotator_caption p').text('" + $(this).attr('title') + "');$.delete_beat('celebs_rotator_thumbs');$.create_beat('celebs_rotator_thumbs', 5000, image_rotate);", 395);
		setTimeout("$('#large_img').fadeIn(400);$('#celebs_rotator_caption_bg').show();$('#celebs_rotator_caption').show();$('#celebs_rotator_thumbs').hide();$('#celebs_rotator_thumbs').show();", 400);

		/*$("#large_img").hide('slide',{ direction: 'left' });
		setTimeout("$('#large_img').attr({ src: '" + largePath + "', alt: '" + largeAlt + "'});$('#large_img').show('slide',{ direction: 'dowm' });", 500);*/

		// on click on gallery thumbnail, load caption title and content
		return false;
	});

	//set class of first image by default
	$("#celebs_rotator_thumbs li:eq(0)").addClass('current_image');

	//create initial beat for auto rotating banner
	$.create_beat('celebs_rotator_thumbs', 5000, image_rotate);

	//i need to do a hide and then show in order to fix unknown bug in IE6
	$('#celebs_rotator_thumbs').hide();
	$('#celebs_rotator_thumbs').show();
	
	
	
	
	
	
	// launch fadebox
	jQuery(".open_gallery").each(function()
	{									 
		jQuery(this).fade_box({
			width:800,
			height:500,
			fade_width:15,
			fade_height:15,
			enable_fade:true,
			fade_click_close:false
		});
	});
	
	
	
	
	
});