var TenYearSlider = Class.create(
{
	initialize: function() 
	{
		this.viewer_previx = 'ten_year_slider_'; // [string] = The text before the ID# in the id of the items
		this.current_year = 2010; // [int] The current index
		this.box_id = 0;
		
		this.fps = 30;
		this.cycle_time = 3.5; // [int] The time in seconds for the cycle
	 	this.transition_time = 0.5; // [int] # of secs for transition
	 	
		Event.observe(window, 'load', this.load.bindAsEventListener(this)); // load the event observers
		
		this.in_transition = false; // [bool] = Flag to indicate if the viewer in in the midst of a transition
		
	},	
	
	
	/********************************************************/
	/*										   			    */
	/*   FUNCTION LOAD THE ITEMS REQUIRED AFTER SITE LOAD   */
	/*													    */
	/********************************************************/
	load : function()
	{
		this.updateIndex();		
		this.startCycling();
	},
	
	startCycling : function()
	{
		new PeriodicalExecuter(this.hideCurrentBox.bind(this), this.cycle_time); // change image every 5 seconds 
	},
	
	
	/******************************************************/
	/*													  */
	/*    FUNCTION TO PROCESS WHEN AN ITEM IS SELECTED    */
	/*													  */
	/******************************************************/
	select: function(id)
	{
		if(this.in_transition)
		{
		//	setTimeout(this.select(id), 1000);
		}
		else
		{
			if(this.ids[this.current_index] != id)
			{
		 		$(this.viewer_previx+this.ids[this.current_index]).hide(); // hide the current index
				$(this.viewer_previx+id).show(); // show the new one
				this.current_index = this.ids.indexOf(id); //update the current_index id
				this.updateBoxID();
			}
		}
	},
	
	
	/* 	FUNCTION	: 	forward
		DESCRIPTION	:	Moves the viewer forward
		PARAMS		:	
		RESULT		:	
	 */
	forward: function() 
	{ 
		if(this.in_transition)
		{
		}
		else
		{
			this.hideCurrentBox();
		}
	},
	
	
	
	/* 	FUNCTION	: 	hideCurrentBox
		DESCRIPTION	:	Hides current box
		PARAMS		:	
		RESULT		:	
	 */
	hideCurrentBox: function() 
	{ 
		this.in_transition = true;
		new Effect.Fade(this.box_id, 
    	{
			duration: this.transition_time,
			fps: this.fps,
			afterFinish: function() 
			{ 
			   	this.updateIndex(); // get the next index
			   	this.showCurrentBox();
			}.bind(this)
    	})
	},
	
	/* 	FUNCTION	: 	showCurrentBox
		DESCRIPTION	:	Shows current box
		PARAMS		:	
		RESULT		:	
	 */
	showCurrentBox: function() 
	{ 
		new Effect.Appear(this.box_id, 
    	{
			duration: this.transition_time,
			fps: this.fps,
			queue:'end'
    	})
    	this.in_transition = false;
	},
	
	/* 	FUNCTION	: 	updateIndex
		DESCRIPTION	:	Updates the index
		PARAMS		:	
		RESULT		:	
	 */
	updateIndex: function() 
	{ 
		this.current_year++;
		if(this.current_year >2011)
		{
			this.current_year = 2002;
		}
		$('TenYearSlider_year').update(this.current_year);
		
		this.updateBoxID();
	},
	
	/* 	FUNCTION	: 	getCurrentBoxID
		DESCRIPTION	:	Returns the ID of the current box
		PARAMS		:	
		RESULT		:	
	 */
	updateBoxID: function() 
	{ 
		this.box_id = this.viewer_previx + this.current_year;
		
	}
	

	
	

});

