/*
 * 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 heighttmp = container.scrollHeight;
	var height = parseInt(container.scrollHeight);
	var _timer = null;
	container.style.visibility='visible';
	container.scrollTop=0;
	
	//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.doScroll = function () { 
		if(container.scrollTop>height) {
			//Reiniciamos El Scroll
			container.scrollTop=1;
		}else{
		container.scrollTop=container.scrollTop+1;		
		}
	};
	
	this.start = function() {
		if(!_timer){
			_timer = window.setInterval(self.doScroll, self.scrollSpeed);
		}
	};
	this.go = function(){
		self.start();
	}
	this.stop = function () { 
			if (_timer){
				window.clearInterval(_timer);
				_timer=null;
			}
	};
	window.setTimeout(self.go, 2000);
	//this.start();
};