// JavaScript Document

// Control Slide Show
	var photo_array = new Array();
	var current_photo_index = 0;
	var previous_photo_index = 0;
	var pe;
	
	Event.observe(window, 'load', function() {
				
				if($('photo_bar')){
					$$('#photo_bar img').invoke('observe','click', change_photo);
					$$('#photo_bar img').each(function(s) {
										  photo_array.push(s.src);
					});
					update_viewport(current_photo_index);
					pe = new PeriodicalExecuter(rotate_photos, 5);
				}
	});
	
	function rotate_photos(){
		
		 if (current_photo_index < (photo_array.length-1))
		  {
			current_photo_index ++; 
		  } else {
			current_photo_index = 0;
		  }
		  update_viewport(current_photo_index);
	}
	
	function change_photo(){
		pe.stop();
		current_photo_index = photo_array.indexOf(this.src);
		update_viewport(current_photo_index);
		pe = new PeriodicalExecuter(rotate_photos, 5);
	}
			
	function update_viewport(photo_index){
		$('viewport_background').src = photo_array[previous_photo_index];
		$('viewport_photo').hide();
		$('viewport_photo').src = photo_array[photo_index];
		$('viewport_photo').appear()
		previous_photo_index = photo_index;
	}
	
// Control Slide Show - End
