/*
|--------------------------------------------------------------------------
| Amedia Creative Frontend Framework > Carousel
|--------------------------------------------------------------------------
|
| @package		Amedia Creative
| @subpackage	Frontend Framework
| @company		Amedia Creative, Inc.
| @phone		310/651/8733
| @fax			310/388/1210
| @author		Joey Avino / Ever Barreto
| @email		joey@amediacreative.com / ever@amediacreative.com
| @link			http://www.amediacreative.com
| @copyright	2008 Amedia Creative, Inc.
| @requires 	mootools.1.2.js
|
*/

/*
|--------------------------------------------------------------------------
| Amedia Creative Frontend Framework > Carousel > Core JavaScript
|--------------------------------------------------------------------------
|
| NOTE: Do not change the names of these classes.
|
*/

	/**
	* Function to activate the carousel once it's been initialized
	*
	* @name 	New Carousel Class
	* @access 	public
	* @param 	var-type none
	* @return 	none
	* @author 	Joey Avino
	* @email	joey@amediacreative.com
	*/
	var Carousel = new Class({

		/**
		* Function to activate the carousel
		*
		* @name 	Display Carousel
		* @access 	public
		* @param 	var-type none
		* @return 	none
		* @author 	Joey Avino
		* @email	joey@amediacreative.com
		*/
		Implements: Options, options: {

			item_width: 775,
			duration: 500,
			transition: Fx.Transitions.Pow.easeOut,
			next_btn_id: 'next',
			prev_btn_id: 'prev',
			event: 'click'

		},

		initialize: function(carousel, options) {

			this.setOptions(options);
			this.carousel = $(carousel);

			this.next_btn = $(this.options.next_btn_id);	
			this.prev_btn = $(this.options.prev_btn_id);

			this.max_margin = this.carousel.getChildren('div').length * this.options.item_width - this.options.item_width;
			this.position = parseInt(this.carousel.getStyle('left'));

			this.fx_carousel = new Fx.Tween(carousel, {

				property: 'left',
				duration: this.options.duration,
				transition: this.options.transition

			});

			var get_objects = $$('.object');

			if (get_objects.length <= 1) {

				this.next_btn.setStyle('display', 'none');
				this.prev_btn.setStyle('display', 'none');

			}

			this.next_btn.addEvent(this.options.event, this.next_item.bind(this));
			this.prev_btn.addEvent(this.options.event, this.previous_item.bind(this));

		},





		/**
		* Function ran when the next button is used.
		* 
		* @name 	Next Item
		* @access 	public
		* @param 	var-type none
		* @return 	none
		* @author 	Joey Avino
		* @email	joey@amediacreative.com
		*/
		next_item: function() {

			if(this.position == -this.max_margin) {

				this.fx_carousel.start(0);
				this.position = 0;

			}

			else {
			  
				var new_position = this.position - this.options.item_width;
				this.fx_carousel.start(new_position);

				this.position = new_position;

			}
		},





		/**
		* Function ran when the previous button is used.
		* 
		* @name 	Previous Item
		* @access 	public
		* @param 	var-type none
		* @return 	none
		* @author 	Joey Avino
		* @email	joey@amediacreative.com
		*/
		previous_item: function() {

			if(this.position == 0) {

				this.fx_carousel.start(-this.max_margin);
				this.position = -this.max_margin;

			}

			else { 

				var new_position = this.position + this.options.item_width;
				this.fx_carousel.start(new_position);
				this.position = new_position;

			}
		}
	});