/*
 * Scroll News 
 * @author Angel Daniel Medina Núñez
 * @web www.webadictos.com.mx
 * @email daniel@webadictos.com.mx
 * Esta clase genera un scroll  hacia arriba (tipo marquesina)
 * Utilización:
 * var scroll = new ScrollNews('divcontenedor',velocidad);
 * la velocidad es opcional predeterminado esta a 30.
 */
 
NewsScroller = function (id,speed) {
	var self  = this;
	var container = document.getElementById(id);
	var boxheight = container.style.height.replace('px','');
	var boxwidth = container.offsetWidth;
	var heighttmp = container.scrollHeight;
	var width = parseInt(container.scrollWidth);
	var _timer;
	var direction = 1;
	
	//Duplicamos el contenido del div para que se haga el efecto de marquesina.
	container.innerHTML =  container.innerHTML +  container.innerHTML; 
	
	this.scrollSpeed = (parseInt(speed)>0) ? speed : 30;
	this.direction = 1;	
	
	this.setDirection = function (direction){
		this.direction = direction;
	};
	
	this.doScroll = function () { 
		/*document.getElementById('ver').innerHTML = (container.scrollLeft) + "-"  + (width-boxwidth);*/
		if((container.scrollLeft) >=(width-boxwidth)) {
			//Reiniciamos El Scroll
			container.scrollLeft=1;
		}else{
			if (self.direction == 1){
				container.scrollLeft=container.scrollLeft+1;		
			}else {
				container.scrollLeft=container.scrollLeft-1;		
			}
		}
	};
	
	this.start = function(speed) {
		this.scrollSpeed = (parseInt(speed)>0) ? speed : this.scrollSpeed;
		_timer = window.setInterval(self.doScroll, this.scrollSpeed);
	};

	this.stop = function () { 
		if (_timer) window.clearInterval(_timer);
	};
	
	this.start(0);
};
