
// scroller working draft by http://www.industrious.com, based on code by geeeet@ghtml.com

var upH = 11; // Height of up-arrow
var upW = 11; // Width of up-arrow
var downH = 11; // Height of down-arrow
var downW = 11; // Width of down-arrow
var dragH = 11; // Height of scrollbar
var dragW = 11; // Width of scrollbar
var scrollH = 74; // Height of scrollbar
var speed = 4; // 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 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 viewH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span
var winWidth;
var divWidth = 745;
var divTopOffset = 30;
var divSideOffset;


// 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();
		}
	}
	// If no scrolling is to take place
	else{
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag && contentH > viewH){
		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;
	return true;
}

// Reads content layer top
function getT(){
	if(ie4)
		contentT = document.all.scrollcontent.style.pixelTop;
	else if(nn4)
		contentT = document.scrollview.document.content.top;
	else if(dom)
		contentT = parseInt(document.getElementById("scrollcontent").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(nn4){
		document.all.scrollcontent.style.top = contentT;
		document.all.scrollruler.style.top = dragT;
		document.all.scrolldrag.style.top = dragT;
	}
	else if(nn4){
		document.scrollview.document.content.top = contentT;
		document.scrollruler.top = dragT;
		document.scrolldrag.top = dragT;
	}
	else if(dom || ie4){
		document.getElementById("scrollcontent").style.top = contentT + "px";
		document.getElementById("scrolldrag").style.top = dragT + "px";
		document.getElementById("scrollruler").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(){
	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();
	}

	if(clickDown){
		if(contentT > -(contentH - viewH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			contentT = contentT - speed;
			if(contentT < -(contentH - viewH))
				contentT = -(contentH - viewH);
			
			moveTo();
			timer = setTimeout("scrollDown()",25);
		}
	}
	return false;
}

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



function showscroll(){
var cw, iw, ow;
//clientWidth
if (document.documentElement&&document.documentElement.clientWidth)
cw=document.documentElement.clientWidth;
if (document.body&&document.body.clientWidth)
cw=document.body.clientWidth;
// firefox, mozilla, netscape
if (window.innerWidth){
iw=window.innerWidth;
if (iw!=cw){
alert('Vertical Scrollbar Does Exist');
}else{
alert('Vertical Scrollbar Does NOT Exist');
}
}else{
// IE
// offsetWidth
if (document.documentElement&&document.documentElement.offsetWidth)
ow=document.documentElement.offsetWidth;
if (document.body&&document.body.offsetWidth)
ow=document.body.offsetWidth;
if (ow!=cw){
alert('Vertical Scrollbar Does Exist');
}else{
alert('Vertical Scrollbar Does NOT Exist');
}
}
}






// Preload
function startScroll(){



//alert(document.body.clientWidth);
winWidth = (!ie4) ? window.innerWidth : document.body.clientWidth;
divSideOffset = Math.floor((winWidth-divWidth)/2);

/*

var cw, iw, ow;
//clientWidth
if (document.documentElement&&document.documentElement.clientWidth)
cw=document.documentElement.clientWidth;
if (document.body&&document.body.clientWidth)
cw=document.body.clientWidth;
// firefox, mozilla, netscape
if (window.innerWidth){
iw=window.innerWidth;
if (iw!=cw){
divSideOffset-=7;
//alert('Vertical Scrollbar Does Exist');
}else{
//alert('Vertical Scrollbar Does NOT Exist');
}
}else{
// IE
// offsetWidth
if (document.documentElement&&document.documentElement.offsetWidth)
ow=document.documentElement.offsetWidth;
if (document.body&&document.body.offsetWidth)
ow=document.body.offsetWidth;
if (ow!=cw){
//divSideOffset-=8;
//alert('Vertical Scrollbar Does Exist');
}else{
//alert('Vertical Scrollbar Does NOT Exist');
}
}*/




document.getElementById("scrollcontent").style.visibility = "hidden";
document.getElementById("scrollview").style.height = 100 + "px";
//document.getElementById("scrollview").style.overflow = "hidden";
document.getElementById("scrollview").style.top = (295 + divTopOffset) + "px";
document.getElementById("scrollview").style.left = (435 + divSideOffset) + "px";
document.getElementById("scrollview").style.visibility = "hidden";
document.getElementById("scrollbase").style.top = (290 + divTopOffset) + "px";
document.getElementById("scrollbase").style.left = (418 + divSideOffset) + "px";
document.getElementById("scrollbase").style.visibility = "hidden";
document.getElementById("scrollup").style.top = (371 + divTopOffset) + "px";
document.getElementById("scrollup").style.left = (677 + divSideOffset) + "px";
document.getElementById("scrollup").style.visibility = "hidden";
document.getElementById("scrolldown").style.top = (382 + divTopOffset) + "px";
document.getElementById("scrolldown").style.left = (677 + divSideOffset) + "px";
document.getElementById("scrolldown").style.visibility = "hidden";
document.getElementById("scrolldrag").style.top = (297 + divTopOffset) + "px";
document.getElementById("scrolldrag").style.left = (677 + divSideOffset) + "px";
document.getElementById("scrolldrag").style.visibility = "hidden";
document.getElementById("scrollruler").style.top = (297 + divTopOffset) + "px";
document.getElementById("scrollruler").style.left = (677 + divSideOffset) + "px";



	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.scrollup.style.pixelLeft;
		upT = document.all.scrollup.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.scrolldown.style.pixelLeft;
		downT = document.all.scrolldown.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.scrolldrag.style.pixelLeft;
		dragT = document.all.scrolldrag.style.pixelTop;		
		// Ruler Y variable
		rulerT = document.all.scrollruler.style.pixelTop;		
		// Height of content layer and clip layer
		contentH = parseInt(document.all.scrollcontent.scrollHeight);
		viewH = parseInt(document.all.scrollview.style.height);
	}
	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;
		// Height of content layer and clip layer
		contentH = document.view.document.content.clip.bottom;
		viewH = document.view.clip.bottom;
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("scrollup").style.left);
		upT = parseInt(document.getElementById("scrollup").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("scrolldown").style.left);
		downT = parseInt(document.getElementById("scrolldown").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("scrolldrag").style.left);
		dragT = parseInt(document.getElementById("scrolldrag").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("scrollruler").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("scrollcontent").offsetHeight);
		viewH = parseInt(document.getElementById("scrollview").offsetHeight);
		document.getElementById("scrollcontent").style.top = 0 + "px";
		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-viewH));
	// 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;
	

}

