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

// Edit here
var speed = 3; // Scroll speed

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

var clickLeft = false; // If click on up-arrow
var clickRight = false; // If click on down-arrow
var clickUp	= false;
var clickDown = false;

var timer = setTimeout("",500); // Repeat variable

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 contentL = 0; // Content layer Y;
var contentW; // Content height
var contentClipW; // Content clip height
var contentT = 0; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height

// content info
var contentWidth; // Content width
var contentClipWidth; // Content clip wdith
var contentHeight; // Content width
var contentClipHeight; // Content clip wdith

// scroll bar
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y




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();
                }
        }
        // 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 startUp () {
	clickUp = true;
	return scrollUp();
}

function startDown () {
	clickDown = true;
	return scrollDown();
}

function startRight () {
	clickRight = true;
	return scrollRight();
}

function startLeft () {
	clickLeft = true;
	return scrollLeft();
}

function up(){
        clearTimeout(timer);
        // Resetting variables
        clickRight = false;
        clickLeft = false;
        clickUp = false;
        clickDown = false;
        return true;
}

// Reads content layer top
function getT(){
    contentL = getElmById("innerContent").style.left;
    contentT = getElmById("innerContent").style.top;
}

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

// Moves the layer
function moveTo(){

	getElmById("innerContent").style.left = contentL;
	getElmById("innerContent").style.top = contentT;

}

function scrollUp(){
//	getT();
	if(clickUp){
		if(contentT < 0) {                      
			contentT = contentT + speed;
			if (contentT > 0) contentT = 0;
			moveTo();
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

function scrollDown(){
//	getT();
	if(clickDown){
		if(contentT > -(contentH - contentClipH)) { 
			contentT = contentT - speed;
			if (contentT < -(contentH - contentClipH)) contentT = -(contentH - contentClipH);
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

function scrollLeft(){
//	getT();
	if(clickLeft){
		if(contentL < 0) {                      
			contentL = contentL + speed;
			if (contentL > 0) contentL = 0;
			moveTo();
			timer = setTimeout("scrollLeft()",25);
		}
	}
	return false;
}

function scrollRight(){
//	getT();
	if(clickRight){
		if(contentL > -(contentW - contentClipW)) { 
			contentL = contentL - speed;
			if (contentL < -(contentW - contentClipW)) contentL = -(contentW - contentClipW);
			moveTo();
			timer = setTimeout("scrollRight()",25);
		}
	}
	return false;
}

function eventLoader (width) {
	getT();	
//	contentL = 0;

	contentW = getElmById("innerContent").offsetWidth;
	contentH = getElmById("innerContent").offsetHeight;
//	contentW = width;
	contentClipW = getElmById("outerContent").offsetWidth;
//	contentClipH = getElmById("outerContent").offsetHeight;
	contentClipH = 86;

//	showHideLayers('','innerContent','hidden');

//	top.alert(contentH +":"+ contentClipH);
//	top.alert(contentH +":"+ contentClipH);

	if ( (contentH - contentClipH) > 0 ){
//		showHideLayers('','subScroll','visible');
	}
	
	// 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;

}
