/**
 * Picks a random number between a range, or random item from an array
 *
 * publishes 'randomized' event with index and item (if items array provided)
 *
 * @author Alec Hill
 */
(function(){

com.alechill.Randomizer = new Class({
    
	Implements: [Events, Options],
	
    options: {
		interval: 0,
		min: 0,
		max: 0,
		items: null // array
	},
	
	periodical: null,
    
    initialize: function( options ){
		this.setOptions(options);
		
		if(this.options.items){
			this.options.min = 0;
			this.options.max = this.options.items.length;
		}
		
		if(this.options.interval){
			this.periodical = this.rondomize.periodical(this.options.interval, this);
		}
		this.randomize();
		
    },
	
	/**
	 * do the random selection
	 */
	randomize: function(){
		var index = $random(this.options.min, this.options.max);
		var item = this.options.items ? this.options.items[index] : null;
		this.fireEvent('randomized', index, item);
	}
    
});

})();