//object to control the photo reel on the welcome page
var photos = {
	
	speeds : { wait : 6000, duration : 3000, timeout : 100 }, //animation speeds
	
	total : 3, //total photos
	
	path : 'images/header_photos/', //path to photos
	
	current : 1,

	regexp : new RegExp( /^.+\/([0-9]+)\.jpg$/ ),

	init : function() {

		//initialise rotation
		setTimeout( 'photos.rotate1()', photos.speeds.wait );
		$('header_photo2').setStyle( { opacity : 0 } );
	
		//preload images
		photos.header_photos = new Array();
		for( var i = 1; i <= photos.total; i++ ) {
			photos.header_photos[i] = new Image();
			photos.header_photos[i].src = photos.path + i + '.jpg';
		} //end for
		
	},

	rotate1 : function() {

		//get current photo
		photos.current = $('header_photo1').src.replace( photos.regexp, "$1" );
	
		//work out next photo number
		//var np = cp == header_photos_length ? 1 : cp + 1; //next
		do { var np = Math.floor( Math.random() * photos.total ) + 1; } while( np == photos.current ); //random

		//set src
		$('header_photo2').src = photos.header_photos[np].src;

		//blend
		if( !is_ie ) $('header_photo2').onload = photos.rotate2;
		else photos.rotate2();
	
	},

	rotate2 : function() {
		
		//if in ie and not completely loaded, try again in 3 seconds
		if( is_ie && !$('header_photo2').complete ) {
			
			setTimeout( 'photos.rotate2()', photos.speeds.timeout );
			return;
			
		} //end if

		//do the blend
		new Effect.Opacity( 'header_photo1', { duration: ( photos.speeds.duration / 1000 ), from: 1, to: 0 } );
		new Effect.Opacity( 'header_photo2', { duration: ( photos.speeds.duration / 1000 ), from: 0, to: 1 } );
		
		//when that is finished, swap photo 2 to photo 1
		setTimeout( 'photos.swap_photos()', photos.speeds.duration );
		
		setTimeout( 'photos.rotate1()', photos.speeds.wait + photos.speeds.duration );
	
	},
	
	swap_photos : function() {
		
		//swap photo 2 to photo 1 
		$('header_photo1').src = $('header_photo2').src;
		new Effect.Opacity( 'header_photo1', { duration: 0, from: 0, to: 1 } );
		new Effect.Opacity( 'header_photo2', { duration: 0, from: 1, to: 0 } );
	
	}
	
}

//object to control the sliding pass selector on the home page
var passes = {
	
	'descriptions' : [ '2 DAY ADULT PASS - &pound;32.00', '4 DAY ADULT PASS - &pound;45.00', '6 DAY ADULT PASS - &pound;59.00',  ],
	
	'speed' : 0.8, //speed of the slide
	
	'width' : 331, //width of the pass image and margin
	
	'total' : 3, //total passes
	
	'current' : 1, 

	'scroll' : function( type ) {
	
		//work out the next (or previous) pass
		if( type == 'n' ) passes.current = passes.current < passes.total ? passes.current + 1 : 1;
		else passes.current = passes.current > 1 ? passes.current - 1 : passes.total;
	
		//slide to the pass
		new Effect.Morph( $('pass-container2'), { style: 'left: ' + ( ( passes.current - 1 ) * passes.width * -1 ) + 'px;', duration: passes.speed } ); 
		
		//update description
		$('pass_desc').innerHTML = passes.descriptions[ passes.current -1 ];
		
	}
	
}