// Made by geeeet@ghtml.com
// Keep these two lines and you're free to use this code

var upH = 7; // Height of up-arrow
var upW = 8; // Width of up-arrow
var downH = 7; // Height of down-arrow
var downW = 8; // Width of down-arrow
var dragH = 7; // Height of scrollbar
var dragW = 8; // Width of scrollbar
var speed = 8; // Scroll speed

var LscrollH = 582; // Height of scrollbar

// 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 Ltimer = setTimeout("",500); // Repeat variable
var LclickUp = false; // If click on up-arrow
var LclickDown = false; // If click on down-arrow
var LclickDrag = false; // If click on scrollbar
var LclickAbove = false; // If click above scrollbar
var LclickBelow = false; // If click below scrollbar
var LtopL; // Absolute X
var LtolT; // Absolute Y
var LupL; // Up-arrow X
var LupT; // Up-arrow Y
var LdownL; // Down-arrow X
var LdownT; // Down-arrow Y
var LdragL; // Scrollbar X
var LdragT; // Scrollbar Y
var LrulerL; // Ruler X
var LrulerT; // Ruler Y
var LcontentT; // Content layer Y;
var LcontentH; // Content height
var LcontentClipH; // Content clip height
var LscrollLength; // Number of pixels scrollbar should move - scroll step
var LstartY; // Keeps track of offset between mouse and span

window.onresize = redo;

function redo() {
  window.location.reload();
}

// Mousedown
function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	getMouse(e);

    // levo okno
	LstartY = (mouseY - LdragT);
	if(mouseX >= LupL && (mouseX <= (LupL + upW)) && mouseY >= LupT && (mouseY <= (LupT + upH))) { // If click on up-arrow
		LclickUp = true;
		return LscrollUp();
	} else if(mouseX >= LdownL && (mouseX <= (LdownL + downW)) && mouseY >= LdownT && (mouseY <= (LdownT + downH))) { // Else if click on down-arrow
		LclickDown = true;
		return LscrollDown();
	} else if(mouseX >= LdragL && (mouseX <= (LdragL + dragW)) && mouseY >= LdragT && (mouseY <= (LdragT + dragH))) { // Else if click on scrollbar
		LclickDrag = true;
		return false;
	} else if(mouseX >= LdragL && (mouseX <= (LdragL + dragW)) && mouseY >= LrulerT && (mouseY <= (LrulerT + LscrollH))) {
		// If click above drag
		if(mouseY < LdragT){
			LclickAbove = true;
			LclickUp = true;
			return LscrollUp();
		} else { // Else click below drag
			LclickBelow = true;
			LclickDown = true;
			return LscrollDown();
		}
	}
	return true;
}

//////////////////
function move(e) {
//////////////////
// Drag function

    //levo okno
	if(LclickDrag && LcontentH > LcontentClipH){
		getMouse(e);
		LdragT = (mouseY - LstartY);
		if (LdragT < (LrulerT)) LdragT = LrulerT;
		if (LdragT > (LrulerT + LscrollH - dragH))	LdragT = (LrulerT + LscrollH - dragH);
		LcontentT = ((LdragT - LrulerT)*(1/LscrollLength));
		LcontentT = eval('-' + LcontentT);
		LmoveTo();
		if (ie4) return false; // So ie-pc doesn't select gifs
	}
} //move


////////////////
function Lup() {
////////////////
	clearTimeout(Ltimer);
	// Resetting variables
	LclickUp = false;
	LclickDown = false;
	LclickDrag = false;
	LclickAbove = false;
	LclickBelow = false;
	return true;
} //Lup


//////////////////
function LgetT() {
//////////////////
// Reads content layer top
	if(ie4) LcontentT = document.all.Lcontent.style.pixelTop;
	else if(nn4) LcontentT = document.contentClip.document.Lcontent.top;
	else if(dom) LcontentT = parseInt(document.getElementById("Lcontent").style.top);
} //LgetT

//////////////////////
function getMouse(e) {
//////////////////////
// Reads mouse X and Y coordinates
	if(ie4) {
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	} else if(nn4 || dom) {
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
} //getMouse


////////////////////
function LmoveTo() {
////////////////////
// Moves the layer
    LdragRelT = LdragT - LtopT;
	if(ie4){
		document.all.Lcontent.style.top = LcontentT;
		document.all.Ldrag.style.top = LdragRelT;
	} else if(nn4){
		document.LcontentClip.document.content.top = LcontentT;
		document.Lruler.top = LdragRelT;
	} else if(dom){
		document.getElementById("Lcontent").style.top = LcontentT + "px";
		document.getElementById("Ldrag").style.top = LdragRelT + "px";
	}
} //LmoveTo


//////////////////////
function LscrollUp() {
//////////////////////
// Scrolls up
	LgetT();
	if(LclickAbove) {
		if(LdragT <= (mouseY-(dragH/2))) return Lup();
	}
	if(LclickUp) {
		if(LcontentT < 0) {
			LdragT = LdragT - (speed*LscrollLength);
			if(LdragT < (LrulerT)) LdragT = LrulerT;
			LcontentT = LcontentT + speed;
			if(LcontentT > 0) LcontentT = 0;
			LmoveTo();
			Ltimer = setTimeout("LscrollUp()",25);
		}
	}
	return false;
} //LscrollUp


///////////////////////
function LscrollDown() {
///////////////////////
// Scrolls down
	LgetT();
	if(LclickBelow) {
		if(LdragT >= (mouseY-(dragH/2))) return Lup();
	}
	if(LclickDown) {
		if (LcontentT > -(LcontentH - LcontentClipH)) {
			LdragT = LdragT + (speed*LscrollLength);
			if(LdragT > (LrulerT + LscrollH - dragH)) LdragT = (LrulerT + LscrollH - dragH);
			LcontentT = LcontentT - speed;
			if(LcontentT < -(LcontentH - LcontentClipH)) LcontentT = -(LcontentH - LcontentClipH);
			LmoveTo();
			Ltimer = setTimeout("LscrollDown()",25);
		}
	}
	return false;
} //LscrollDown

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

///////////////////////
function getAbsX(elt) {
///////////////////////
// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
   x = getAbsPos(elt,"Left");
   return (x);
} //getAbsX
///////////////////////
function getAbsY(elt) {
///////////////////////
   y = getAbsPos(elt,"Top");
   return (y);
} //getAbsY
///////////////////////////////
function getAbsPos(elt,which) {
///////////////////////////////
  iPos = 0;
  while (elt != null) {
    iPos += elt["offset" + which];
    elt = elt.offsetParent;
  }
  return iPos;
} //getAbsPos

////////////////////////
function eventLoader() {
////////////////////////
// Preload

    // levo okno
	if(ie4){
        LtopL = getAbsX(document.all.Lbase);
        LtopT = getAbsY(document.all.Lbase);
		// Up-arrow X and Y variables
		LupL = LtopL + document.all.Lup.style.pixelLeft;
		LupT = LtopT + document.all.Lup.style.pixelTop;
		// Down-arrow X and Y variables
		LdownL = LtopL + document.all.Ldown.style.pixelLeft;
		LdownT = LtopT + document.all.Ldown.style.pixelTop;

		// Scrollbar X and Y variables
		LdragL = LtopL + document.all.Ldrag.style.pixelLeft;
		LdragT = LtopT + document.all.Ldrag.style.pixelTop;
		// Ruler Y variable
		LrulerT = LtopT + document.all.Lruler.style.pixelTop;
		// Height of content layer and clip layer
		LcontentH = parseInt(document.all.Lcontent.scrollHeight);
		LcontentClipH = parseInt(document.all.LcontentClip.style.height);
		
        if (LcontentH>LcontentClipH) { // ruler prikazemo samo ce vsebina predolga
           document.all.Lup.style.visibility='';
           document.all.Ldown.style.visibility='';
           document.all.Ldrag.style.visibility='';
           document.all.Lruler.style.visibility='';
           document.all.LscrollBG.style.visibility='';
        }
	} else if(nn4) {
        LtopL = getAbsX(document.Lbase);
        LtopT = getAbsY(document.Lbase);
		// Up-arrow X and Y variables
		LupL = LtopL + document.Lup.left;
		LupT = LtopT + document.Lup.top;
		// Down-arrow X and Y variables
		LdownL = LtopL + document.Ldown.left;
		LdownT = LtopT + document.Ldown.top;
		// Scrollbar X and Y variables
		LdragL = LtopL + document.Ldrag.left;
		LdragT = LtopT + document.Ldrag.top;
		// Ruler Y variable
		LrulerT = LtopT + document.Lruler.top;
		// Height of content layer and clip layer
		LcontentH = document.LcontentClip.document.content.clip.bottom;
		LcontentClipH = document.LcontentClip.clip.bottom;
        if (LcontentH>LcontentClipH) { // ruler prikazemo samo ce vsebina predolga
           document.Lup.style.visibility='';
           document.Ldown.style.visibility='';
           document.Ldrag.style.visibility='';
           document.Lruler.style.visibility='';
           document.LscrollBG.style.visibility='';
        }
	} else if(dom) {
        oBase = document.getElementById("Lbase");
        LtopL = getAbsX(oBase);
        LtopT = getAbsY(oBase);
		// Up-arrow X and Y variables
		LupL = LtopL + parseInt(document.getElementById("Lup").style.left);
		LupT = LtopT + parseInt(document.getElementById("Lup").style.top);
		// Down-arrow X and Y variables
		LdownL = LtopL + parseInt(document.getElementById("Ldown").style.left);
		LdownT = LtopT + parseInt(document.getElementById("Ldown").style.top);
		// Scrollbar X and Y variables
		LdragL = LtopL + parseInt(document.getElementById("Ldrag").style.left);
		LdragT = LtopT + parseInt(document.getElementById("Ldrag").style.top);
		// Ruler Y variable
		LrulerT = LtopT + parseInt(document.getElementById("Lruler").style.top);
        LscrollH = LscrollH + 4;

		// Height of content layer and clip layer
		LcontentH = parseInt(document.getElementById("Lcontent").offsetHeight);
		LcontentClipH = parseInt(document.getElementById("LcontentClip").offsetHeight);
		document.getElementById("Lcontent").style.top = 0 + "px";
        if (LcontentH>LcontentClipH) { // ruler prikazemo samo ce vsebina predolga
           document.getElementById("Lup").style.visibility='';
           document.getElementById("Ldown").style.visibility='';
           document.getElementById("Ldrag").style.visibility='';
           document.getElementById("Lruler").style.visibility='';
           document.getElementById("LscrollBG").style.height = (parseInt(document.getElementById("LscrollBG").style.height) + 4) + "px";
           document.getElementById("LscrollBG").style.top = (parseInt(document.getElementById("LscrollBG").style.top) - 4) + "px";
           //alert(document.getElementById("LscrollBG").style.height);
           document.getElementById("LscrollBG").style.visibility='';
        }
    }
	// Number of pixels scrollbar should move - scroll step
	LscrollLength = ((LscrollH-dragH)/(LcontentH-LcontentClipH));

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