onload=eventLoader

var upH = 9; // Height of up-arrow
var upW = 5; // Width of up-arrow
var downH = 9; // Height of down-arrow
var downW = 5; // Width of down-arrow
var dragH = 26; // Height of scrollbar
var dragW = 17; // Width of scrollbar
var scrollH = 180; // Height of scrollbar
var speed = 4; // Scroll speed
var tocando = 0;
var tocando1 = 0;
// 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
var content;

// 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);
	startY1 = (mouseY - dragT1);
	// 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();
		}
	}
//para el scroll 2
	// If click on up-arrow
	else if(mouseX >= upL1 && (mouseX <= (upL1 + upW1)) && mouseY >= upT1 && (mouseY <= (upT1 + upH1))){
		clickUp1 = true;
		return scrollUp1();
	}	
	// Else if click on down-arrow
	else if(mouseX >= downL1 && (mouseX <= (downL1 + downW1)) && mouseY >= downT1 && (mouseY <= (downT1 + downH1))){
		clickDown1 = true;
		return scrollDown1();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL1 && (mouseX <= (dragL1 + dragW1)) && mouseY >= dragT1 && (mouseY <= (dragT1 + dragH1))){
		clickDrag1 = true;
		return false;
	}
	else if(mouseX >= dragL1 && (mouseX <= (dragL1 + dragW1)) && mouseY >= rulerT1 && (mouseY <= (rulerT1 + scrollH1))){
		// If click above drag
		if(mouseY < dragT1){
			clickAbove1 = true;
			clickUp1 = true;
			return scrollUp1();
		}
		// Else click below drag
		else{
			clickBelow1 = true;
			clickDown1 = true;
			return scrollDown1();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
//Parte del div que se mueve
	if (window.ss) {
            var x=(nav)?  e.pageX  :  event.x+document.body.scrollLeft; 
            var y=(nav)?  e.pageY  :  event.y+document.body.scrollTop; 
            skn.left=x+Xoffset; 
            skn.top=y+Yoffset; 
	}
//FINParte del div que se mueve
	getContent();
	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=contentT*(-1);
		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
	else {
		if(clickDrag1 && contentH1 > contentClipH1){
			getMouse(e);
			dragT1 = (mouseY - startY1);
		
			if(dragT1 < (rulerT1))
				dragT1 = rulerT1;		
			if(dragT1 > (rulerT1 + scrollH1 - dragH1))
				dragT1 = (rulerT1 + scrollH1 - dragH1);
		
			contentT1 = ((dragT1- rulerT1)*(1/scrollLength1));
			contentT1=contentT1*(-1);	
	
			moveTo1();
		
			// So ie-pc doesn't select gifs
			if(ie4)
				return false;
		}
	}
}

function up(){
	clearTimeout(timer);
	clearTimeout(timer1);
	// Resetting variables
	if (tocando!=1){
	clickUp = false;
	clickDown = false;
	}
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	
	if (tocando1!=1){
	clickUp1 = false;
	clickDown1 = false;
	}
	clickDrag1 = false;
	clickAbove1 = false;
	clickBelow1 = false;
	return true;
}

// Reads content layer top
function getT(){
	if(ie4)
		contentT = document.all.content.style.pixelTop;
	else if(nn4)
		contentT = document.contentClip.document.content.top;
	else if(dom)
		contentT = parseInt(document.getElementById("content").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){
		document.all.content.style.top = contentT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.contentClip.document.content.top = contentT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("content").style.top = contentT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
}

// Scrolls up
function scrollUp(){
	getT();
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		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(){
	getContent();
	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();
}

function getContent(){
	if (ie4){
		// Height of content layer and clip layer
		contentH = parseInt(document.all.content.scrollHeight);
		contentClipH = parseInt(document.all.contentClip.style.height);
	}
	else if (nn4){
		// Height of content layer and clip layer
		contentH = document.contentClip.document.content.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;	
	}
	else if(dom){
		contentH = parseInt(document.getElementById("content").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));

}

// Preload
function eventLoader(){
	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		// Ruler Y variable
		rulerT = document.all.ruler.style.pixelTop;

	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.up.left;
		upT = document.up.top;		
		// Down-arrow X and Y variables
		downL = document.down.left;
		downT = document.down.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		rulerT = document.ruler.top;

	}
	else if(dom){
                document.getElementById("up").style.top=(parseInt(document.getElementById("up").style.top)-16)+ "px";
                document.getElementById("up1").style.top=(parseInt(document.getElementById("up1").style.top)-16)+ "px";
                document.getElementById("down").style.top=(parseInt(document.getElementById("down").style.top)-16)+ "px";
                document.getElementById("down1").style.top=(parseInt(document.getElementById("down1").style.top)-16)+ "px";
                document.getElementById("drag").style.top=(parseInt(document.getElementById("drag").style.top)-16)+ "px";
                document.getElementById("drag1").style.top=(parseInt(document.getElementById("drag1").style.top)-16)+ "px";
                document.getElementById("ruler").style.top=(parseInt(document.getElementById("ruler").style.top)-16)+ "px";
                document.getElementById("ruler1").style.top=(parseInt(document.getElementById("ruler1").style.top)-16)+ "px";
                document.getElementById("fondo").style.top=(parseInt(document.getElementById("fondo").style.top)-16)+ "px";
                document.getElementById("fondo1").style.top=(parseInt(document.getElementById("fondo1").style.top)-16)+ "px";

                document.getElementById("contentClip").style.top=(parseInt(document.getElementById("contentClip").style.top)-16)+ "px";

		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left);
		upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left);
		downT = parseInt(document.getElementById("down").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left);
		dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").style.top);
		document.getElementById("content").style.top = 0 + "px";
	}
	getContent();

	// Initializes event capturing
	eventLoader1();
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
	
	ensenarObjetos();
	esconder1();
	esconder2();
}

function showObject(obj) {
	if (ns4) obj.visibility = "show"
	else if (ie4 || ns6) {obj.visibility = "visible";}
}

function layerWrite(id,nestref,text) {
	if (ie4) {
		document.all[id].innerHTML = text;

	}
	else if (nn4) {		
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
		lyr.open();
		lyr.write(text);
		lyr.close();}
	else if (dom) {document.getElementById(id).innerHTML = text;}
}

function ensenarObjetos(){
text="<table border='0' width='300'>\n";
for (i=0;i<datos.array.length;i++){
  text=text+"<tr><td height='25' align=right><p><a href='javascript:void(null)' onClick='ensenarInformacion("+datos.array[i].name+");'><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#082039'><b>-"+datos.array[i].texto+"</b></font></a></p></td></tr>\n"; }
text=text+"</table>\n";
layerWrite("content","contentClip",text);
text="";
}


function ensenarInformacion(objeto){
	if(ie4){
		document.all.drag1.style.pixelTop=138;		
		document.all.ruler1.style.pixelTop=138;
		document.all.content1.style.pixelTop=0;
		dragT1=138;
		rulerT1=138;
	}
	else if(nn4){
		document.drag1.top=138;		
		document.ruler1.top=138;
		document.contentClip.document.content1.top=0;
		dragT1=138;
		rulerT1=138;
	}
	else if(dom){
		document.getElementById("drag1").style.top=122 + "px";
		document.getElementById("ruler1").style.top=122 + "px";
		document.getElementById("content1").style.top = 0 + "px";
		dragT1=122;
		rulerT1=122;
	}
texto="";
texto=texto+"<table border='0' width='300'>\n";
texto=texto+"<tr><td align=left><p><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'><b>"+objeto.texto+"</b></font></p></td></tr>\n";
texto=texto+"<tr><td align=left><p><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'><b>"+objeto.nombre+"</b></font></p></td></tr>\n";
texto=texto+"<tr><td><font class=letrapequena>&nbsp;</font></td></tr>\n";
if (objeto.link != "")

{
texto=texto+"<tr><td align=right>";
texto+="<table border='0' width='300'>";
texto+="<tr>";
texto+="<td width='200'>";
texto+="&nbsp;";
texto+="</td>";
texto+="<table border='0' cellspacing='0' cellpadding='0' width='100'>";
texto+="<tr>";
texto+="<td width='1' height='1' bgcolor=#000000><img src='/images/pixel.gif' width='1' height='1'></td>";
texto+="<td width='98' height='1' bgcolor=#000000><img src='/images/pixel.gif' width='98' height='1'></td>";
texto+="<td width='1' height='1' bgcolor=#000000><img src='/images/pixel.gif' width='1' height='1'></td>";
texto+="</tr>";
texto+="<tr>";
texto+="<td width='1' bgcolor=#000000><img src='/images/pixel.gif width='1' height='1'></td>";
texto+="<td width='100' align='center' background='/images/pixel.gif' bgcolor=#72B4CC>";
texto+="<p>";
texto+="<a href='#' onclick=javascript:window.open('"+objeto.link+"','','')>";
texto+="<font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#000000'>";
texto+="<b>"+objeto.iralsitio;
texto+="</b>";
texto+="</font>";
texto+="</a>";
texto+="</p>";
texto+="</td>";
texto+="<td width='1' bgcolor=#000000><img src='/images/pixel.gif width='1' height='1'></td>";
texto+="</tr>";
texto+="<tr>";
texto+="<td width='1' height='1' bgcolor=#000000><img src='/images/pixel.gif' width='1' height='1'></td>";
texto+="<td width='98' height='1' bgcolor=#000000><img src='/images/pixel.gif' width='1' height='1'></td>";
texto+="<td width='1' height='1' bgcolor=#000000><img src='/images/pixel.gif' width='1' height='1'></td>";
texto+="</tr></table>";
texto+="</tr>";
texto+="</table>";
texto+="</td>";
texto+="</tr>\n";
}
texto=texto+"</table>\n";
layerWrite("content1","contentClip",texto);
esconder2()
}

function esconder1() {
	if (nn4) {
		var prof = document.contentClip.document.content.clip.bottom;
		var profCont = document.contentClip.clip.bottom;
		if (profCont >= prof){ 
			document.up.visibility="hide";
			document.down.visibility="hide";
			document.drag.visibility="hide";
			document.ruler.visibility="hide";
			document.fondo.visibility="hide";
			}
		else   { 
			document.up.visibility="show";
			document.down.visibility="show";
			document.drag.visibility="show";
			document.ruler.visibility="show";
			document.fondo.visibility="show"; 
			}
	}
	if (ie4) {		
		var prof = parseInt(document.all.content.scrollHeight);
		var profCont = parseInt(document.all.contentClip.style.height);
		if (profCont >= prof){
			document.all.up.style.visibility="hidden";
			document.all.down.style.visibility="hidden";
			document.all.drag.style.visibility="hidden";
			document.all.ruler.style.visibility="hidden";
			document.all.fondo.style.visibility="hidden";}
		else 	{			
			document.all.up.style.visibility="visible";
			document.all.down.style.visibility="visible";
			document.all.drag.style.visibility="visible";
			document.all.ruler.style.visibility="visible";
			document.all.fondo.style.visibility="visible";
			}
	}
        if (dom) {
                var prof = parseInt(document.getElementById("content").offsetHeight);
                var profCont = parseInt(document.getElementById("contentClip").offsetHeight);
                if (profCont >= prof){
                        document.getElementById("up").style.visibility="hidden";
                        document.getElementById("down").style.visibility="hidden";
                        document.getElementById("drag").style.visibility="hidden";
                        document.getElementById("ruler").style.visibility="hidden";
                        document.getElementById("fondo").style.visibility="hidden";
                        }
                else    {
                        document.getElementById("up").style.visibility="visible";
                        document.getElementById("down").style.visibility="visible";
                        document.getElementById("drag").style.visibility="visible";
                        document.getElementById("ruler").style.visibility="visible";
                        document.getElementById("fondo").style.visibility="visible"; 
                        }
        }
}

function esconder2() {
	if (nn4) {
		var prof = document.contentClip.document.content1.clip.bottom;
		var profCont = document.contentClip.clip.bottom;
		if (profCont >= prof){			
			document.up1.visibility="hide";
			document.down1.visibility="hide";
			document.drag1.visibility="hide";
			document.ruler1.visibility="hide";
			document.fondo1.visibility="hide";
			}
		else   { 
			document.up1.visibility="show";
			document.down1.visibility="show";
			document.drag1.visibility="show";
			document.ruler1.visibility="show";
			document.fondo1.visibility="show";
			}
	}
	else if (ie4) {		
		var prof = parseInt(document.all.content1.scrollHeight);
		var profCont = parseInt(document.all.contentClip.style.height);
		if (profCont >= prof){			
			document.all.up1.style.visibility="hidden";
			document.all.down1.style.visibility="hidden";
			document.all.drag1.style.visibility="hidden";
			document.all.ruler1.style.visibility="hidden";
			document.all.fondo1.style.visibility="hidden";}
		else 	{			
			document.all.up1.style.visibility="visible";
			document.all.down1.style.visibility="visible";
			document.all.drag1.style.visibility="visible";
			document.all.ruler1.style.visibility="visible";
			document.all.fondo1.style.visibility="visible";
			}
	}
        if (dom) {
                var prof = parseInt(document.getElementById("content1").offsetHeight);
                var profCont = parseInt(document.getElementById("contentClip").offsetHeight);
                if (profCont >= prof){
                        document.getElementById("up1").style.visibility="hidden";
                        document.getElementById("down1").style.visibility="hidden";
                        document.getElementById("drag1").style.visibility="hidden";
                        document.getElementById("ruler1").style.visibility="hidden";
                        document.getElementById("fondo1").style.visibility="hidden";
                        }
                else    {
                        document.getElementById("up1").style.visibility="visible";
                        document.getElementById("down1").style.visibility="visible";
                        document.getElementById("drag1").style.visibility="visible";
                        document.getElementById("ruler1").style.visibility="visible";
                        document.getElementById("fondo1").style.visibility="visible"; 
                        }
        }
}
