/*
|--------------------------------------------------------------------------
| Amedia Creative Frontend Framework > Rotator
|--------------------------------------------------------------------------
|
| @package		Amedia Creative
| @subpackage	Frontend Framework
| @company		Amedia Creative, Inc.
| @phone		310/651/8733
| @fax			310/388/1210
| @author		Joey Avino
| @email		joey@amediacreative.com
| @link			http://www.amediacreative.com
| @copyright	2008 Amedia Creative, Inc.
| @requires 	mootools.1.2.js
| @version		1.0
|
*/

/*
|--------------------------------------------------------------------------
| Amedia Creative Frontend Framework > Rotator > Core JavaScript
|--------------------------------------------------------------------------
|
| NOTE: This file is setup to work without requiring edits.
| All items can be called from the external file.
|
*/

	/**
	* Function to activate the multiselect section once it's been initialized from external
	*
	* @name 	New Rotator Class
	* @access 	public
	* @param 	var-type none
	* @return 	none
	* @author 	Joey Avino
	* @email	joey@amediacreative.com
	*/
	var Rotator = new Class({

		Implements: Options, options: {

			slide_timer:  4000,
			transition_time: 3000,
			set_transition: Fx.Transitions.Pow.easeOut,
			slide_items: '.slide_item'

		},
		
		/**
		* Function to activate the JavaScript
		*
		* @name 	Initialize
		* @access 	public
		* @param 	var-type none
		* @return 	none
		* @author 	Joey Avino
		* @email	joey@amediacreative.com
		*/
		initialize: function(rotator, options) {

			this.setOptions(options);

			var items = $$(this.options.slide_items);  //Get array of elements for sliding
			var slide_timer = this.options.slide_timer;
			var transition_time = this.options.transition_time;
			var set_transition = this.options.set_transition;

			/* --------end config vars-------- */
			
			//Setup positions
			items.each(function(element, index) {
				
				//since the viewer obviously has javascript on, we can remove the 'first_item' class
				if(index == 0) {

					element.removeClass('first_item');
					element.setStyle('left', "0");

				}

				else {

					element.setStyle('left', "0");
					element.setStyle('opacity', "0");

				}
			});
			//end setup
			
			//Slider Stuff
			var slide_function = new function() {

				var num_items = items.length;  //get number of slider items
				var item_num = 0;  //initialize a variable to hold the current slide index

				var slide_it = function() { 

					//get item to slide out
					var cur_item = items[item_num];  
					
					//change index
					if(item_num < (num_items - 1)) { item_num++; }
					else { item_num = 0; }
					
					//now get item to slide in using new index
					var new_item = items[item_num];
					
					//set up our animation stylings for out and in motions (note:  Fx.Styles does NOT exist in moo 1.2, so we must use Fx.Morph or Fx.Tween)
					var item_in = new Fx.Morph(new_item, {

							 duration: transition_time, 
							 transition: set_transition, 
							 wait: false

					});
					
					var item_out = new Fx.Morph(cur_item, {

							 duration: transition_time, 
							 transition: set_transition, 
							 wait: false

					});
					
					//we will set a beginning value here
					//this is so that it gives the illusion of continuous motion from one direction, even after the first cycle of items
					item_in.start({

			'left': [0, 0],
			'opacity': [0,1]

					});
					
					//no beginning values needed, since we always want to push the old item out to the left
					item_out.start({
  
			'left': '0',
			'opacity': [0]

					});
					
				};

				//call the function, periodically  (note: the interval period is defined at the top of this file)
				slide_it.periodical(slide_timer, this);
			}
		
		}
	});