/*
 * *************************************************************************************
 * The MIT License
 * Copyright (c) 2007 Stephen Ingram - http://www.jixor.com/
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the rights to use, copy, modify,
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * *************************************************************************************
 */

var slider = new Class ( {

	options: {

		idContainer:'filmNavigator_container',
		idUl:'filmThumbs',
		idRight:'filmNavigator_next',
		idLeft:'filmNavigator_previous',
		increment:440,
		duration:1000

	},

	initialize: function ( options ) {

		this.setOptions( options );

		this.scroll = new Fx.Scroll( this.options.idContainer, {
			wait:false,
			duration:this.options.duration,
			transition: Fx.Transitions.Quint.easeInOut
		} );

		$( this.options.idLeft ).addEvent( 'click', this.left.bind( this ) );
		$( this.options.idRight ).addEvent( 'click', this.right.bind( this ) );
		//$( this.options.idRight ).addEvent( 'mouseenter', this.rightenter.bind( this ) );

		var ulWidth = 0;

		$( this.options.idUl ).getChildren().each( function ( obj ) {
			var objWidth = $( obj ).getSize().size.x;
			ulWidth = ulWidth + objWidth;
		} );

		$( this.options.idUl ).setStyle( 'width', ulWidth );

	},

	left: function () {

		var xCoord = $( this.options.idContainer ).getSize().scroll.x;
		this.scroll.scrollTo( xCoord - this.options.increment, 0 );

	},

	right: function () {

		var xTotal = $( this.options.idUl ).getSize().size.x;
		var xBox = $( this.options.idContainer ).getSize().size.x;
		var xCoord = $( this.options.idContainer ).getSize().scroll.x;

		if( ( xCoord + xBox ) == ( xTotal ) ) {
			this.scroll.scrollTo( 0,0 );
		} else {
			this.scroll.scrollTo( xCoord + this.options.increment, 0 );
		}

	},

	rightenter: function () {

		var xCoord = $( this.options.idContainer ).getSize().scroll.x;

		if ( xCoord < this.options.increment )
			this.scroll.scrollTo( xCoord + this.options.increment, 0 );

	}

} );

slider.implement( new Events, new Options );