/* 
 * Documento   : galeria-home
 * Autor       : RDE Soluciones (www.rdesoluciones.com)
 * Fecha       : 07-oct-2009, 19:05:16
 */
var TickerItems = new Class({
  initialize: function(elemId) {
    this.elem = $(elemId);
    this.items = this.elem.getElements('.tickerItem');
    this.speed = 200;
    this.delay = 1500;
    this.current = 0;
    this.bloqueado = false;
    mytimer = null;
		var w = 0;
		var h = 0;
    w = this.elem.getSize().x;
    var obj = this;
    this.items.each(function(item,index) {
      item.addEvent('click', function() {
        obj.bloqueado = true;
      });
      h += item.getSize().y;
    });
		this.elem.setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			width: w,
      height: h
		});
    this.elem.addEvents({
      mouseenter: function() {
        obj.pause();
      },
      mouseleave: function() {
        obj.resume();
      }
    });
    this.fx = new Fx.Tween(this.elem, {duration: 'long', onComplete: function() {
			var i = (obj.current == 0) ? obj.items.length : obj.current;
			obj.items[i-1].injectInside(obj.elem);
			obj.elem.setStyle('top', 0);
    }});
    mytimer = this.next.bind(this).delay(this.delay + this.speed);
  },
	pause: function() {
    $clear(mytimer);
    mytimer = null;
	},
	resume: function() {
    if ((mytimer == null) && (!this.bloqueado)) {
      mytimer = this.next.bind(this).delay(this.delay + this.speed);
    }
	},
  next: function() {
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		var pos = this.items[this.current];
    this.fx.start('top', this.elem.top, -pos.offsetTop);
		mytimer = this.next.bind(this).delay(this.delay + this.speed);
  }
});
var mytimer = null;
var hor = null;
function onSmoothboxImageClosed()
{
  $('mensaje-cerrar-imagen').fade(0);
  $('imagen-ampliada').fade(0);
  $('img-ampliada').fade(0);
  hor.bloqueado = false;
  hor.resume();
}
window.addEvent('domready', function() {
  $('imagen-ampliada').fade('hide');
  $('mensaje-cerrar-imagen').fade('hide');
  hor = new TickerItems('galeria-ticker');
  TB_init();
  $('mensaje-cerrar-imagen').addEvent('click', function(){
    $('mensaje-cerrar-imagen').fade(0);
    $('imagen-ampliada').fade(0);
    $('img-ampliada').fade(0);
    hor.bloqueado = false;
    hor.resume();
  });
  $('img-ampliada').addEvent('click', function(){
    $('mensaje-cerrar-imagen').fade(0);
    $('imagen-ampliada').fade(0);
    $('img-ampliada').fade(0);
    hor.bloqueado = false;
    hor.resume();
  });
});
