var currentFrame = 1;

$(document).ready(function(){

	setTimeout("advanceFrame()", 3000);
	
	$(".frame-thumb a").hover(
		function() {
			var frame = $(this).attr("id").replace("thumbgo-","");
			if (frame != currentFrame) {
				clearTimeout(window.show_timeout);
				window.show_running = 1;
				advanceFrame(frame);
				window.show_running = 0;
				clearTimeout(window.show_timeout);
			} else {
				clearTimeout(window.show_timeout);
				window.show_running = 0;
			}
		},
		function() {
			window.show_running = 1;
			clearTimeout(window.show_timeout);
			window.show_timeout = setTimeout("advanceFrame()", 1000);
		}
	);

});

function advanceFrame(frame) {
	if (window.show_frame_count === null) return;
	if (!window.show_running) return;

	$('#frame-'+currentFrame+' .summary').slideUp('slow');
	$('#frame-'+currentFrame+' .summary-background').slideUp('slow');

	$('#frame-'+currentFrame+' .title').slideUp('slow');
	$('#frame-'+currentFrame+' .title-background').slideUp('slow');
	
	$('#frame-'+currentFrame).fadeOut();
	$('#thumb-'+currentFrame+' img').toggleClass('thumb-unselected');
	
	if (frame) currentFrame = frame;
	else currentFrame++;

	if (currentFrame > window.show_frame_count) currentFrame = 1;
	$('#thumb-'+currentFrame+' img').toggleClass('thumb-unselected');
	$('#frame-'+currentFrame).fadeIn();
	
	$('#frame-'+currentFrame+' .title-background').slideDown('slow');
	$('#frame-'+currentFrame+' .summary-background').slideDown('slow');

	$('#frame-'+currentFrame+' .title').slideDown('slow');
	$('#frame-'+currentFrame+' .summary').slideDown('slow');
	
	clearTimeout(window.show_timeout);
	if (!frame) window.show_timeout = setTimeout("advanceFrame()", 5000);
}
