// Cross-Browser Functions

var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;

function addEvent(event,method){
this[event] = method;
if(ns4) this.captureEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function removeEvent(event){
this[event] = null;
if(ns4) this.releaseEvents(Event[event.substr(2,event.length).toUpperCase()]);
}
function getElement(name,nest){
nest = nest ? "document."+nest+"." : "";
var el = dom ? document.getElementById(name) : iex ? document.all[name] : ns4 ? eval(nest+"document."+name) : false;
el.css = ns4 ? el : el.style;
el.getTop = function(){return parseInt(el.css.top) || 0};
el.setTop = function(y){el.css.top = ns4 ? y: y+"px"};
el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
el.getClipHeight = function(){return ns4 ? el.clip.height : el.offsetHeight};
el.hideVis = function(){el.css.visibility="hidden"};
el.addEvent = addEvent;
el.removeEvent = removeEvent;
return el;
}
function getYMouse(e){
return iex ? event.clientY : e.pageY;
}

document.addEvent = addEvent;
document.removeEvent = removeEvent;

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Scroller Class

ScrollObj = function(speed, dragHeight, trackHeight, trackObj, upObj, downObj, dragObj, contentMaskObj, contentObj){
this.speed = speed;
this.dragHeight = dragHeight;
this.trackHeight = trackHeight;
this.trackObj = getElement(trackObj);
this.upObj = getElement(upObj);
this.downObj = getElement(downObj);
this.dragObj = getElement(dragObj);
this.contentMaskObj = getElement(contentMaskObj);
this.contentObj = getElement(contentObj,contentMaskObj);
this.obj = contentObj+"Object";
eval(this.obj+"=this");

this.trackTop = this.dragObj.getTop();
this.trackLength = this.trackHeight-this.dragHeight;
this.trackBottom = this.trackTop+this.trackLength;
this.contentMaskHeight = this.contentMaskObj.getClipHeight();
this.contentHeight = this.contentObj.getHeight();
this.contentLength = this.contentHeight-this.contentMaskHeight;
this.scrollLength = this.trackLength/this.contentLength;
this.scrollTimer = null;

if(this.contentHeight <= this.contentMaskHeight){
this.dragObj.hideVis();
}else{
var self = this;
this.trackObj.addEvent("onmousedown", function(e){self.scrollJump(e);return false});
this.upObj.addEvent("onmousedown", function(){self.scroll(self.speed);return false});
this.upObj.addEvent("onmouseup", function(){self.stopScroll()});
this.upObj.addEvent("onmouseout", function(){self.stopScroll()});
this.downObj.addEvent("onmousedown", function(){self.scroll(-self.speed);return false});
this.downObj.addEvent("onmouseup", function(){self.stopScroll()});
this.downObj.addEvent("onmouseout", function(){self.stopScroll()});
this.dragObj.addEvent("onmousedown", function(e){self.startDrag(e);return false});
if(iex) this.dragObj.addEvent("ondragstart", function(){return false});
}
}
ScrollObj.prototype.startDrag = function(e){
this.dragStartMouse = getYMouse(e);
this.dragStartOffset = this.dragObj.getTop();
var self = this;
document.addEvent("onmousemove", function(e){self.drag(e)});
document.addEvent("onmouseup", function(){self.stopDrag()});
}
ScrollObj.prototype.stopDrag = function(){
document.removeEvent("onmousemove");
document.removeEvent("onmouseup");
}
ScrollObj.prototype.drag = function(e){
var currentMouse = getYMouse(e);
var mouseDifference = currentMouse-this.dragStartMouse;
var dragDistance = this.dragStartOffset+mouseDifference;
var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
this.dragObj.setTop(dragMovement);
var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
this.contentObj.setTop(contentMovement);
}
ScrollObj.prototype.scroll = function(speed){
var contentMovement = this.contentObj.getTop()+speed;
var dragMovement = this.trackTop-Math.round(this.contentObj.getTop()*(this.trackLength/this.contentLength));
if(contentMovement > 0){
contentMovement = 0;
}else if(contentMovement < -this.contentLength){
contentMovement = -this.contentLength;
}
if(dragMovement < this.trackTop){
dragMovement = this.trackTop;
}else if(dragMovement > this.trackBottom){
dragMovement = this.trackBottom;
}
this.contentObj.setTop(contentMovement);
this.dragObj.setTop(dragMovement);
this.scrollTimer = window.setTimeout(this.obj+".scroll("+speed+")",25);
}
ScrollObj.prototype.stopScroll = function(){
if(this.scrollTimer){
window.clearTimeout(this.scrollTimer);
this.scrollTimer = null;
}
}
ScrollObj.prototype.scrollJump = function(e){
var currentMouse = getYMouse(e);
var dragDistance = currentMouse-(this.dragHeight/2);
var dragMovement = (dragDistance<this.trackTop) ? this.trackTop : (dragDistance>this.trackBottom) ? this.trackBottom : dragDistance;
this.dragObj.setTop(dragMovement);
var contentMovement = -(dragMovement-this.trackTop)*(1/this.scrollLength);
this.contentObj.setTop(contentMovement);
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Misc Functions

function fixNetscape4(){
if(ns4origWidth != window.innerWidth || ns4origHeight != window.innerHeight){
window.location.reload();
}	
}
if(document.layers){
ns4origWidth = window.innerWidth;
ns4origHeight = window.innerHeight;
window.onresize = fixNetscape4;
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Controla as informações do link
tooltip = {
	name : "tooltipDiv",
	offsetX : -60,
	offsetY : -60,
	tip : null
};
tooltip.init = function () {
	if (!document.getElementById) return;
	
	// It would be nice to be able to generate the tooltip div, 
	// but when using document.createElement Explorer5/MacOS9, 
	// the tooltip div becomes 100% of the window height.
	// Therefore, we have to use document.getElementById to access
	// a div that is already in the body.
	
	// this.tip = document.createElement ("div");
	// this.tip.setAttribute ("id", this.name);
	// document.body.appendChild (this.tip);
	
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
	
	var a;
	var anchors = document.getElementsByTagName ("a");
	for (var i = 0; i < anchors.length; i ++) {
		a = anchors[i];
		if (a.className == "tooltip") {
			a.onmouseover = function () {tooltip.show (this.title)};
			a.onmouseout = function () {tooltip.hide ()};
		}
	}
};
tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {// Explorer
	
		// Explorer5 contains the documentElement object but it's empty, 
		// so we must check if the scrollLeft property is available.
		
		// If Explorer6 is in Quirks mode, the documentElement properties 
		// will still be defined, but they will contain the number 0.
		
		// If Explorer6 is in Standards compliant mode, the document.body 
		// properties will still be defined, but they will contain the number 0.
		
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {// Mozilla
		x = evt.pageX;
		y = evt.pageY;
	}
	// If the style property value is not a string containing the unit measurement,
	// browsers in standard compliant mode will not set the property.
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
};
tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "visible";
	this.tip.style.display = "block";
};
tooltip.hide = function () {
	if (!this.tip) return;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "hidden";
	this.tip.style.display = "none";
	this.tip.innerHTML = "";
};

//função abre janela
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+','
win = window.open(mypage,myname,settings)
}

