// Made by geeeet@ghtml.com
// Keep these two lines and you're free to use this code

// Known bugs :
// If ie4.5 mac, please press apple-t to remove sidebar, otherwise everything is pushed 20px to the right...

// Corrected bugs :
// 25.01.2001 - When the height of the span "content" was less than the height of the span "contentClip" a javascript error occured, function changed : move()
// 21.02.2001 - Scrolling text wasn't selectable in ie, function changed : move()
// 05.03.2001 - Ie x and y coordinates was wrong when page was scrolled, function changed : getMouse()

// 19.04.2001 - Finally able to remove browser-scrollbar if content is longer than the browser is high:
// Just put this in the style-tag right before the end head-tag:
// body {margin-left:0; margin-right:0; margin-top:0; margin-bottom:0; width:100%;height:100%;overflow:hidden}

// Touch me here :-)
var upH = 16; // Height of up-arrow
var upW = 6; // Width of up-arrow
var downH = 16; // Height of down-arrow
var downW = 6; // Width of down-arrow
var dragH = 36; // Height of scrollbar
var dragW = 6; // Width of scrollbar
var scrollH = 210; // Height of scrollbar
var speed = 4; // Scroll speed

// And now... go to the bottom of the page...

// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

var timer = setTimeout("",500); // Repeat variable
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

//variaveis do homero

var contentAtual;
var rulerAtual;
var dragAtual;

// Mousedown
function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);
	startY = (mouseY - dragT);
//	alert('dragL ==>' + dragL + '\n  dragT ==>' + dragT)
//	alert('mouseX ==>' + mouseX + '\n  mouseY ==>' + mouseY)
//	alert('dragLat ==>' + dragLat + '\n  dragTop ==>' + dragTop)
	// If click on up-arrow
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	// Else if click on down-arrow
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
		clickDown = true;
		return scrollDown();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		// If click above drag
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		// Else click below drag
		else{
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag && contentH > contentClipH){
		getMouse(e);
		dragT = (mouseY - startY);
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT = eval('-' + contentT);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
}

function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads content layer top
function getT(){
	if(ie4)
		contentT = contentAtual.style.pixelTop;
	else if(nn4)
		contentT = contentAtual.top;
	else if(dom)
		contentT = parseInt(contentAtual.style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}

// Moves the layer
function moveTo(){
	if(ie4){
		contentAtual.style.top = contentT;
		rulerAtual.style.top = dragT;
		dragAtual.style.top = dragT;
	}
	else if(nn4){
		contentAtual.top = contentT;
		rulerAtual.top = dragT;
		dragAtual.top = dragT;
	}
	else if(dom){
		contentAtual.style.top = contentT + "px";
		rulerAtual.top.style.top = dragT + "px";
		dragAtual.style.top = dragT + "px";
	}
}

// Scrolls up
function scrollUp(){
	getT();
	
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
//		alert(contentT)
		if(contentT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			contentT = contentT + speed;
			if(contentT > 0)
				contentT = 0;
			
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

// Scrolls down
function scrollDown(){
	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}

	if(clickDown){
		if(contentT > -(contentH - contentClipH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			contentT = contentT - speed;
			if(contentT < -(contentH - contentClipH))
				contentT = -(contentH - contentClipH);
			
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload Agenda
function eventLoader(topRuler)
{
	up();

	//constantes
	upH = 16; // Height of up-arrow
	upW = 6; // Width of up-arrow
	downH = 16; // Height of down-arrow
	downW = 6; // Width of down-arrow
	dragH = 36; // Height of scrollbar
	dragW = 6; // Width of scrollbar
	scrollH = 208; // Height of scrollbar
	clickUp = false; // If click on up-arrow
	clickDown = false; // If click on down-arrow
	clickDrag = false; // If click on scrollbar
	clickAbove = false; // If click above scrollbar
	clickBelow = false; // If click below scrollbar		
	rulerT = topRuler;

	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.upAgenda.style.pixelLeft;
		upT = document.all.upAgenda.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.downAgenda.style.pixelLeft;
		downT = document.all.downAgenda.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.dragAgenda.style.pixelLeft;
		dragT = document.all.dragAgenda.style.pixelTop;
		// Height of content layer and clip layer
		contentH = parseInt(document.all.contentAgenda.scrollHeight);
		contentClipH = parseInt(document.all.contentClipAgenda.style.height);
		//setando variaveis do homer
		contentT = parseInt(document.all.dragAgenda.style.posTop);
		contentAtual = document.all.contentAgenda;
		rulerAtual	 = document.all.rulerAgenda;
		dragAtual	 = document.all.dragAgenda;		
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.upAgenda.left;
		upT = document.upAgenda.top;		
		// Down-arrow X and Y variables
		downL = document.downAgenda.left;
		downT = document.downAgenda.top;		
		// Scrollbar X and Y variables
		dragL = document.dragAgenda.left;
		dragT = document.dragAgenda.top;		
		// Height of content layer and clip layer
		contentH = document.contentClipAgenda.document.contentAgenda.clip.bottom;
		contentClipH = document.contentClipAgenda.clip.bottom;
		//setando variaveis do homer
		contentT = parseInt(document.drag.style.posTop);		
		contentAtual = document.contentClipAgenda.document.contentAgenda;
		rulerAtual	 = document.rulerAgenda;
		dragAtual	 = document.dragAgenda;		
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("upAgenda").style.left);
		upT = parseInt(document.getElementById("upAgenda").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("downAgenda").style.left);
		downT = parseInt(document.getElementById("downAgenda").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("dragAgenda").style.left);
		dragT = parseInt(document.getElementById("dragAgenda").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("contentAgenda").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClipAgenda").offsetHeight);
		document.getElementById("contentAgenda").style.top = 0 + "px";
		//setando variaveis do homer
		contentT = parseInt(document.getElementById("dragAgenda").style.posTop);
		contentAtual = document.getElementById("contentAgenda");
		rulerAtual	 = document.getElementById("rulerAgenda");			
		dragAtual	 = document.getElementById("dragAgenda");		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
	
}

//scroll da galeria
function scrollGaleria(topRuler)
{
	up();

	//constantes
	upH = 16; // Height of up-arrow
	upW = 6; // Width of up-arrow
	downH = 16; // Height of down-arrow
	downW = 6; // Width of down-arrow
	dragH = 36; // Height of scrollbar
	dragW = 6; // Width of scrollbar
	scrollH = 205; // Height of scrollbar
	clickUp = false; // If click on up-arrow
	clickDown = false; // If click on down-arrow
	clickDrag = false; // If click on scrollbar
	clickAbove = false; // If click above scrollbar
	clickBelow = false; // If click below scrollbar		
	rulerT = topRuler;

	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.upGaleria.style.pixelLeft;
		upT = document.all.upGaleria.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.downGaleria.style.pixelLeft;
		downT = document.all.downGaleria.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.dragGaleria.style.pixelLeft;
		dragT = document.all.dragGaleria.style.pixelTop;
		// Height of content layer and clip layer
		contentH = parseInt(document.all.contentGaleria.scrollHeight);
		contentClipH = parseInt(document.all.contentClipGaleria.style.height);
		//setando variaveis do homer
		contentT = parseInt(document.all.dragGaleria.style.posTop);
		contentAtual = document.all.contentGaleria;
		rulerAtual	 = document.all.rulerGaleria;
		dragAtual	 = document.all.dragGaleria;		
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.upGaleria.left;
		upT = document.upGaleria.top;		
		// Down-arrow X and Y variables
		downL = document.downGaleria.left;
		downT = document.downGaleria.top;		
		// Scrollbar X and Y variables
		dragL = document.dragGaleria.left;
		dragT = document.dragGaleria.top;		
		// Height of content layer and clip layer
		contentH = document.contentClipGaleria.document.contentGaleria.clip.bottom;
		contentClipH = document.contentClipGaleria.clip.bottom;
		//setando variaveis do homer
		contentT = parseInt(document.drag.style.posTop);		
		contentAtual = document.contentClipGaleria.document.contentGaleria;
		rulerAtual	 = document.rulerGaleria;
		dragAtual	 = document.dragGaleria;		
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("upGaleria").style.left);
		upT = parseInt(document.getElementById("upGaleria").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("downGaleria").style.left);
		downT = parseInt(document.getElementById("downGaleria").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("dragGaleria").style.left);
		dragT = parseInt(document.getElementById("dragGaleria").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("contentGaleria").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClipGaleria").offsetHeight);
		document.getElementById("contentGaleria").style.top = 0 + "px";
		//setando variaveis do homer
		contentT = parseInt(document.getElementById("dragGaleria").style.posTop);
		contentAtual = document.getElementById("contentGaleria");
		rulerAtual	 = document.getElementById("rulerGaleria");			
		dragAtual	 = document.getElementById("dragGaleria");		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	}


// Scroll do curso
function scrollCurso(topRuler){
	up();

	//constantes
	upH = 16; // Height of up-arrow
	upW = 6; // Width of up-arrow
	downH = 16; // Height of down-arrow
	downW = 6; // Width of down-arrow
	dragH = 36; // Height of scrollbar
	dragW = 6; // Width of scrollbar
	scrollH = 205; // Height of scrollbar
	clickUp = false; // If click on up-arrow
	clickDown = false; // If click on down-arrow
	clickDrag = false; // If click on scrollbar
	clickAbove = false; // If click above scrollbar
	clickBelow = false; // If click below scrollbar		
	rulerT = topRuler;

	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.upCurso.style.pixelLeft;
		upT = document.all.upCurso.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.downCurso.style.pixelLeft;
		downT = document.all.downCurso.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.dragCurso.style.pixelLeft;
		dragT = document.all.dragCurso.style.pixelTop;
		// Height of content layer and clip layer
		contentH = parseInt(document.all.contentCurso.scrollHeight);
		contentClipH = parseInt(document.all.contentClipCurso.style.height);
		//setando variaveis do homer
		contentT = parseInt(document.all.dragCurso.style.posTop);
		contentAtual = document.all.contentCurso;
		rulerAtual	 = document.all.rulerCurso;
		dragAtual	 = document.all.dragCurso;		
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.upCurso.left;
		upT = document.upCurso.top;		
		// Down-arrow X and Y variables
		downL = document.downCurso.left;
		downT = document.downCurso.top;		
		// Scrollbar X and Y variables
		dragL = document.dragCurso.left;
		dragT = document.dragCurso.top;		
		// Height of content layer and clip layer
		contentH = document.contentClipCurso.document.contentCurso.clip.bottom;
		contentClipH = document.contentClipCurso.clip.bottom;
		//setando variaveis do homer
		contentT = parseInt(document.drag.style.posTop);		
		contentAtual = document.contentClipCurso.document.contentCurso;
		rulerAtual	 = document.rulerCurso;
		dragAtual	 = document.dragCurso;		
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("upCurso").style.left);
		upT = parseInt(document.getElementById("upCurso").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("downCurso").style.left);
		downT = parseInt(document.getElementById("downCurso").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("dragCurso").style.left);
		dragT = parseInt(document.getElementById("dragCurso").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("contentCurso").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClipCurso").offsetHeight);
		document.getElementById("contentCurso").style.top = 0 + "px";
		//setando variaveis do homer
		contentT = parseInt(document.getElementById("dragCurso").style.posTop);
		contentAtual = document.getElementById("contentCurso");
		rulerAtual	 = document.getElementById("rulerCurso");			
		dragAtual	 = document.getElementById("dragCurso");		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
}


// scroll do Conteudo interno

// Scroll do curso
//por causa do iFrame usa-se "top.document" 
function scrollConteudo(){
	up();

	//constantes
	upH = 12; // Height of up-arrow
	upW = 7; // Width of up-arrow
	downH = 12; // Height of down-arrow
	downW = 7; // Width of down-arrow
	dragH = 35; // Height of scrollbar
	dragW = 7; // Width of scrollbar
	scrollH = 196; // Height of scrollbar
	clickUp = false; // If click on up-arrow
	clickDown = false; // If click on down-arrow
	clickDrag = false; // If click on scrollbar
	clickAbove = false; // If click above scrollbar
	clickBelow = false; // If click below scrollbar		
	rulerT = 165;

	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.upConteudo.style.pixelLeft;
		upT = document.all.upConteudo.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.downConteudo.style.pixelLeft;
		downT = document.all.downConteudo.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.dragConteudo.style.pixelLeft;
		dragT = document.all.dragConteudo.style.pixelTop;
		// Height of content layer and clip layer
		contentH = eval("parseInt(top.document.ifrmConteudo.contentConteudo.scrollHeight)");
		contentClipH = eval("parseInt(top.document.ifrmConteudo.contentClipConteudo.style.height)");
		//setando variaveis do homer
		contentT = parseInt(document.all.dragConteudo.style.posTop);
		contentAtual = eval("top.document.ifrmConteudo.contentConteudo");
		rulerAtual	 = document.all.rulerConteudo;
		dragAtual	 = document.all.dragConteudo;		
	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.upConteudo.left;
		upT = document.upConteudo.top;		
		// Down-arrow X and Y variables
		downL = document.downConteudo.left;
		downT = document.downConteudo.top;		
		// Scrollbar X and Y variables
		dragL = document.dragConteudo.left;
		dragT = document.dragConteudo.top;		
		// Height of content layer and clip layer
		contentH = document.contentClipConteudo.document.contentConteudo.clip.bottom;
		contentClipH = document.contentClipConteudo.clip.bottom;
		//setando variaveis do homer
		contentT = parseInt(document.drag.style.posTop);		
		contentAtual = document.contentClipConteudo.document.contentConteudo;
		rulerAtual	 = document.rulerConteudo;
		dragAtual	 = document.dragConteudo;		
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("upConteudo").style.left);
		upT = parseInt(document.getElementById("upConteudo").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("downConteudo").style.left);
		downT = parseInt(document.getElementById("downConteudo").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("dragConteudo").style.left);
		dragT = parseInt(document.getElementById("dragConteudo").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("contentConteudo").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClipConteudo").offsetHeight);
		document.getElementById("contentConteudo").style.top = 0 + "px";
		//setando variaveis do homer
		contentT = parseInt(document.getElementById("dragConteudo").style.posTop);
		contentAtual = document.getElementById("contentConteudo");
		rulerAtual	 = document.getElementById("rulerConteudo");			
		dragAtual	 = document.getElementById("dragConteudo");		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;	
}


