function Scroll(){

	var scrollerspeed; //velocida com que o boxScroll rola;
	var barraSpeed; //velocida com que a barra de rolagem mexe, proporcional ao scrollerspeed;
	var boxScroll; //div com position absolute que contem o texto a mexer
	var scrollerheight; //altura do containner do box Scroll
	var barraScroll; //div com position absolute que contem a barra de rolagem
	var barraHeight; //altura do containner da BarraScroll
	var actualheight; //tamanho do newsticker dinamico

	this.Scroll = function(boxScroll, barraScroll, scrollerheight, barraHeight){
		this.boxScroll = document.getElementById(boxScroll);
		this.barraScroll = document.getElementById(barraScroll);
		this.barraHeight = barraHeight;
		this.scrollerspeed = (typeof(this.scrollerspeed)!='undefined')?this.scrollerspeed:8;
		this.scrollerheight = scrollerheight;
		this.actualheight = (this.boxScroll.offsetHeight < this.scrollerheight)?this.scrollerheight:this.boxScroll.offsetHeight;
		this.boxScroll.style.top = "0px";
		this.barraScroll.style.height = this.barraHeight+"px";
		this.showBarra();
	}

	this.setSpeed = function(sp){
		this.scrollerspeed = sp;
	}

	this.scroll_up = function(mouseover,obj){
			if(mouseover)
				lefttime = eval("setInterval('"+obj+".scrollscroller(true)',20)")
			else
				clearInterval(lefttime);
	}

	this.scroll_down = function(mouseover, obj){
		if(mouseover)
			lefttime = eval("setInterval('"+obj+".scrollscroller(false)',20)")
		else
			clearInterval(lefttime);
	}

	this.scrollscroller = function(up){
		//alert("("+scrollerspeed+"*"+(barraHeight-barraNoticia.offsetHeight)+")/("+(actualheight-scrollerheight)+") = "+((scrollerspeed * (barraHeight-barraNoticia.offsetHeight))/(actualheight-scrollerheight)))
		if(up){ //subindo
			if (parseInt(this.boxScroll.style.top)<0){
				this.boxScroll.style.top=parseInt(this.boxScroll.style.top)+this.scrollerspeed+"px"
				if(parseInt(this.barraScroll.style.top) > 0)//para a barra
					this.barraScroll.style.top = parseInt(this.barraScroll.style.top) - parseInt(this.barraSpeed) +"px";
			}
		}
		else{ //descendo
			if (parseInt(this.boxScroll.style.top)>((this.actualheight-this.scrollerheight)*-1)){
				this.boxScroll.style.top = parseInt(this.boxScroll.style.top)-this.scrollerspeed+"px";
				if(parseInt(this.barraScroll.style.top) < (this.barraHeight - parseInt(this.barraScroll.offsetHeight))) //para a barra
					this.barraScroll.style.top = (parseInt(this.barraScroll.style.top) + parseInt(this.barraSpeed)) +"px"
			}
		}
	}

	/** /
	this.showBarra = function(){
		percent = ((this.scrollerheight*100)/this.actualheight)/100;
		//alert(Math.round(this.barraHeight*percent))
		this.barraScroll.style.height = (Math.round(this.barraHeight*percent))+"px";
		this.barraScroll.style.top = "0px";
		this.barraSpeed = ""+((this.scrollerspeed * (this.barraHeight-this.barraScroll.offsetHeight))/(this.actualheight-this.scrollerheight));
		//alert("("+this.scrollerspeed+"*"+(this.barraHeight-this.barraScroll.offsetHeight)+")/("+(this.actualheight-this.scrollerheight)+") = "+((this.scrollerspeed * (this.barraHeight-this.barraScroll.offsetHeight))/(this.actualheight-this.scrollerheight)))
		decimal = this.barraSpeed.split(".");
		this.barraSpeed = parseInt(decimal[0])+1;
		percent = ((this.scrollerheight*100)/this.actualheight)/100;
		this.barraSpeed = ""+((this.scrollerspeed * (this.barraHeight-this.barraScroll.offsetHeight))/(this.actualheight-this.scrollerheight));
		decimal = this.barraSpeed.split(".");
		this.barraSpeed = parseInt(decimal[0])+1;
	}
	/**/
	this.showBarra = function(){
		this.barraScroll.style.height = 9+"px";
		this.barraScroll.style.top = "0px";
		//alert(this.scrollerspeed);
		x = parseInt(this.actualheight) - this.scrollerheight; //
		y = this.barraHeight - parseInt(this.barraScroll.offsetHeight);
		Vx = this.scrollerspeed;
		speed = (Vx*y)/x;
		//alert(speed+"/"+y+" = "+Vx+" / "+x);
		this.barraSpeed = ""+speed;

		/* ROUND */
		decimal = this.barraSpeed.split(".");
		dec = ""+decimal[1];
		//alert(parseInt(dec.charAt(0)))
		this.barraSpeed = (parseInt(dec.charAt(0)) > 5)?(parseInt(decimal[0])+1):parseInt(decimal[0]);
		//alert(this.barraSpeed);
	}

}
