
var showreel_rotation_time=8000;
var showreel_transition_time=1500;

function showreel(){
	var initial_node=new Array();
	initial_node[0]='<a href="moviegoers/family_innovation_screen/friday.html#2100"><img src="images/moviegoers/showreel_0.jpg" alt="Alien" /></a>';
	initial_node[1]='<a href="moviegoers/arrow_world_cinema_screen/friday.html#1200"><img src="images/moviegoers/showreel_1.jpg" alt="Departures" /></a>';
	initial_node[2]='<a href="moviegoers/arrow_world_cinema_screen/friday.html#2135"><img src="images/moviegoers/showreel_2.jpg" alt="Battle Royale" /></a>';
	initial_node[3]='<a href="moviegoers/arrow_world_cinema_screen/friday.html#1500"><img src="images/moviegoers/showreel_3.jpg" alt="Cinema Paradiso" /></a>';
	initial_node[4]='<a href="moviegoers/arrow_world_cinema_screen/saturday.html#2015"><img src="images/moviegoers/showreel_4.jpg" alt="City of the Living Dead" /></a>';
	initial_node[5]='<a href="moviegoers/bfi_archive_screen/sunday.html#1900"><img src="images/moviegoers/showreel_5.jpg" alt="Jeff Keen" /></a>';
	initial_node[6]='<a href="moviegoers/bfi_archive_screen/sunday.html#2100"><img src="images/moviegoers/showreel_6.jpg" alt="Dracula" /></a>';
	initial_node[7]='<a href="moviegoers/bfi_archive_screen/saturday.html#2100"><img src="images/moviegoers/showreel_7.jpg" alt="Great Expectations" /></a>';
	
	// Declare the node values which will be used
	var node_values=new Array();
	
	// Not initial run - use contents of next box
	if (document.getElementById('showreel_1').innerHTML) {
		
		// When not empty, the contents just takes the contents from next box
		for (i=0;i<initial_node.length;i++) {
			num=i;
			replace_id='showreel_'+(num);
			replace_with_id='showreel_'+((num+1)%initial_node.length);
			node_values[i]=document.getElementById(replace_with_id).innerHTML;
		}
	// Initial run, use initial values
	} else {
		for (i=0;i<initial_node.length;i++) {
			node_values[i]=initial_node[i];
		}
	}

	// Now replace cells
	for (i=0;i<initial_node.length;i++) {
		replace_id='showreel_'+(i);
		//document.getElementById(replace_id).innerHTML=node_values[i];
		//$('#'+replace_id).fadeTo('slow',0.2);
		//new_span_id='span_'+i;
		$('#'+replace_id).fadeTo(showreel_transition_time,0.01,replace_content(replace_id,node_values[i]));
		
		//document.getElementById(replace_id).innerHTML.fadeOut('slow');
	}
	
	// Now set the timeout to run the function again
	setTimeout(showreel,showreel_rotation_time);
	
}

// Pause
function pause(milliseconds) {
	var dt = new Date();
	while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}

// Replace content
function replace_content(id,content) {
	
	document.getElementById(id).innerHTML=content;
	$('#'+id).fadeTo(0,0.01);
	$('#'+id).fadeTo(showreel_transition_time,1);
	$('#'+id).fadeTo(showreel_rotation_time-(2*showreel_transition_time),1);
}


window.onload=function() {
	if (document.getElementById('showreel')) {
		showreel();
	}
}
