function lib_bwcheck() {
	this.ver = navigator.appVersion;
	this.agent = navigator.userAgent;
	this.dom = document.getElementById ? 1 : 0;
	this.opera5 = (navigator.userAgent.indexOf("Opera") > -1 && document.getElementById) ? 1 : 0;
	this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie6 = (this.ver.indexOf("MSIE 6") > -1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie7 = (this.ver.indexOf("MSIE 7") > -1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie4 = (document.all && !this.dom && !this.opera5) ? 1 : 0;
	this.ie = this.ie4 || this.ie5 || this.ie6 || this.ie7;
	this.mac = this.agent.indexOf("Mac") > -1;
	this.ns6 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
	this.ns4 = (document.layers && !this.dom) ? 1 : 0;
	this.bw = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this;
};

var bw = new lib_bwcheck();

var velocidade = 30;

var loop;

var px = bw.ns4 || window.opera ? "" : "px";

var textoCarregado = false;

var travou = 0;
var travado = 0;

function makeObj(obj, nest) {
    nest = (!nest) ? "" : 'document.'+nest+'.';
	this.el = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest+'document.'+obj) : 0;
	this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? eval(nest + 'document.' + obj) : 0;
	this.scrollHeight = bw.ns4 ? this.css.document.height : this.el.offsetHeight;
	this.clipHeight = bw.ns4 ? this.css.clip.height : this.el.offsetHeight;
	this.up = goUp;
	this.down = goDown;
	this.moveIt = moveIt;
	this.x = 0;
	this.y = 0;
    this.obj = obj + "Object";
    eval(this.obj + "=this");
    return this;
};

function moveIt(x, y) {
	this.x = x;
	this.y = y;
	this.css.left = this.x + px;
	this.css.top = this.y + px;
};

function goDown(numero, move) {
	if (this.y > -this.scrollHeight + rolagem.oContainer[numero].clipHeight) {
		this.moveIt(0, this.y - move);
		if (loop)
			setTimeout(this.obj + ".down(" + numero + ", " + move + ")", velocidade);
		RolaBarra(numero);
	};
};

function goUp(numero, move) {
	if (this.y < 0) {
		this.moveIt(0, this.y - move);
		if (loop)
			setTimeout(this.obj + ".up(" + numero + ", " + move + ")", velocidade);
		RolaBarra(numero);
	};
};

function RolaBarra(numero) {
	if (rolagem.oBarra[numero] != 0) {
		y = -rolagem.oTexto[numero].y / (rolagem.oTexto[numero].scrollHeight - rolagem.oContainer[numero].clipHeight);
		y = y * (rolagem.Tamanho[numero] - rolagem.Altura[numero]);
		if (y > rolagem.Tamanho[numero] - rolagem.Altura[numero])
			y = rolagem.Tamanho[numero] - rolagem.Altura[numero];
		rolagem.oBarra[numero].moveIt(0, y);
	}
}

function oRolagem() {
	this.oContainer = new Array;
	this.oTexto = new Array;
	this.oBarra = new Array;
	this.Altura = new Array;
	this.Tamanho = new Array;
	this.Arrastar = new Array;
	this.Total = 0;
	this.Ativo = 0;
	this.Arrastando = 0;
	this.Y = 0;
	this.AdicionaRolagem = AdicionaRolagem;
	this.Rola = Rola;
	this.NaoRola = NaoRola;
	this.Mostra = Mostra;
	this.Oculta = Oculta;
	this.ComecaArrasto = ComecaArrasto;
	this.FimArrasto = FimArrasto;
	this.Arrasta = Arrasta;
	this.SetaAtivo = SetaAtivo;
	textoCarregado = true;
};

function AdicionaRolagem(container, texto, barracontainer, barra, altura, tamanho, arrastar) {
	this.oContainer[this.Total] = new makeObj(container);
	this.oTexto[this.Total] = new makeObj(texto, container);
	if (AdicionaRolagem.arguments.length < 7) {
		this.oBarra[this.Total] = 0;
		this.Altura[this.Total] = 0;
		this.Tamanho[this.Total] = 0;
		this.Arrastar[this.Totoal] = 0;
	}
	else {	
		this.oBarra[this.Total] = new makeObj(barra, barracontainer);
		this.Altura[this.Total] = altura;
		this.Tamanho[this.Total] = tamanho;
		if (bw.ie4)
			this.Arrastar[this.Total] = 0
		else
			this.Arrastar[this.Total] = arrastar;
	};
	this.Total++;
};

function Rola(numero, velocidade) {
	if (textoCarregado) {
		loop = true;
		if (velocidade > 0)
			this.oTexto[numero].down(numero, velocidade);
		else
			this.oTexto[numero].up(numero, velocidade);
	};
};

function NaoRola() {
	loop = false;
};

function Mostra(numero) {
//	alert(numero);
	//if (numero == 1){
		//this.oTexto[0].css.visibility = "hidden";		
//	}
	this.oTexto[numero].css.visibility = "visible";
	this.Ativo = numero;
	RolaBarra(numero);
	if (this.oBarra[numero] != 0)
		if (rolagem.oTexto[numero].scrollHeight > rolagem.oContainer[numero].clipHeight)
			this.oBarra[numero].css.visibility = "visible";
	if (this.Arrastar[numero]) {
		if (bw.ns4)
			this.oBarra[numero].el.captureEvents(Event.MOUSUP|Event.MOUSEDOWN);
		this.oBarra[numero].el.onmousedown = this.ComecaArrasto;
		this.oBarra[numero].el.onmouseup = this.FimArrasto;
	}
};

function Oculta(numero) {

	this.oTexto[numero].css.visibility = "hidden";
	if (this.oBarra[numero] != 0)
	this.oBarra[numero].css.visibility = "hidden";
};

function SetaAtivo(numero) {
	this.Ativo = numero;
}

function ComecaArrasto(e) {
	if (bw.ns4)
		if (e.which == 1) {
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			window.onmousemove = Arrasta;
			window.onmouseup = FimArrasto;
			rolagem.Y = e.pageY;
			rolagem.Arrastando = true;
			travado = rolagem.Y - rolagem.oBarra[rolagem.Ativo].y;
			return false;
		}
		else
			return true;
	else
		if (event.button == 1) {
			document.body.onmousemove = Arrasta;
			document.body.onmouseup = FimArrasto;
			rolagem.Y = event.clientY;
			rolagem.Arrastando = true;
			travado = rolagem.Y - rolagem.oBarra[rolagem.Ativo].y;
			return false;
		}
		else
			return true;
}

function FimArrasto(e) {
	if (bw.ns4)
		if (e.which == 1) {
			window.releaseEvents(Event.MOUSEMOVE);
			window.onmousemove = null;
			window.onmouseup = null;
			rolagem.Arrastando = false;
			return false;
		}
		else
			return true;
	else
		if (event.button == 1) {
			document.body.onmousemove = null;
			document.body.onmouseup = null;
			rolagem.Arrastando = false;
			return false;
		}
		else
			return true;
}

function Arrasta(e) {
	if (bw.ns4) {
		if (rolagem.Arrastando) {
			temp = rolagem.oBarra[rolagem.Ativo].y + e.pageY - rolagem.Y;
			if (temp < 0) {
				travou = -1;
				temp = 0;
				rolagem.Arrastando = false;
			}
			if (temp > rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo]) {
				travou = 1;
				temp = rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo];
				rolagem.Arrastando = false;
			}
			rolagem.oBarra[rolagem.Ativo].moveIt(0, temp);
			rolagem.Y = e.pageY;
			BarraRola(rolagem.Ativo);
			return false;
		}
		else {
			if (travou < 0)
				if (e.pageY >= travado) {
					rolagem.Arrastando = true;
					rolagem.Y = travado;
					travou = 0;
				}
			if (travou > 0)
				if (e.pageY <= (travado + rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo])) {
					rolagem.Arrastando = true;
					rolagem.Y = travado + rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo];
					travou = 0;
				}
			return false;
		}
	}
	else
		if (rolagem.Arrastando) {
			temp = rolagem.oBarra[rolagem.Ativo].y + event.clientY - rolagem.Y;
			travou = 0;
			if (temp < 0) {
				travou = -1;
				temp = 0;
				rolagem.Arrastando = false;
			}
			if (temp > rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo]) {
				travou = 1;
				temp = rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo];
				rolagem.Arrastando = false;
			}
			rolagem.oBarra[rolagem.Ativo].moveIt(0, temp);
			rolagem.Y = event.clientY;
			BarraRola(rolagem.Ativo);
			return false;
		}
		else {
			if (travou < 0)
				if (event.clientY >= travado) {
					rolagem.Arrastando = true;
					rolagem.Y = travado;
					travou = 0;
				}
			if (travou > 0)
				if (event.clientY <= (travado + rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo])) {
					rolagem.Arrastando = true;
					rolagem.Y = travado + rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo];
					travou = 0;
				}
			return false;
		}
}

function BarraRola() {
	y = rolagem.oBarra[rolagem.Ativo].y / (rolagem.Tamanho[rolagem.Ativo] - rolagem.Altura[rolagem.Ativo]);
	y = y * (rolagem.oTexto[rolagem.Ativo].scrollHeight - rolagem.oContainer[rolagem.Ativo].clipHeight);
	y = - Math.round(y);
	rolagem.oTexto[rolagem.Ativo].moveIt(0, y);
}

if (bw.bw) {
	rolagem = new oRolagem;
};