/*
//*******
//
//	filename: timeline.js
//	author: Zack Brown
//	date: 8th December 2010
//
//*******
*/

//declare timeline class
var Timeline = Class.create();

//declare timeline prototype
Timeline.prototype = {

	//timeline element
	element: null,
	
	//increment step
	step: 0,
	
	//total increment
	increment: 0,
	
	//max offset
	max_offset: 0,
	
	//init function
	initialize: function()
	{
		//timeline handle
		var timeline_handle = "timeline";
		
		//past and future handles
		var past_handle = "timeline_past";
		var future_handle = "timeline_future";
		
		//gather timeline element
		this.element = $(timeline_handle);
		
		//check timeline element is valid
		if(this.element != null && this.element != undefined)
		{
			//check past and future handles are valid
			if($(past_handle) != undefined && $(future_handle) != undefined)
			{
				//observe click events
				Event.observe($(past_handle), "click", this.past.bind(this));
				Event.observe($(future_handle), "click", this.future.bind(this));
				
				//determine increment step
				this.step = this.element.childElements().first().getWidth();
				
				//determine max increment offset
				this.max_offset = ((this.element.childElements().length / 2) * this.step);
				
				//scroll
				this.scroll();
			}
		}
	},
	
	//handle 'past' click events
	past: function()
	{
		//check increment
		if(this.increment < 0)
		{
			//accumulate increment
			this.increment += this.step;
		}
		
		//scroll
		this.scroll();
	},
	
	//handle 'future' click events
	future: function()
	{
		//check increment
		if(this.increment > -this.max_offset)
		{
			//subtract increment
			this.increment -= this.step;
		}
		
		//scroll
		this.scroll();
	},
	
	//scroll timeline
	scroll: function()
	{
		//scroll
		var effect = new Effect.Move(this.element, {x: this.increment, mode: "absolute"});
	}

}

//observe window load events
Event.observe(window, "load", function()
{
	//create a new timeline
	var timeline = new Timeline();
	
});
