
//function for auto rotate images
function image_rotate()
{
	$("#media_rotator_thumbs li").each(function(count)
	{
		if($(this).hasClass('current_image'))
		{
			$('#media_rotator_thumbs a:eq(' + count + ')').trigger('click');
			alert($(this).children("a").get(0).attr("href"));

		}
	});
}

$(document).ready(function(){

	// preload gallery images
	preload_images(
		"/api/images/gallery/media_rotator_featured_video.jpg",
		"/api/images/gallery/media_rotator_featured_photo.jpg",
		"/api/images/gallery/media_rotator_testimonials.jpg",
		"/api/images/gallery/media_rotator_featured_performance.jpg",
		"/api/images/gallery/media_rotator_hotel_media.jpg"
		);



	// set bg opacity on photo caption
	$("#media_rotator_caption_bg").css("opacity",0.8);

	// on click on gallery thumbnail, load caption title and content
	$("#media_rotator_caption h3").text($("#media_rotator_thumbs a").attr("name"));
	$("#media_rotator_caption p").text($("#media_rotator_thumbs a").attr("title"));

	// on click on gallery thumbnail, load large img in gallery frame
	$("#media_rotator_thumbs a").click(function(){
		//remove the current "current_image" class and add it to the clicked one
		$("#media_rotator_thumbs li.current_image").removeClass('current_image');
		$(this).parent("li").addClass('current_image');
		var largePath = "/api/images/gallery/" + $(this).attr("id") + ".jpg";
		var largeAlt = $(this).attr("name");
		$("#large_img").attr({ src: largePath, alt: largeAlt });

		$("#large_img").parent('a').attr("href", $(this).attr("href"));

		// on click on gallery thumbnail, load caption title and content
		$("#media_rotator_caption h3").text($(this).attr("name"));
		$("#media_rotator_caption p").text($(this).attr("title"));
		return false;
	});

	//set class of first image by default
	$("#media_rotator_thumbs li:eq(0)").addClass('current_image');

	//create beat for auto rotating banner
	$.create_beat('media_rotator_thumbs', 5000, function()
	{
		var new_image = 0;
		$("#media_rotator_thumbs li").each(function(count)
		{

			if($(this).hasClass('current_image'))
			{
				new_image = count + 1;
				$("#media_rotator_thumbs li.current_image").removeClass('current_image');
			}
		});

		if(new_image > 4)
		{
			new_image = 0;
		}

		$('#media_rotator_thumbs a:eq(' + new_image + ')').trigger('click');

	});


	// launch fadebox
	$(".open_gallery").each(function()
	{
		$(this).fade_box({
			width:800,
			height:500,
			fade_width:15,
			fade_height:15,
			enable_fade:true,
			fade_click_close:false/*,
			wrapping_class: 'fade_box_media'*/
		});
	});


});
