// ------------------------------------------------------------------
//      AUTOR: Ryan J. Salva
//		MODIFICADO: Emiliano Díaz
//      MODIFIED: Diciembre 16, 2008
//
//      DESCRIPCION:
//      Crea un rotador de imagenes.
//
//      USO:
//		<div id="container">
//			<a href="#" target="_self"><img src="img1.jpg" alt="img" /></a>
//		</div>
//
//      <script type="text/javascript">
//          window.addEvent('domready',function() {
//               var f1 = new Fader('container',{options:}).start();
//          });
//		<script>
// ------------------------------------------------------------------

var mooRotador = new Class({
	Implements: Options,
	options: {
		pause: 7000,
		duration: 2500,
		clear: true,
		loop: true,
		onComplete: Class.empty,
		onStart: Class.empty,
		iniciorapido: false
	},
	initialize: function(container,options) {
		this.setOptions(options);
		this.container = $(container);
		this.container.addClass('mooRotador');
		this.container.setStyles({'position':'relative'});
		this.linkimg = this.container.getElements('a[rel^=milkbox]');
		this.imgs = this.linkimg.getElements('img');
		this.imgsize = this.imgs[0].getProperty('height');
		this.linkimg.setStyles({'position':'absolute','top':0,'left':0,'opacity':0});
		this.linkimg[0].setStyle('opacity',1);
		this.next = -1;
		this.start();
	},
	start: function() {
		if(this.options.iniciorapido == true){ this.show()};
		this.periodical = this.show.bind(this).periodical(this.options.pause);
	},
	stop: function() {
		$clear(this.periodical);
	},
	show: function() {	
		if(this.options.loop && this.next==this.linkimg.length-1)
		this.stop();
		
		this.next = (this.next==this.linkimg.length-1)?0:this.next+1;
		var prev = (this.next==0)?this.linkimg.length-1:this.next-1;
		
		this.linkimg.set('tween',{duration: this.options.duration});	
		this.linkimg[this.next].tween('opacity',1);
		this.linkimg[prev].tween('opacity',0);	
	}
}); 