/* =======================================================
* ypSimpleScroll
* 3/11/2001
* 
* http:
* ======================================================= */

ypSimpleScroll.prototype.scrollNorth = function() { this.startScroll(90) }
ypSimpleScroll.prototype.scrollSouth = function() { this.startScroll(270) }
ypSimpleScroll.prototype.scrollWest = function() { this.startScroll(180) }
ypSimpleScroll.prototype.scrollEast = function() { this.startScroll(0) }
ypSimpleScroll.prototype.startScroll = function(deg, speed) {
if (this.loaded)
{
if (this.aniTimer) window.clearTimeout(this.aniTimer)
this.overrideScrollAngle(deg)
this.speed = speed ? speed : this.origSpeed
this.lastTime = (new Date()).getTime() - this.y.minRes
this.aniTimer = window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
}
}
ypSimpleScroll.prototype.endScroll = function() {
if (this.loaded)
{
window.clearTimeout(this.aniTimer)
this.aniTimer = 0;
this.speed = this.origSpeed
}
}
ypSimpleScroll.prototype.overrideScrollAngle = function(deg) {
if (this.loaded)
{
deg = deg % 360
if (deg % 90 == 0) {
var cos = deg == 0 ? 1 : deg == 180 ? -1 : 0
var sin = deg == 90 ? -1 : deg == 270 ? 1 : 0
} else {
var angle = deg * Math.PI / 180
var cos = Math.cos(angle)
var sin = Math.sin(angle)
sin = -sin
}
this.fx = cos / (Math.abs(cos) + Math.abs(sin))
this.fy = sin / (Math.abs(cos) + Math.abs(sin))
this.stopH = deg == 90 || deg == 270 ? this.scrollLeft : deg < 90 || deg > 270 ? this.scrollW : 0
this.stopV = deg == 0 || deg == 180 ? this.scrollTop : deg < 180 ? 0 : this.scrollH
}
}
ypSimpleScroll.prototype.overrideScrollSpeed = function(speed) {
if (this.loaded) this.speed = speed
}
ypSimpleScroll.prototype.scrollTo = function(stopH, stopV, aniLen) {
if (this.loaded)
{
if (stopH != this.scrollLeft || stopV != this.scrollTop) {
if (this.aniTimer) window.clearTimeout(this.aniTimer)
this.lastTime = (new Date()).getTime()
var dx = Math.abs(stopH - this.scrollLeft)
var dy = Math.abs(stopV - this.scrollTop)
var d = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2))
this.fx = (stopH - this.scrollLeft) / (dx + dy)
this.fy = (stopV - this.scrollTop) / (dx + dy)
this.stopH = stopH
this.stopV = stopV
this.speed = d / aniLen * 1000
window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
}
}
}
ypSimpleScroll.prototype.jumpTo = function(nx, ny) { 
if (this.loaded)
{
nx = Math.min(Math.max(nx, 0), this.scrollW)
ny = Math.min(Math.max(ny, 0), this.scrollH)
this.scrollLeft = nx
this.scrollTop = ny
if (this.y.ns4)this.content.moveTo(-nx, -ny)
else {
this.content.style.left = -nx
this.content.style.top = -ny
}
}
}
ypSimpleScroll.minRes = 10
ypSimpleScroll.ie = document.all ? 1 : 0
ypSimpleScroll.ns4 = document.layers ? 1 : 0
ypSimpleScroll.dom = document.getElementById ? 1 : 0
ypSimpleScroll.mac = navigator.platform == "MacPPC"
ypSimpleScroll.mo5 = document.getElementById && !document.all ? 1 : 0
ypSimpleScroll.prototype.scroll = function() {
this.aniTimer = window.setTimeout(this.gRef + ".scroll()", this.y.minRes)
var nt = (new Date()).getTime()
var d = Math.round((nt - this.lastTime) / 1000 * this.speed)
var nx = d * this.fx + this.scrollLeft
var ny = d * this.fy + this.scrollTop
var xOut = (nx >= this.scrollLeft && nx >= this.stopH) || (nx <= this.scrollLeft && nx <= this.stopH)
var yOut = (ny >= this.scrollTop && ny >= this.stopV) || (ny <= this.scrollTop && ny <= this.stopV)
if (nt - this.lastTime != 0 &&
((this.fx == 0 && this.fy == 0) ||
(this.fy == 0 && xOut) ||
(this.fx == 0 && yOut) ||
(this.fx != 0 && this.fy != 0 && xOut && yOut)))
{
this.jumpTo(this.stopH, this.stopV)
this.endScroll()
}
else {
this.jumpTo(nx, ny)
this.lastTime = nt
}
}
function ypSimpleScroll(id, left, top, width, height, speed, contentWidth, initLeft, initTop)
{
var y = this.y = ypSimpleScroll
if (!initLeft) initLeft = 0
if (!initTop) initTop = 0
if (!contentWidth) contentWidth = width
if (document.layers && !y.ns4) history.go(0)
if (y.ie || y.ns4 || y.dom) {
this.loaded = false
this.id = id
this.origSpeed = speed
this.aniTimer = false
this.op = ""
this.lastTime = 0
this.clipH = height
this.clipW = width
this.scrollTop = initTop
this.scrollLeft = initLeft
this.gRef = "ypSimpleScroll_"+id
eval(this.gRef+"=this")
var d = document
d.write('<style type="text/css">')
d.write('#' + this.id + 'Container { left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px; clip:rect(0 ' + width + ' ' + height + ' 0); overflow:hidden; }')
d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; }')
d.write('#' + this.id + 'Content { left:' + (-initLeft) + 'px; top:' + (-initTop) + 'px; width:' + contentWidth + 'px; }')
d.write('</style>')
}
}
ypSimpleScroll.prototype.load = function() {
var d, lyrId1, lyrId2
d = document
lyrId1 = this.id + "Container"
lyrId2 = this.id + "Content"
this.container = this.y.dom ? d.getElementById(lyrId1) : this.y.ie ? d.all[lyrId1] : d.layers[lyrId1]
this.content = obj2 = this.y.ns4 ? this.container.layers[lyrId2] : this.y.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
this.docH = Math.max(this.y.ns4 ? this.content.document.height : this.content.offsetHeight, this.clipH)
this.docW = Math.max(this.y.ns4 ? this.content.document.width : this.content.offsetWidth, this.clipW)
this.scrollH = this.docH - this.clipH
this.scrollW = this.docW - this.clipW
this.loaded = true
this.scrollLeft = Math.max(Math.min(this.scrollLeft, this.scrollW),0)
this.scrollTop = Math.max(Math.min(this.scrollTop, this.scrollH),0)
this.jumpTo(this.scrollLeft, this.scrollTop)
}
var oThumb, oArrow, thumbTrackH, arrowTrackH;

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set the scroller window sizes!!!
// ypSimpleScroll(id, left, top, width, height, speed, contentWidth, initLeft, initTop)
var mainScroll = new ypSimpleScroll("main", 0, 0, cwidth, cheight, 100);
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// ////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////
var thumbsiz = theight;
// ////////////////////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////////////////////////
/* ========================================================== */
/* called to initialise the scroller and thumb */

function initialise() {

oThumb = ypGetElementById("scrollBarThumb");
mainScroll.load(); 
Drag.init(oThumb, 0, 0, thumbsiz, 0); 
oThumb.onDrag = function() { doDrag(); }
}
/* called when he wants to start scrolling down */
function doDown() {
this.aniTimer = window.setTimeout("moveDown()", 1);
}
/* move the thumb down and scroll the proportional amount */
function moveDown() {
if (parseInt(oThumb.style.top) >= thumbsiz) {
mainScroll.scrollTo(0,mainScroll.scrollH,75);
return(false);
} else {
var y = parseInt(oThumb.style.top) + 5;
if (y >= (thumbsiz-5)) y = thumbsiz;
oThumb.style.top = y;
y = y / thumbsiz;
mainScroll.scrollTo(0, parseInt(mainScroll.scrollH * y), 75);
this.aniTimer = window.setTimeout("moveDown()", 80);
}
}
/* called when he wants to stop scrolling */
function doStop() {
if (this.aniTimer) window.clearTimeout(this.aniTimer);
}
/* called when he wants to start scrolling up */
function doUp() {
this.aniTimer = window.setTimeout("moveUp()", 1);
}
/* move the thumb up and scroll the proportional amount */
function moveUp() {
if (parseInt(oThumb.style.top) == 0) {
mainScroll.scrollTo(0, 0, 75);
return(false);
} else {
var y = parseInt(oThumb.style.top) - 5;
if (y <= 5) y=0;
oThumb.style.top = y;
y = y / thumbsiz;
mainScroll.scrollTo(0, parseInt(mainScroll.scrollH * y), 75);
this.aniTimer = window.setTimeout("moveUp()", 80);
}
}
/* we get here while dragging */
function doDrag() {
var y = parseInt(oThumb.style.top);
if (y <= 4) {
mainScroll.scrollTo(0, 0, 10);
return(false);
} 
if (y >= thumbsiz-5) {
mainScroll.scrollTo(0,mainScroll.scrollH,10);
return(false);
}
y = y / thumbsiz;
mainScroll.scrollTo(0, parseInt(mainScroll.scrollH * y), 10);
}
function ypGetElementById(s) {
return (document.getElementById ? document.getElementById(s) : document.all[s])
}
function mousewheel() {
if (event.wheelDelta >= 120) {
if (parseInt(oThumb.style.top) == 0) {
mainScroll.scrollTo(0, 0, 75);
return(false);
} else {
var y = parseInt(oThumb.style.top) - 5;
if (y <= 5) y=0;
oThumb.style.top = y;
y = y / thumbsiz;
mainScroll.scrollTo(0, parseInt(mainScroll.scrollH * y), 75);
}
}
else if (event.wheelDelta <= -120) {
if (parseInt(oThumb.style.top) >= thumbsiz) {
mainScroll.scrollTo(0,mainScroll.scrollH,75);
return(false);
} else {
var y = parseInt(oThumb.style.top) + 5;
if (y >= (thumbsiz-5)) y = thumbsiz;
oThumb.style.top = y;
y = y / thumbsiz;
mainScroll.scrollTo(0, parseInt(mainScroll.scrollH * y), 75);
}
}
}
var Drag = {
obj : null,
init : function(o, minY, maxX, maxY, minX)
{
o.onmousedown = Drag.start;
if (o.style.left == "") o.style.left = "0px";
if (o.style.top == "") o.style.top = "0px";
o.minX = typeof minX != 'undefined' ? minX : null;
o.minY = typeof minY != 'undefined' ? minY : null;
o.maxX = typeof maxX != 'undefined' ? maxX : null;
o.maxY = typeof maxY != 'undefined' ? maxY : null;
o.onDragStart = new Function();
o.onDragEnd = new Function();
o.onDrag = new Function();
},
start : function(e)
{
var o = Drag.obj = this;
e = Drag.fixE(e);
var y = parseInt(o.style.top);
var x = parseInt(o.style.left);
o.onDragStart(x, y);
o.lastMouseX = e.clientX;
o.lastMouseY = e.clientY;
if (o.minX != null) o.minMouseX = e.clientX - x + o.minX;
if (o.minY != null) o.minMouseY = e.clientY - y + o.minY;
if (o.maxX != null) o.maxMouseX = o.minMouseX + o.maxX - o.minX;
if (o.maxY != null) o.maxMouseY = o.minMouseY + o.maxY - o.minY;
document.onmousemove = Drag.drag;
document.onmouseup = Drag.end;
return false;
},
drag : function(e)
{
e = Drag.fixE(e);
var o = Drag.obj;
var ey = e.clientY;
var ex = e.clientX;
var y = parseInt(o.style.top);
var x = parseInt(o.style.left);
var nx, ny;
if (o.minX != null) ex = Math.max(ex, o.minMouseX);
if (o.maxX != null) ex = Math.min(ex, o.maxMouseX);
if (o.minY != null) ey = Math.max(ey, o.minMouseY);
if (o.maxY != null) ey = Math.min(ey, o.maxMouseY);
nx = x + ex - o.lastMouseX;
ny = y + ey - o.lastMouseY;
Drag.obj.style.left = nx + "px";
Drag.obj.style.top = ny + "px";
Drag.obj.lastMouseX = ex;
Drag.obj.lastMouseY = ey;
Drag.obj.onDrag(nx, ny);
return false;
},
end : function()
{
document.onmousemove = null;
document.onmouseup = null;
Drag.obj.onDragEnd(parseInt(Drag.obj.style.left), parseInt(Drag.obj.style.top));
Drag.obj = null;
},
fixE : function(e)
{
if (!e) e = window.event;
if (!e.layerX) e.layerX = e.offsetX;
if (!e.layerY) e.layerY = e.offsetY;
return e;
}
};
