/* 
 #########################################
 Author : JACKSON OATES jackson@zeroninelab.com
 Company : ZERO NINE LAB, LLC - www.zeroninelab.com
 Date: 04/01/2010
 Updated: 04/08/2010
 *
 #########################################
 CREATE AN ITEM ROTATION
 
 IMPLEMENT:
 var rotate = new Rotation(id,{ // item container (mask)
	 _itemClass:'.item',		// class of items to be rotated
	 _time:8000,				// rotation time in MS (delay between) defaults to 5 seconds
	 _len:3,					// item array length
	 onTorpedo:myFunction
 })
 UPDATE:
 04/08/2010 - added callback event: onTorpedo, passes index back, and now pass in length of items array
 
 */
var Rotation = new Class({
    Implements: [Options],
    options: {
        _itemClass: null,
        _time: null,
        _len: null,
		onTorpedo: $empty
    },
    initialize: function(options){
        this.setOptions(options);
        //this.target	= $(id);
        //this.items 	= this.getItems();
		this.len	= this.options._len; 
        this.time 	= this.options._time  || 5000;
		this.count	= 0;
        this.start 	= this.init();
    },
    init: function(){
		this.addCount = function(){
			if(this.count < this.len-1){
				this.count++;
			}else{
				this.count = 0;
			}
			//this.doRotation(this.count);
			this.fireEvent('onTorpedo', this.count);
		}.bind(this);
		this.addCount.periodical(this.time, this.count); //Will add the number of seconds at the Site.	
    },
 
    // RETURN ITEM ARRAY //
    
    getItems: function(){
		return this.target.getElements(this.options._itemClass);
    }
    
    // ROTATION //
    // killed in favor of callback onTorpedo event
    /*
	doRotation: function(index){
		this.items.each(function(el){
			el.setStyles({
				'opacity':0,
				'display':'none'
			})
		})
		this.items[index].setStyle('display','block')
		var fx = new Fx.Tween(this.items[index], {
			fps:75,
			duration:450,
			transition: Fx.Transitions.Quad.easeInOut
		});
		fx.start('opacity',1)		
    }
    */
});
Rotation.implement(new Events, new Options);


