/*
scroll.js

This code is from Dynamic Web Coding
www.dyn-web.com
Copyright 2001 by Sharon Paine
Permission granted to use this code as long as this
entire notice is included.
*/

dom = (document.getElementById) ? true : false;
ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
ns4 = (document.layers && !dom) ? true : false;
ie4 = (document.all && !dom) ? true : false;
nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

var scrTimer = 20; // interval between calls to scroll onmouseover
var scrTmId=0;        // for setTimeouts

var pgLoaded;
wndo = new Array();        // "window" for scrollable content

function dw_shiftTo(x,y) {
        if (ns4) { this.css.moveTo(x,y); }
        else { this.css.left=x+"px"; this.css.top=y+"px"; }
}

function dw_shiftBy(x,y) {
        if (ns4) { this.css.moveBy(x,y); }
        else {
                this.css.left = parseInt(this.css.left)+x+"px";
                this.css.top = parseInt(this.css.top)+y+"px";
        }
}

function dw_show() {        this.css.visibility = "visible"; }
function dw_hide() { this.css.visibility = "hidden"; }

// These functions are for onclick scrolling
function jumpDown(num,jump) {
        var y = parseInt(wndo[num].cnt.css.top);
        if (y>(-wndo[num].maxY)) {
                if ((y-jump)>(-wndo[num].maxY)) wndo[num].cnt.shiftBy(0,-jump);
                else wndo[num].cnt.shiftBy(0,-(wndo[num].maxY-Math.abs(y)));
  }
}

function jumpRight(num,jump) {
        var x = parseInt(wndo[num].cnt.css.left);
        if (x>(-wndo[num].maxX)) {
                if ((x-jump)>(-wndo[num].maxX)) wndo[num].cnt.shiftBy(-jump,0);
                else wndo[num].cnt.shiftBy(-(wndo[num].maxX-Math.abs(x)),0);
  }
}

function jumpUp(num,jump) {
        var y = parseInt(wndo[num].cnt.css.top);
        if (y<0) {
                if ((y+jump)<=0) wndo[num].cnt.shiftBy(0,jump);
                else wndo[num].cnt.shiftBy(0,-y);
        }
}

function jumpLeft(num,jump) {
        var x = parseInt(wndo[num].cnt.css.left);
        if (x<0) {
                if ((x+jump)<=0) wndo[num].cnt.shiftBy(jump,0);
                else wndo[num].cnt.shiftBy(-x,0);
        }
}

// These functions are for onmouseover scrolling
function inchDown(num,inc) {
        if (!pgLoaded) return; var y = parseInt(wndo[num].cnt.css.top);
        if (y>-wndo[num].maxY) {
                wndo[num].cnt.shiftBy(0,-inc);
                scrTmId = setTimeout("inchDown("+num+","+inc+")",scrTimer);
        }
}

function inchUp(num,inc) {
        if (!pgLoaded) return; var y = parseInt(wndo[num].cnt.css.top);
        if (y<0) {
                wndo[num].cnt.shiftBy(0,inc);
                scrTmId = setTimeout("inchUp("+num+","+inc+")",scrTimer);
  }
}

function inchRight(num,inc) {
        if (!pgLoaded) return; var y = parseInt(wndo[num].cnt.css.left);
        if (y>-wndo[num].maxX) {
                wndo[num].cnt.shiftBy(-inc,0);
                scrTmId = setTimeout("inchRight("+num+","+inc+")",scrTimer);
        }
}

function inchLeft(num,inc) {
        if (!pgLoaded) return; var y = parseInt(wndo[num].cnt.css.left);
        if (y<0) {
                wndo[num].cnt.shiftBy(inc,0);
                scrTmId = setTimeout("inchLeft("+num+","+inc+")",scrTimer);
  }
}

function stopScroll() {
        clearTimeout(scrTmId);
}

////////////////////////////////////////////////////////////////////
//  Constructor function used for creating scrollable content areas.
//        Used to create both wndo and content objects.
//  Argument for creating wndo objects:        id of wndo div.
//        Arguments for creating content (done in loadScrLyr function):
//        id of content div, id of html element that contains content.
//        NOTE: Netscape 6 needs that html container and its id
//        in order to get width for horizontal scrolling.
//        If only using vertical scrolling, that extra container
//        is not necessary.
////////////////////////////////////////////////////////////////////
function dw_lyrObj(obj,id) {
        this.el = (ns4)? getLyrRef(obj,document): (ie4)? document.all[obj]: (ie5||ns5)? document.getElementById(obj): null;
        this.css = (ns4)? this.el: (ie4||ie5||ns5)? this.el.style: null;
        this.height = (ns4)? this.el.clip.height: (ie4||ie5)? this.el.clientHeight: (ns5)? this.el.offsetHeight: 0;
        this.width = (ns4)? this.el.clip.width: (ie4||ie5)? this.el.clientWidth: (ns5)? (id)? document.getElementById(id).offsetWidth: this.el.offsetWidth: 0;
}

/////////////////////////////////////////////////////////////////////
// loadScrLyr function: loads scrollable content div(s)
//        arg's: wndo array number, id of scrollable div,
//        and id of table or other html element that contains div content.
//        NOTE: Netscape 6 needs that html container and its id
//        in order to get width for horizontal scrolling.
//        If only using vertical scrolling, that extra container
//        is not necessary.
/////////////////////////////////////////////////////////////////////
function loadScrLyr(num,lyr,id) {
        if (!pgLoaded) return; // avoid not loaded errors
        if (typeof wndo[num].cnt != "undefined") wndo[num].cnt.hide();
        wndo[num].cnt = new dw_lyrObj(lyr,id);
        wndo[num].cnt.show();
        wndo[num].cnt.shiftTo(0,0);        // restore top/left to 0
        wndo[num].maxX = wndo[num].cnt.width - wndo[num].width;
        wndo[num].maxY = wndo[num].cnt.height-100;// - wndo[num].height;
}

dw_lyrObj.prototype.shiftBy=dw_shiftBy;
dw_lyrObj.prototype.shiftTo=dw_shiftTo;
dw_lyrObj.prototype.show=dw_show;
dw_lyrObj.prototype.hide=dw_hide;

// get reference to nested layer for ns4
// from dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
        if (ns4) {
                var theLyr;
                for (var i=0; i<doc.layers.length; i++) {
                  theLyr = doc.layers[i];
                        if (theLyr.name == lyr) return theLyr;
                        else if (theLyr.document.layers.length > 0)
                    if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
                                        return theLyr;
          }
                return null;
  }
}
