
// Made by geeeet@ghtml.com - Keep these two lines and you're free to use this code
// Upgraded by email@raphaelhofer.com-dynamic height scrollfield-scroll isnt there when no scrolling needed-safari proof reloading cause doesnt get innerwidth half the time-scrolls in ie+ns4 when mark txt-blocks txtmarking in dom cause it turns crap in ns7pc
// order of script routines- ie then dom then ns4
// tested by raffi pc ie6-ns6-ns7-ns4 mac ie5.2-ns7.2-safari 1.2 -


// fixe hoehe
var scrollhoehe = 306;
var bildschirmhoehe = 306;
var bildschirmbreite = 0;
//preload img scroll
b1 = new Image();
b1.src = "i/GolfScroll.gif";
b2 = new Image();
b2.src = "i/GolfScrollL.gif";
b3 = new Image();
b3.src = "i/GolfScrollR.gif";

function messen(){

if (document.all) {
bildschirmhoehe = document.body.offsetHeight;
bildschirmbreite = document.body.offsetWidth;
scrollH=scrollhoehe;
if (document.all.content.scrollHeight > scrollH+18) {
	document.all.drag.style.display="block"; 
	document.all.ruler.style.display="block";
	//-for reset fontsizeswitcher-
	document.all.drag.style.top=1; 
	document.all.ruler.style.top=1;
	document.all.drag.style.left=497; 
	document.all.ruler.style.left=497;
	document.all.content.style.top=0;
	document.images['ski'].src = 'i/GolfScrollR.gif';
	
	//document.all.contentClip.style.overflow ="hidden";
	
	document.all.contentClip.style.backgroundImage="url(i/GolfScrollbg.gif)";
	} else {
	document.all.drag.style.display="none"; 
	document.all.ruler.style.display="none";
	//-for reset fontsizeswitcher-
	document.all.drag.style.top=1; 
	document.all.ruler.style.top=1;
	document.all.drag.style.left=497; 
	document.all.ruler.style.left=497;
	document.all.content.style.top=0;
	document.images['ski'].src = 'i/GolfScrollR.gif';
	
	//document.all.contentClip.style.overflow ="hidden";
	
	document.all.contentClip.style.backgroundImage="none";
	}		
		
//document.all.up.style.top=180;
//document.all.contentClip.style.left=228;
//if (document.all.content.scrollHeight > document.all.contentClip.style.pixelHeight) {        if (navigator.platform.substr(0,3)=='Mac') {document.all.drag.style.top=181;document.all.ruler.style.top=181;}        else {document.all.drag.style.top=181;document.all.ruler.style.top=181;}document.all.down.style.top=bildschirmhoehe-1;
eventLoader();

}

else if (document.getElementById) {
bildschirmhoehe = window.innerHeight;
if (bildschirmhoehe<1){window.setTimeout('messen()',50);} else {bildschirmbreite = window.innerWidth;
scrollH=scrollhoehe;
if (parseInt(document.getElementById('content').offsetHeight) > scrollH+18) {
	document.getElementById('drag').style.display="block";
    document.getElementById('ruler').style.display="block";
	//-for reset fontsizeswitcher-
	document.getElementById('drag').style.top = "1px";
    document.getElementById('ruler').style.top = "1px";
	document.getElementById('drag').style.left = "497px";
    document.getElementById('ruler').style.left = "497px";
	document.getElementById('content').style.top = "0px";
	document.images['ski'].src = 'i/GolfscrollR.gif';
	//document.getElementById('contentClip').style.overflow ="hidden";
	
    document.getElementById('contentClip').style.backgroundImage="url(i/GolfScrollbg.gif)";
    } else {
	document.getElementById('drag').style.display="none";
    document.getElementById('ruler').style.display="none";
	//-for reset fontsizeswitcher-
	document.getElementById('drag').style.top = "1px";
    document.getElementById('ruler').style.top = "1px";
	document.getElementById('drag').style.left = "497px";
    document.getElementById('ruler').style.left = "497px";
	document.getElementById('content').style.top = "0px";
	document.images['ski'].src = 'i/GolfScrollR.gif';
	//document.getElementById('contentClip').style.overflow ="hidden";
	
    document.getElementById('contentClip').style.backgroundImage="none";	
    }	
eventLoader();
}
//scrollH=scrollhoehe;
//document.getElementById('up').style.top=180;document.getElementById('contentClip').style.left=228;if (parseInt(document.getElementById('content').offsetHeight) > (bildschirmhoehe-1)) {document.getElementById('drag').style.top=181;document.getElementById('ruler').style.top=181;document.getElementById('down').style.top=bildschirmhoehe-1;
//eventLoader();
}

else if (document.layers) {
bildschirmhoehe = window.innerHeight;
bildschirmbreite = window.innerWidth;
scrollH=scrollhoehe;

//document.layers['up'].top=180;document.layers['contentClip'].left=228;if (document.contentClip.document.content.clip.bottom > document.contentClip.clip.bottom) {document.layers['drag'].top=181;document.layers['ruler'].top=181;document.layers['down'].top=bildschirmhoehe-1;
eventLoader();}

}

var upH = 1; // Height up-arrow
var upW = 14; // Width up-arrow
var downH = 1; // Height down-arrow
var downW = 14; // Width down-arrow
var dragH = 44; // Height scroll
var dragW = 22; // Width scroll
var scrollH = 200; // Height scrollbar
var speed = 4;

// Browser
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY;
var mouseX;
var clickUp = false;
var clickDown = false;
var clickDrag = false;
var clickDragtxt = false;
var clickAbove = false;
var clickBelow = false;

var timer = setTimeout("",500);
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

// 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);
        // 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();
                }
        }
        // Else if click on txt
        else if( mouseX > (dragL + dragW) && (mouseY >= 185) && mouseY <= (bildschirmhoehe)){
                clickDragtxt = true;
                if (dom){return false;}
        }
        // If no scrolling is to take place
        else{
                return true;
        }
}

//Drag
function move(e){ 
        if(clickDrag && contentH > contentClipH){
                if (document.getElementById && navigator.userAgent.match(/Netscape/)) {
                        if (mouseY<bildschirmhoehe-15 && mouseX > 1 && mouseX < 450){getMouse(e);}
                        }
                else {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;
        }

        // Else if click on txt
        else if (ie4 || nn4){getMouse(e);

        if(clickDragtxt && contentH > contentClipH ){
                // 13 eval contentClipT -15 eval visible height of scrollarrowdown
                if (mouseY <= 190){clickUp = true;return scrollUp();}
                if (mouseY >= (bildschirmhoehe-15)){clickDown = true;return scrollDown();}
                }
                // ie doesn't select txt: return false;
                }
}

function up(){
        clearTimeout(timer);
        clickUp = false;
        clickDown = false;
        clickDrag = false;
        clickDragtxt = false;
        clickAbove = false;
        clickBelow = 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
function getMouse(e){
        if(ie4){
                mouseY = event.clientY + document.body.scrollTop  - ((bildschirmhoehe-569)/2) - 180; //alert(mouseY);
                mouseX = event.clientX + document.body.scrollLeft  - ((bildschirmbreite-800)/2) - 228; //alert(mouseX);
        }
        else if(nn4){
                mouseY = e.pageY  - ((bildschirmhoehe-569)/2) - 180;
                mouseX = e.pageX  - ((bildschirmbreite-800)/2) - 228;
        }
                else if(dom){
                mouseY = e.clientY  - ((bildschirmhoehe-569)/2) - 180; //alert(mouseY);
                mouseX = e.clientX  - ((bildschirmbreite-800)/2) - 228;  //alert(mouseX);
        }
}

// Moves the layer
var dragLold = dragL;
var dragTold = dragT;
function moveTo(){
		
        if(ie4){
				//img
				var dragLnew = dragL + 5*Math.sin(dragT*0.036);
				//down
				if (dragTold < dragT) {
				  if (dragLnew - dragLold < 0) {
					if (5*Math.sin(dragT*0.036) < -4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollL.gif';}				
					}
				  else if (dragLnew - dragLold > 0) {
					if (5*Math.sin(dragT*0.036) > 4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollR.gif';}
					}
				}
				//up
				else {
				if (dragLnew - dragLold > 0) {
					if (5*Math.sin(dragT*0.036) > 4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollL.gif';}					
					}
				else if (dragLnew - dragLold < 0) {
					if (5*Math.sin(dragT*0.036) < -4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollR.gif';}								
					}
				}			
				//hoehe
                document.all.content.style.top = contentT;
                document.all.ruler.style.top = dragT;
                document.all.drag.style.top = dragT;
				//kurve
                document.all.ruler.style.left = dragL + Math.round(5*Math.sin(dragT*0.036));
                document.all.drag.style.left = dragL + Math.round(5*Math.sin(dragT*0.036));
        }
        else if(nn4){
			
				//hoehe
                document.contentClip.document.content.top = contentT;
                document.ruler.top = dragT;
                document.drag.top = dragT;
				//kurve
                document.ruler.left = dragL + Math.round(5*Math.sin(dragT*0.036));
                document.drag.left = dragL + Math.round(5*Math.sin(dragT*0.036));				
        }
        else if(dom){
				//img
				var dragLnew = dragL + 5*Math.sin(dragT*0.036);
				//down
				if (dragTold < dragT) {
				  if (dragLnew - dragLold < 0) {
					if (5*Math.sin(dragT*0.036) < -4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollL.gif';}				
					}
				  else if (dragLnew - dragLold > 0) {
					if (5*Math.sin(dragT*0.036) > 4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollR.gif';}
					}
				}
				//up
				else {
				if (dragLnew - dragLold > 0) {
					if (5*Math.sin(dragT*0.036) > 4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollL.gif';}					
					}
				else if (dragLnew - dragLold < 0) {
					if (5*Math.sin(dragT*0.036) < -4) {document.images['ski'].src = 'i/GolfScroll.gif';}
					else {document.images['ski'].src = 'i/GolfScrollR.gif';}								
					}
				}
				//hoehe
                document.getElementById("content").style.top = contentT + "px";
                document.getElementById("drag").style.top = dragT + "px";
                document.getElementById("ruler").style.top = dragT + "px";
				//kurve
				document.getElementById("drag").style.left = dragL + Math.round(5*Math.sin(dragT*0.036)) + "px";
                document.getElementById("ruler").style.left = dragL + Math.round(5*Math.sin(dragT*0.036)) + "px";
        }
		//memo img
		dragLold = dragL + 5*Math.sin(dragT*0.036);
		//up or down memo
		dragTold = dragT;
}

// 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(){ 
        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;
}

// reload
function reloadPage(){
        location.reload();
}

// Preload
function eventLoader(){
        if(ie4){
                upL = document.all.up.style.pixelLeft;
                upT = document.all.up.style.pixelTop;
                downL = document.all.down.style.pixelLeft;
                downT = document.all.down.style.pixelTop;
                dragL = document.all.drag.style.pixelLeft;
                dragT = document.all.drag.style.pixelTop;
                rulerT = document.all.ruler.style.pixelTop;
                contentH = parseInt(document.all.content.scrollHeight);
                //contentClipH = parseInt(document.all.contentClip.style.height);
				contentClipH = 306;
        }
        else if(nn4){
                upL = document.up.left;
                upT = document.up.top;
                downL = document.down.left;
                downT = document.down.top;
                dragL = document.drag.left;
                dragT = document.drag.top;
                rulerT = document.ruler.top;
                contentH = document.contentClip.document.content.clip.bottom;
                contentClipH = document.contentClip.clip.bottom;
        }
        else if(dom){
                upL = parseInt(document.getElementById("up").style.left);
                upT = parseInt(document.getElementById("up").style.top);
                downL = parseInt(document.getElementById("down").style.left);
                downT = parseInt(document.getElementById("down").style.top);
                dragL = parseInt(document.getElementById("drag").style.left);
                dragT = parseInt(document.getElementById("drag").style.top);
                rulerT = parseInt(document.getElementById("ruler").style.top);
                contentH = parseInt(document.getElementById("content").offsetHeight); 
                contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
                document.getElementById("content").style.top = 0 + "px";

        }
        // Number of pixels scrollbar should move
        scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
        // Init event capt
        if(nn4){document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);}

        document.onmousedown = down;
        document.onmousemove = move;
        document.onmouseup = up;
}

