/* 
 * Documento   : ticker-noticias.js
 * Autor       : RDE Soluciones (www.rdesoluciones.com)
 * Fecha       : 16-oct-2009, 10:29:41
 */
var TickerNoticias = new Class({
  initialize: function(elemId) {
    this.elem = $(elemId);
    this.items = this.elem.getElements('.noticia');
    this.speed = 10000;
    this.delay = 2000;
    this.current = 0;
		var w = 0;
		var h = 0;
    h = this.elem.getSize().y;
    var obj = this;
    this.items.each(function(item,index) {
      w += item.getSize().x;
    });
		this.elem.setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			width: w,
      height: h
		});
    this.ancho = w;
    this.elem.addEvents({
      mouseenter: function() {
        obj.pause();
      },
      mouseleave: function() {
        obj.resume();
      }
    });
    this.speed = w / 40 * 1000;
    this.fx = new Fx.Tween(this.elem, {duration: this.speed, onComplete: function() {
/*			var i = (obj.current == 0) ? obj.items.length : obj.current;
			obj.items[i-1].injectInside(obj.elem);*/
			obj.elem.setStyle('left', 400);
      obj.fx.options.duration = (400 + obj.ancho) / 40 * 1000 ;
      mytimer2 = obj.next.bind(obj).delay(0);
    }});
    mytimer2 = this.next.bind(this).delay(this.delay);
  },
	pause: function() {
    $clear(mytimer2);
    mytimer2 = null;
	},
	resume: function() {
    if (mytimer2 == null) {
      mytimer2 = 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.options.transition = Fx.Transitions.linear;
    this.fx.start('left', this.elem.left, -this.ancho);
		//
  }
});
var mytimer2 = null;

window.addEvent('domready', function() {
  var ticker = new TickerNoticias('ticker-noticias');
});

