
function InitOnlineDisplay(){
	var ofertas = new ofertasDisplay($$('.listaOnline li'), 25, 500).start();	
}
/* -----------------------------------------------------------------------------
OFERTAS DEL DISPLAY ---------------------------------------------------------
----------------------------------------------------------------------------- */ 
var ofertasDisplay = new Class({
    
		initialize: function(elementos, altura, velocidad){
			this.elem = elementos;
			this.altura = altura;
			this.activo = 0;
			this.velocidad = velocidad;
			
			$$('.displayOnline').adopt(new Element('a', {'title': 'Siguiente', 'class': 'antOfer', 'href': '#'}) );
			$$('.displayOnline').adopt(new Element('a', {'title': 'Anterior', 'class': 'sigOfer', 'href': '#'}) );

			this.anterior = $$('.antOfer');
			this.siguiente = $$('.sigOfer');
			
			this.elem.each(function(elemento, i){
				elemento.setStyle('position', 'absolute');
				if(i==0) elemento.setStyle('top', '0px');
				else elemento.setStyle('top', this.altura+'px');
			}.bind(this));
			
    },
		
		start: function(){
			this.anterior.addEvent('click', function(e){new Event(e).stop(); this.irant();}.bind(this));
			this.anterior.addEvent('mouseover', function(){this.setOpacity(0.4);});
			this.anterior.addEvent('mouseout', function(){this.setOpacity(1);});
			
			this.siguiente.addEvent('click', function(e){new Event(e).stop(); this.irsig();}.bind(this));
			this.siguiente.addEvent('mouseover', function(){this.setOpacity(0.4);});
			this.siguiente.addEvent('mouseout', function(){this.setOpacity(1);});
		},
		
		mueve: function(){
			if(this.activo==this.elem.length-1){
				this.ver(this.activo, 'vete');
				this.activo = 0;	
			}else{
				this.ver(this.activo, 'vete');
				this.activo+=1;
			}
			this.ver(this.activo,'entra');
		},
		
		ver: function(num, sube){
			if(sube=='entra'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start(this.altura, 0);
			}else if(sube=='vete'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start(0, '-'+this.altura);
			}else if(sube=='entraArriba'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start('-'+this.altura, 0);
			}else if(sube=='veteAbajo'){
				var fx = new Fx.Style(this.elem[num], 'top', {duration: this.velocidad}).start(0, this.altura);
			}
		},
		
		irant: function(){
			this.ver(this.activo, 'veteAbajo');
			if(this.activo==0){
				this.activo=this.elem.length-1;
			}else{
				this.activo-=1;
			}
			this.ver(this.activo, 'entraArriba');
		}, 
		
		irsig: function(){
			this.mueve();
		}

});

/* -----------------------------------------------------------------------------
LOAD ---------------------------------------------------------------------------
----------------------------------------------------------------------------- */ 
window.addEvent('domready', InitOnlineDisplay);