/* Copyright (c) 2003-2010, SearchFit, Inc. All rights reserved. */
if (typeof SFUI == "undefined" || !SFUI) { var SFUI = {}; }

SFUI.Scrollable =
{
    scrollTimer:null,
    scrollPixels:0,

    initNavigator:function(containerId) {
        var scrollable = document.getElementById(containerId);
        var scrollableRegion = YAHOO.util.Dom.getRegion(scrollable);
    
        var scrollUpNavigator = document.getElementById(containerId + "_scrollUpNavigator");
        scrollUpNavigator.style.display = scrollable.scrollTop > 0 ? "inline" : "none";
        if (scrollUpNavigator.style.display == "inline") {
            YAHOO.util.Dom.setX(scrollUpNavigator, scrollableRegion.left);
            YAHOO.util.Dom.setY(scrollUpNavigator, scrollableRegion.top);
            YAHOO.util.Dom.setStyle(scrollUpNavigator, "width", (scrollableRegion.right - scrollableRegion.left) + "px");
        }
    
        var scrollDownNavigator = document.getElementById(containerId + "_scrollDownNavigator");
        scrollDownNavigator.style.display = (scrollable.scrollTop + scrollableRegion.bottom - scrollableRegion.top) < scrollable.scrollHeight ? "inline" : "none";
        if (scrollDownNavigator.style.display == "inline") {
            var scrollDownNavigatorRegion = YAHOO.util.Dom.getRegion(scrollDownNavigator);
            YAHOO.util.Dom.setX(scrollDownNavigator, scrollableRegion.left);
            YAHOO.util.Dom.setY(scrollDownNavigator, scrollableRegion.bottom - (scrollDownNavigatorRegion.bottom - scrollDownNavigatorRegion.top));
            YAHOO.util.Dom.setStyle(scrollDownNavigator, "width", (scrollableRegion.right - scrollableRegion.left) + "px");
        }
    },
    scrollVertically:function(containerId, step) {
        this.scrollPixels += step > 0 ? 1 : -1;
        if (Math.abs(this.scrollPixels) > 25) { step *= 2; this.scrollPixels = 0; }
        document.getElementById(containerId).scrollTop += step;
        this.initNavigator(containerId);
        this.scrollTimer = setTimeout("SFUI.Scrollable.scrollVertically('" + containerId + "', " + step + ")", 10);
    },
    stopScrollVertically:function() {
        if (this.scrollTimer != null) {
            clearTimeout(this.scrollTimer);
            this.scrollTimer = null;
            this.scrollPixels = 0;
        }
    }
}