
	
	jQuery(document).ready(
		function()
		{
			var delay_time = 5000;
			var fade_time = 600;

			var current_image = 0;
			var next_image = 1;
			var rotator_cells = jQuery("div.image_rotator");
			var number_of_images = jQuery("div.image_rotator").size();

			var interval_id;

			function go_to_image(this_image, that_image) {
				jQuery(jQuery("div.image_rotator")[that_image])
					.stop() 
					.css("display", "block")
					.animate({opacity: "1.0"}, fade_time)
					.css("z-index", "999");

				jQuery(jQuery("div.image_rotator")[this_image])
					.stop()
					.animate({opacity: 0.0}, fade_time)
					.animate({display: 'block'}, 1)
					.css("z-index","998");
			}
			
			function single_image(this_image) {
				for (i = 0; i < number_of_images; i++) {
					if (i == this_image)
						jQuery(jQuery("div.image_rotator")[this_image])
							.stop()
							.css("display", "block")
							.css("z-index", "999")
							.animate({opacity: "1.0"}, 100)
							.css("opacity", "1.0");
					else
						jQuery(jQuery("div.image_rotator")[i])
							.stop()
							.css("opacity", "0.0")
							.css("z-index", "998")
							.css("display", "none");
				}
			}
			
			function rotate_images() {
				go_to_image(current_image, next_image);
				
				current_image = (current_image + 1) % number_of_images;
				next_image = (next_image + 1) % number_of_images;
			}
			
			function pause_rotation() {
				clearInterval(interval_id);
				
				single_image(current_image);

				next_image = (current_image + 1) % number_of_images;
			}
			
			function stop_rotation() {
				clearInterval(interval_id);
				single_image(0);
			}
			
			function play_rotation() {
				clearInterval(interval_id);
				interval_id = setInterval(function() {rotate_images();}, delay_time);
				rotate_images();
			}
			
			function go_next_image() {
				clearInterval(interval_id);

				go_to_image(current_image, next_image);

				current_image = next_image;
				next_image = (next_image + 1) % number_of_images;
			}
			
			function go_prev_image() {
				clearInterval(interval_id);

				go_to_image(current_image, (current_image - 1 + number_of_images) % number_of_images);

				next_image = current_image;
				current_image = (next_image - 1 + number_of_images) % number_of_images;
				
			}
			
			function rotator_startup() {
				single_image(0);
				interval_id = setInterval(function() {rotate_images()}, delay_time);
			}
			
			if (number_of_images > 1)
				rotator_startup();
			
			jQuery("div.media_content_controller_buttons div.rewind")
				.click(function() {
					go_prev_image();
				});
			jQuery("div.media_content_controller_buttons div.fastforward")
				.click(function() {
					go_next_image();
				});
			jQuery("div.media_content_controller_buttons div.pause")
				.click(function() {
					pause_rotation();
				});
			jQuery("div.media_content_controller_buttons div.play")
				.click(function() {
					play_rotation();
				});
			jQuery("div.media_content_controller_buttons div.stop")
				.click(function() {
					stop_rotation();
				});			
		}
	);