home *** CD-ROM | disk | FTP | other *** search
- //*****************************
- // VARIABLES *
- //*****************************
-
- var contentWindowLayer;
- var contentClipperLayer;
- var contentAreaLayer;
- var verticalTrackLayer;
- var upArrowLayer;
- var downArrowLayer;
- var verticalTabLayer;
-
- var itemID = 1;
- var snapTimerID = 0;
- var beginSnapTimerID = 0;
- var itemHeight;
- var beginRepeatDelay = 300; //length of delay (in milliseconds) before start of repeated execution of snapContent() upon clicking arrow buttons
- var contentWindowY;
- var contentW;
- var contentH;
- var arrowH;
- var vTabH;
- var vTabTopLimit;
- var vTabBottomLimit;
- var vTabRange;
- var vddMultiplier;
- var tabSnapIncrement;
-
-
- //*****************************
- // FUNCTIONS *
- //*****************************
-
- // use this if the entire content area resizes, such as on initial load.
- // configures the appropriate position for all of the scrollbar elements.
-
- function scrollbarSetup() {
-
- repeatDelay = 150;
-
- contentWindowLayer = document.layers["contentWindow"];
- contentClipperLayer = contentWindowLayer.layers["contentClipper"];
- contentAreaLayer = contentClipperLayer.layers["contentArea"];
- verticalTrackLayer = contentWindowLayer.layers["verticalTrack"];
- upArrowLayer = contentWindowLayer.layers["upArrow"];
- downArrowLayer = contentWindowLayer.layers["downArrow"];
- verticalTabLayer = contentWindowLayer.layers["verticalTab"];
-
- // First, compute the appropriate positions
-
- itemHeight = contentAreaLayer.itemHeight;
-
- // Then, move the scrollbar elements around
-
- //set down arrow location relative to content clipper layer height.
- downArrowLayer.moveTo(175, (contentClipperLayer.clip.height - 15));
- downArrowLayer.zIndex=800;
-
- //vertical scrollbar tab bottom edge position limit
- vTabBottomLimit = downArrowLayer.top;
-
- //vertical scrollbar tab top edge position limit
- //the magic constant is the height of visible part (less than 15 pixels by 15 pixels) of the arrow button images
- vTabTopLimit = 14;
-
- //vertical scrollbar tab height
- vTabH = verticalTabLayer.document.images[0].height;
-
- //vertical scrollbar tab track length
- vTabRange = vTabBottomLimit - vTabH - vTabTopLimit; //don't ask. it works.
-
- //content window top edge
- contentWindowY = contentWindowLayer.top;
-
- //content area document width
- contentW = contentAreaLayer.document.width;
-
- //content area document height
- contentH = contentAreaLayer.document.height;
-
- //arrow height
- arrowH = upArrowLayer.document.images[0].height;
-
- // remember to resize the scrollbar itself based on the present contents
- sizeScrollbar();
- }
-
- // sizeScrollbar gets called whenever the content area changes size, so that the
- // scrollbar can recompute its size, position, and the like. We take the height
- // and number of items from the appropriately set variables in the content area.
-
- function sizeScrollbar() {
- //visibility of track, buttons and tab defaults to hide.
- //the track layer and image height is greater than we will ever use.
- //up arrow location is constant; we don't change it here.
-
- contentH = contentAreaLayer.topPos;
- maxItems = contentAreaLayer.itemCount;
-
- //value by which to multiply mouse position delta
- //for use in contentAreaLayer.moveTo() in tabScrollVertically(), in vertical_scroll.js
- vddMultiplier = ((contentH - ((vTabRange + (arrowH * 2)))));
-
- //distance of tab movement when up arrow is clicked
- tabSnapIncrement = vTabRange / (maxItems - 2); //don't ask. it works.
-
- // make track, buttons and tab visible, but only if the content space is large enough
- // to accomodate them
-
- if (contentH > contentClipperLayer.clip.height) {
- // verticalTrackLayer.visibility = "show";
- upArrowLayer.visibility = "show";
- downArrowLayer.visibility = "show";
- // verticalTabLayer.visibility = "show";
- } else {
- verticalTrackLayer.visibility = "hide";
- upArrowLayer.visibility = "hide";
- downArrowLayer.visibility = "hide";
- verticalTabLayer.visibility = "hide";
- }
- }
-
- function arrowTimer(direction) {
- //if the mouse is held down for N milliseconds, start repeating the incremental scrolling
- if(direction == "up") {
- //scroll the content up one increment
- snapContent('up');
-
- //beginSnapTimerID is cleared in arrowBehavior()
- beginSnapTimerID = setTimeout(repeatSnapContent, beginRepeatDelay, "up");
- }
-
- else if(direction == "down") {
- //scroll the content down one increment
- snapContent('down');
-
- //beginSnapTimerID is cleared in arrowBehavior()
- beginSnapTimerID = setTimeout(repeatSnapContent, beginRepeatDelay, "down");
- }
- }
-
- function repeatSnapContent(direction) {
- // java.lang.System.out.println("RepeatSnapContent called");
-
- snapContent(direction);
-
- //if the mouse down persists, repeat the incremental scrolling
- //snapTimerID is cleared in arrowBehavior()
- snapTimerID = setTimeout(repeatSnapContent, repeatDelay, direction);
- }
-
- function snapContent(direction) {
- // java.lang.System.out.println("SnapContent called (" + direction + "), itemID = " + itemID + ", max = " + maxItems);
- //the "down" arrow was clicked
- if(direction == "down") {
- //if the item number has incremented beyond the last item
- if(itemID > maxItems) {
- //reset the item number to the last item and do nothing
- itemID = maxItems;
- return;
- }
-
- //otherwise
- else {
- //if reasonable, increment the item number
- if((itemID + 1) > maxItems) return;
- else itemID += 1;
-
- //update tab layer properties to reflect new position
- verticalTabLayer.tabOffset = 0;
- verticalTabLayer.setPreviousTabPosition(verticalTabLayer.DRAG_Y);
- verticalTabLayer.recalcTabPosition(verticalTabLayer.top, vTabTopLimit);
-
- //move tab only if it is within bounds
- if(itemID == (maxItems - 1)) verticalTabLayer.moveTo(verticalTabLayer.left, (vTabBottomLimit - vTabH));
- else if(itemID < maxItems) verticalTabLayer.checkTabBounds(tabSnapIncrement, vTabTopLimit);
- else if(itemID == maxItems) return;
-
- //update tab layer properties
- // verticalTabLayer.recalcVerticalDragDelta();
- // verticalTabLayer.recalcContentY();
-
- //move the content area layer down by one item length
- contentAreaLayer.moveBy(0, -itemHeight);
- }
- }
-
- //the "up" arrow was clicked
- if(direction == "up") {
- //if the item number has decremented beyond the first item
- if(itemID < 1) {
- //reset the item number to the first item and do nothing
- itemID = 1;
- return;
- }
-
- //otherwise
- else {
- //if reasonable, decrement the item number
- if((itemID - 1) < 1) return;
- else itemID -= 1;
-
- //update tab layer properties to reflect new position
- verticalTabLayer.tabOffset = 0;
- verticalTabLayer.setPreviousTabPosition();
- verticalTabLayer.recalcTabPosition(verticalTabLayer.top, vTabTopLimit);
-
- //move tab only if it is within bounds
- if(itemID == 1) verticalTabLayer.moveTo(verticalTabLayer.left, vTabTopLimit);
- else verticalTabLayer.checkTabBounds(-tabSnapIncrement, vTabTopLimit);
-
- //update tab layer properties
- verticalTabLayer.recalcVerticalDragDelta();
- verticalTabLayer.recalcContentY();
-
- //if it isn't already at the top,
- if(contentAreaLayer.top >= 0) {
- contentAreaLayer.top = 0;
- itemID = 1;
- return;
- }
- else {
- //move the content area layer down by one item length
- contentAreaLayer.moveBy(0, itemHeight);
- }
- }
- }
- }
-
- //depression behavior for scrollbar arrow buttons,
- //and clearTimeout() for setTimeout() in arrowTimer() and repeatSnapContent()
- function arrowBehavior(direction,state) {
- if(direction == "up") {
- if(state == "in") {
- upArrowLayer.document.images["upArrowImage"].src = "images/i_uparr.gif";
- }
- else if(state == "out") {
- upArrowLayer.document.images["upArrowImage"].src = "images/o_uparr.gif";
-
- //clear timer IDs
- clearTimeout(snapTimerID);
- clearTimeout(beginSnapTimerID);
- }
- }
-
- else if(direction == "down") {
- if(state == "in") {
- downArrowLayer.document.images["downArrowImage"].src = "images/i_dnarr.gif";
- }
- else if(state == "out") {
- downArrowLayer.document.images["downArrowImage"].src = "images/o_dnarr.gif";
-
- //clear timer IDs
- clearTimeout(snapTimerID);
- clearTimeout(beginSnapTimerID);
- }
- }
- }
-
-