//------------------------------------------------------------------------
// 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 < 3; i++ )
		{
			
			// Create a div for this slide.
			Slideshow.slides[i] = document.createElement( "div" );
			var slide = Slideshow.slides[i];
			
			// Set the slide as transparent.
			LW_DOM_Library.setStyle( slide, "opacity", 0 );
			
			// Add the image to it.
			slide.innerHTML = '<img src="images/commercial_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 );
			
		}
		
		// 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 the variables we need.
		var slide = Slideshow.slides[slide_id];	
		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.	
		Slideshow.setupAnimation( slide_id );
		
	},
	
	
	//------------------------------------------------------------------------
	// Name: setupAnimation()
	// Desc: This sets up the slide's animation depending upon which stage
	//       it's at.
	//------------------------------------------------------------------------
	setupAnimation: function( slide_id )
	{
		
		var slide = Slideshow.slides[slide_id];
		
		// Create the animation sequence object.
		var anim_sequence = new LW_Animation_Sequence();
		
		// Add the slide in animation.		
		var anim = new LW_Animation( slide, 1000 );
		
		anim.controller.move.by.Y = 160;
		anim.controller.move.ease = LW_Animation.BACK_EASE_OUT;
		anim.controller.opacity.to = 1;
		
		anim_sequence.addAnimation( anim );
		
		// Add the slide out animation.
		var anim = new LW_Animation( slide, 1000 );
		
		anim.controller.opacity.to = 0;
		anim.controller.delay = 4000;
		
		anim_sequence.addAnimation( anim );
		
		// We do this so that the next slide will be called to roll in when this
		// slide's animation sequence finishes.
		anim_sequence.onFinish = function(){ Slideshow.nextSlide( slide_id ); };
		
		// Start the sequence.
		anim_sequence.start();
		
	},
	
	
	//------------------------------------------------------------------------
	// Name: nextSlide()
	// Desc: Calls the next slide in the slideshow.
	//------------------------------------------------------------------------
	nextSlide: function( slide_id )
	{
		
		// Get the next slide's ID.
		var next_slide = Slideshow.current_index + 1;
		
		// 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 );
		
	}
	
}