// 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 = 15; // Height of up-arrow
var upW = 15; // Width of up-arrow
var downH = 15; // Height of down-arrow
var downW = 15; // Width of down-arrow
var dragH = 46; // Height of scrollbar
var dragW = 11; // Width of scrollbar
var scrollH = 223; // Height of scrollbar
var speed = 10; // 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 mac = navigator.userAgent.indexOf('Mac')>-1?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 clickRight = false;

var timer = setTimeout("",1000); // 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 dragbgL //dragbg x
var contentL // content x
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

//scroll right
var upL_r; // Up-arrow X
var downL_r; // Down-arrow X
var dragL_r; // Scrollbar X
var rulerL_r; // Ruler X
//var dragbgL_r //dragbg x
var contentL_r // content x
var dragT_r; // Scrollbar Y
var rulerT_r; // Ruler Y
var contentT_r; // Content layer Y;
var startY_r; // Keeps track of offset between mouse and span

// 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);		
		startY_r = (mouseY - dragT_r);
        
        // If click on up-arrow
        if((mouseX >= (upL - 5)) && (mouseX <= (upL + upW + 5)) && (mouseY >= (upT - 5)) && (mouseY <= (upT + upH + 5))){
                clickUp = true;
                return scrollUp();
        }     
		 // If click on up-arrow right
        else if((mouseX >= (upL_r - 5)) && (mouseX <= (upL_r + upW + 5)) && (mouseY >= (upT - 5)) && (mouseY <= (upT + upH + 5))){
                clickRight = true;
				clickUp = true;
                return scrollUp();
        }     
        // Else if click on down-arrow
        else if((mouseX >= (downL - 5)) && (mouseX <= (downL + downW + 5)) && (mouseY >= (downT - 5)) && (mouseY <= (downT + downH + 5))){
                clickDown = true;
                return scrollDown();
        }
		// Else if click on down-arrow right
        else if((mouseX >= (downL_r - 5)) && (mouseX <= (downL_r + downW + 5)) && (mouseY >= (downT - 5)) && (mouseY <= (downT + downH + 5))){
                clickRight = true;
				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();
                }
        }
		// Else if click on scrollbar right
        else if(mouseX >= dragL_r && (mouseX <= (dragL_r + dragW)) && mouseY >= dragT_r && (mouseY <= (dragT_r + dragH))){
                clickRight = true;
				clickDrag = true;
                return false;
        }
        else if(mouseX >= dragL_r && (mouseX <= (dragL_r + dragW)) && mouseY >= rulerT_r && (mouseY <= (rulerT_r + scrollH))){
                // If click above drag
                clickRight = true;
				if(mouseY < dragT_r){
                        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(clickRight){
        if(clickDrag && contentH > contentClipH){
                getMouse(e);
                dragT_r = (mouseY - startY_r);
                
                if(dragT_r < (rulerT_r))
                        dragT_r = rulerT_r;         
                if(dragT_r > (rulerT_r + scrollH - dragH))
                        dragT_r = (rulerT_r + scrollH - dragH);
                
                contentT_r = ((dragT_r - rulerT_r)*(1/scrollLength));
                contentT_r = eval('-' + contentT_r);

                moveTo();
                
                // So ie-pc doesn't select gifs
                if(ie4)
                        return false;
        }
	}else{
		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;
		clickRight = false;
		//alert("0");
        return true;
}

// Reads content layer top
function getT(){
	if(clickRight){
        if(ie4)
                contentT_r = document.all.content1.style.pixelTop;
        else if(nn4)
                contentT_r = document.contentClip.document.content1.top;
        else if(dom)
                contentT_r = parseInt(document.getElementById("content1").style.top);
	}else{
        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 (clickRight){
	    if(ie4){
                document.all.content1.style.top = contentT_r;
                document.all.ruler1.style.top = dragT_r;
                document.all.drag1.style.top = dragT_r;
        }
        else if(nn4){
                document.contentClip1.document.content.top = contentT_r;
                document.ruler1.top = dragT_r;
                document.drag1.top = dragT_r;
        }
        else if(dom){
                document.getElementById("content1").style.top = contentT_r + "px";
                document.getElementById("drag1").style.top = dragT_r + "px";
                document.getElementById("ruler1").style.top = dragT_r + "px";
        }
	} else {
	    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(){
	if(clickRight){
        getT();
        
        if(clickAbove){
                if(dragT_r <= (mouseY-(dragH/2)))
                        return up();
        }
        
        if(clickUp){
                if(contentT_r < 0){               
                        dragT_r = dragT_r - (speed*scrollLength);
                        
                        if(dragT_r < (rulerT_r))
                                dragT_r = rulerT_r;
                                
                        contentT_r = contentT_r + speed;
                        if(contentT_r > 0)
                                contentT = 0;
                        
                        moveTo();
                        timer = setTimeout("scrollUp()",50);
                }
        }
        return false;
	}else{
        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()",50);
                }
        }
        return false;
	}
}

// Scrolls down
function scrollDown(){
	if(clickRight){
        getT();
        
        if(clickBelow){
                if(dragT_r >= (mouseY-(dragH/2)))
                        return up();
        }

        if(clickDown){
                if(contentT_r > -(contentH - contentClipH)){                      
                        dragT_r = dragT_r + (speed*scrollLength);
                        if(dragT_r > (rulerT_r + scrollH - dragH))
                                dragT_r = (rulerT_r + scrollH - dragH);
                        
                        contentT_r = contentT_r - speed;
                        if(contentT_r < -(contentH - contentClipH))
                                contentT_r = -(contentH - contentClipH);
                        
                        moveTo();
                        timer = setTimeout("scrollDown()",50);
                }
        }
        return false;
	}else{
        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()",50);
                }
        }
        return false;
	}
}

// reloads page to position the layers again
function reloadPage(){
        location.reload();
}

// Preload
function eventLoader(){
		if(ie4 && !mac){
                // Up-arrow X and Y variables
				//alert("pcie");
                upL = document.all.up.style.pixelLeft + x;
				document.all.up.style.pixelLeft = upL;
				//right x
				upL_r = document.all.up1.style.pixelLeft + xr;
				document.all.up1.style.pixelLeft = upL_r;
                upT = document.all.up.style.pixelTop;           
                // Down-arrow X and Y variables
                downL = document.all.down.style.pixelLeft + x;
				document.all.down.style.pixelLeft = downL;
				//right x
				downL_r = document.all.down1.style.pixelLeft + xr;
				document.all.down1.style.pixelLeft = downL_r;
                downT = document.all.down.style.pixelTop;
                // Scrollbar X and Y variables
                dragL = document.all.drag.style.pixelLeft + x;
				document.all.drag.style.pixelLeft = dragL;
				// right x
				dragL_r = document.all.drag1.style.pixelLeft + xr;
				document.all.drag1.style.pixelLeft = dragL_r;
                dragT = document.all.drag.style.pixelTop;
				//right scroll
				dragT_r = document.all.drag1.style.pixelTop;
				//dragbg x variables
				//dragbgL = document.all.dragbg.style.pixelLeft + x;
				//document.all.dragbg.style.pixelLeft = dragbgL;
				//right x
				//dragbgL_r = document.all.dragbg1.style.pixelLeft + xr;
				//document.all.dragbg1.style.pixelLeft = dragbgL_r;
				//contentClip X variables
				contentL = document.all.contentClip.style.pixelLeft + x;
				document.all.contentClip.style.pixelLeft = contentL;      
				//right x
				contentL_r = document.all.contentClip1.style.pixelLeft + xr;
				document.all.contentClip1.style.pixelLeft = contentL_r;            
                // Ruler Y variable				
                rulerT = document.all.ruler.style.pixelTop;     
				rulerT_r = document.all.ruler1.style.pixelTop;         
                // Height of content layer and clip layer
                contentH = parseInt(document.all.content.scrollHeight);
                contentClipH = parseInt(document.all.contentClip.style.height);
				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.dragbg.style.visibility= 'visible';
				document.all.contentClip.style.visibility= 'visible';
				//right layer
				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.dragbg1.style.visibility= 'visible';
				document.all.contentClip1.style.visibility= 'visible';
        }
        else if(nn4){
                //alert("nn4")
				// Up-arrow X and Y variables
                upL = document.up.left + x;
				document.up.left = upL;
				//right x
				upL_r = document.up1.left + xr;
				document.up1.left = upL_r;
                upT = document.up.top;          
                // Down-arrow X and Y variables
                downL = document.down.left + x;
				document.down.left = downL;
				//right x
				downL_r = document.down1.left + xr;
				document.down1.left = downL_r;
                downT = document.down.top;              
                // Scrollbar X and Y variables
                dragL = document.drag.left + x;
				document.drag.left = dragL;
				//right x
				dragL_r = document.drag1.left + xr;
				document.drag1.left = dragL_r;
                dragT = document.drag.top;
				//right scroll
				dragT_r = document.drag1.top;
				//contentClip X variables
				contentL = document.contentClip.left + x;
				document.contentClip.left = contentL; 
				//right x
				contentL_r = document.contentClip1.left + xr;
				document.contentClip1.left = contentL_r;                
                // Ruler Y variable
                rulerT = document.ruler.top;
				rulerT_r = document.ruler1.top;
				// for mac nn4
				if(mac){
					//alert("macnn4")
					dragT = document.drag.top + 3;
					document.drag.top = dragT;
					//right scroll
					dragT_r = document.drag1.top + 3;
					document.drag1.top = dragT_r;
					rulerT = document.ruler.top + 3;
					document.ruler.top = rulerT;
					rulerT_r = document.ruler1.top + 3;
					document.ruler1.top = rulerT_r;
				}
				// dragbg X variables
                //dragbgL = document.dragbg.left + x;
				//document.dragbg.left = dragbgL;
				//right x
				//dragbgL_r = document.dragbg1.left + xr;
				//document.dragbg1.left = dragbgL_r;
                // Height of content layer and clip layer
                contentH = document.contentClip.document.content.clip.bottom;
                contentClipH = document.contentClip.clip.bottom;
				document.up.visibility= 'visible';
				document.down.visibility= 'visible';
				document.drag.visibility= 'visible';
				document.ruler.visibility= 'visible';
				//document.dragbg.visibility= 'visible';
				document.contentClip.visibility= 'visible';
				//right layer
				document.up1.visibility= 'visible';
				document.down1.visibility= 'visible';
				document.drag1.visibility= 'visible';
				document.ruler1.visibility= 'visible';
				//document.dragbg1.visibility= 'visible';
				document.contentClip1.visibility= 'visible';
        }
        else if(dom){	
				//alert("dommac")	
                // Up-arrow X and Y variables
                upL = parseInt(document.getElementById("up").style.left) + x;
				document.getElementById("up").style.left = upL;
				//right x
				upL_r = parseInt(document.getElementById("up1").style.left) + xr;
				document.getElementById("up1").style.left = upL_r;
                upT = parseInt(document.getElementById("up").style.top);
                // Down-arrow X and Y variables
                downL = parseInt(document.getElementById("down").style.left) + x;
				document.getElementById("down").style.left = downL;
				//right x
				downL_r = parseInt(document.getElementById("down1").style.left) + xr;
				document.getElementById("down1").style.left = downL_r;
                downT = parseInt(document.getElementById("down").style.top);
                // Scrollbar X and Y variables
                dragL = parseInt(document.getElementById("drag").style.left) + x;
				document.getElementById("drag").style.left = dragL;
				//right x
				dragL_r = parseInt(document.getElementById("drag1").style.left) + xr;
				document.getElementById("drag1").style.left = dragL_r;
                dragT = parseInt(document.getElementById("drag").style.top) - 3;
				document.getElementById("drag").style.top = dragT;
				//right scroll 
				dragT_r = parseInt(document.getElementById("drag1").style.top) - 3;
				document.getElementById("drag1").style.top = dragT_r;
				//contentClip X variables
				contentL = parseInt(document.getElementById("contentClip").style.left) + x;
				document.getElementById("contentClip").style.left = contentL;   
				//right x
				contentL_r = parseInt(document.getElementById("contentClip1").style.left) + xr;
				document.getElementById("contentClip1").style.left = contentL_r;  
                // Ruler Y variable
                rulerT = parseInt(document.getElementById("ruler").style.top) - 3;
				document.getElementById("ruler").style.top = rulerT;
				rulerT_r = parseInt(document.getElementById("ruler1").style.top) - 3;
				document.getElementById("ruler1").style.top = rulerT_r;
				// dragbg X variables
                //dragbgL = parseInt(document.getElementById("dragbg").style.left) + x;
				//document.getElementById("dragbg").style.left = dragL;
				//right x
				//dragbgL_r = parseInt(document.getElementById("dragbg1").style.left) + xr;
				//document.getElementById("dragbg1").style.left = dragL_r;
                // Height of content layer and clip layer
                contentH = parseInt(document.getElementById("content").offsetHeight);
                contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
                document.getElementById("content").style.top = 0 + "px";
				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("dragbg").style.visibility= 'visible';
				document.getElementById("contentClip").style.visibility= 'visible';
				//right layer
				document.getElementById("content1").style.top = 0 + "px";
				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("dragbg1").style.visibility= 'visible';
				document.getElementById("contentClip1").style.visibility= 'visible';
        }
        // Number of pixels scrollbar should move
        scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
        //alert(scrollLength);
		// 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;
}