//------------------------------------------------------------------------
// Name: Slideshow
// Desc: Manages the setting up and animation of the slides.
//------------------------------------------------------------------------
Slideshow = 
{
	
	//----------------------------------------------------------------------
	// Public Variables
	//----------------------------------------------------------------------
	slides: new Array(),
	current_index: 0,
	
	
	//----------------------------------------------------------------------
	// Public Member Functions
	//----------------------------------------------------------------------
	//------------------------------------------------------------------------
	// Name: initialize()
	// Desc: Initializes the Slideshow. Adds all the slides to the DOM and
	//       sets them up for animation.
	//------------------------------------------------------------------------
	initialize: function()
	{
		
		// Let's loop through all the slides.
		for ( var i = 0; i < 9; i++ )
		{
			
			// Create a div for this slide.
			Slideshow.slides[i] = document.createElement( "div" );
			var slide = Slideshow.slides[i];
			
			// Set the slide to transparent.
			LW_DOM_Library.setStyle( slide, "opacity", 0 );
			
			// Add the image to it.
			slide.innerHTML = '<img src="images/festiva_slides/slide' + i + '.jpg" />';
						
			// Append the child to the right column and set it up for absolute positioning.
			document.getElementById( "right_column" ).appendChild( slide );	
			
			var X = LW_DOM_Library.getX( slide );
			LW_DOM_Library.setStyle( slide, "position", "absolute" );
			LW_DOM_Library.setX( slide, X );
			LW_DOM_Library.setY( slide, 0 );
			
		}
		
		// Let's set up the first slide.
		Slideshow.setupSlide( 0 );
		
	},
	
	
	//------------------------------------------------------------------------
	// Name: setupSlide()
	// Desc: Sets up the particular slide at the particular stage that it
	//       should be in.
	//------------------------------------------------------------------------
	setupSlide: function( slide_id )
	{
		
		// Get how many times we should loop.
		var loop = ((Slideshow.slides.length - slide_id) >= 3) ? 3 : (Slideshow.slides.length - slide_id);
		
		// Loop through the slides we should show.
		for ( var i = 0; i < loop; i++ )
		{
			
			// Get the variables we need.
			var slide = Slideshow.slides[slide_id + i];
			var right_columnY = LW_DOM_Library.getY( document.getElementById( "right_column" ) );
			
			// Set the new Y value.
			LW_DOM_Library.setY( slide, right_columnY - 135 );
			
			// Now let's set this slide up for animation.
			if ( i < loop - 1 )
				Slideshow.setupAnimation( slide_id + i, i, false );
			else
				Slideshow.setupAnimation( slide_id + i, i, true );
			
		}  // Next slide.
		
	},
	
	
	//------------------------------------------------------------------------
	// Name: setupAnimation()
	// Desc: This sets up the slide's animation depending upon which stage
	//       it's at.
	//------------------------------------------------------------------------
	setupAnimation: function( slide_id, stage, last )
	{
		
		var slide = Slideshow.slides[slide_id];
		
		// Create the animation sequence object.
		var anim_sequence = new LW_Animation_Sequence();
		
		// Set up the animation depending upon which stage it's at.
		if ( stage == 0 )
		{
			
			// Create the initial animation.
			var anim = new LW_Animation( slide, 1000 );
			
			anim.controller.move.by.Y = 160;
			anim.controller.move.ease = LW_Animation.STRONG_EASE_OUT;
			anim.controller.opacity.to = 1;
			anim.controller.delay = 1000;
			
			anim_sequence.addAnimation( anim );
			
			// Set the final slide out animation.
			var anim = new LW_Animation( slide, 1000 );
			anim.controller.opacity.to = 0;
			anim.controller.delay = 6000;
			
			anim_sequence.addAnimation( anim );
			
		}
		else if ( stage == 1 )
		{
			
			// Create the initial animation.
			var anim = new LW_Animation( slide, 1000 );
			
			anim.controller.move.by.Y = 320;
			anim.controller.move.ease = LW_Animation.STRONG_EASE_OUT;
			anim.controller.opacity.to = 1;
			anim.controller.delay = 500;
			
			anim_sequence.addAnimation( anim );
			
			// Set the final slide out animation.
			var anim = new LW_Animation( slide, 1000 );
			anim.controller.opacity.to = 0;
			anim.controller.delay = 6500;
			
			anim_sequence.addAnimation( anim );
			
		}
		else if ( stage == 2 )
		{
			
			// Create the initial animation.
			var anim = new LW_Animation( slide, 1000 );
			
			anim.controller.move.by.Y = 480;
			anim.controller.move.ease = LW_Animation.STRONG_EASE_OUT;
			anim.controller.opacity.to = 1;
			
			anim_sequence.addAnimation( anim );
			
			// Set the final slide out animation.
			var anim = new LW_Animation( slide, 1000 );
			anim.controller.opacity.to = 0;
			anim.controller.delay = 7000;
			
			anim_sequence.addAnimation( anim );
			
		}
		
		// If this is the last slide in the set of animations, set the onFinish event. 
		if ( last ) anim_sequence.onFinish = function(){ Slideshow.nextSlide(); };
		
		// Start the sequence.
		anim_sequence.start();
		
	},
	
	
	//------------------------------------------------------------------------
	// Name: nextSlide()
	// Desc: Calls the next slide in the slideshow.
	//------------------------------------------------------------------------
	nextSlide: function()
	{
		
		// Get the next slide's ID.
		var next_slide = Slideshow.current_index + 3;
		
		// If this is the last slide in the slideshow, start over again.
		if ( next_slide >= Slideshow.slides.length )
			next_slide = 0;
		
		// Set the current index to the next slide's ID.
		Slideshow.current_index = next_slide;
			
		// Now set up the slide to slide in.
		Slideshow.setupSlide( next_slide );
		
	}
	
}