
function ZoomBox( divZoomBox ) {
    var m_divZoomBox  = divZoomBox;
    var m_bInProgress = false;

    var m_iStartX = null;
    var m_iStartY = null;
    var m_iEndX   = null;
    var m_iEndY   = null;

    this.isInProgress             = isInProgress;
    this.getStartX                = getStartX;
    this.getStartY                = getStartY;
    this.getEndX                  = getEndX;
    this.getEndY                  = getEndY;
    this.start                    = start;
    this.update                   = update;
    this.stop                     = stop;
    this.setDragBoxAroundEndPoint = setDragBoxAroundEndPoint;
    this.hide                     = hide;
    this.tooSmall                 = tooSmall;


    function start( x, y ) {
        m_iStartX = x;
        m_iStartY = y;
        m_iEndX   = x;
        m_iEndY   = y;

        m_divZoomBox.style.left   = m_iStartX;
        m_divZoomBox.style.top    = m_iStartY;
        m_divZoomBox.style.width  = 0;
        m_divZoomBox.style.height = 0;

        m_bInProgress                 = true;
        m_divZoomBox.style.visibility = 'visible';
    }

    function update( x, y ) {
        if (!(m_bInProgress))
            return false;

        m_iEndX                   = x;
        m_iEndY                   = y;
        var iWidth                = m_iEndX - m_iStartX;
        var iHeight               = m_iEndY - m_iStartY;

        //!!! Setting these prevents onmouseup from firing!?
        m_divZoomBox.style.width  = Math.abs( iWidth );
        m_divZoomBox.style.height = Math.abs( iHeight );

        if (iWidth > 0)  m_divZoomBox.style.left = m_iStartX;
        else             m_divZoomBox.style.left = m_iEndX;

        if (iHeight > 0) m_divZoomBox.style.top = m_iStartY;
        else             m_divZoomBox.style.top = m_iEndY;
    }

    function stop() {
        m_bInProgress = false;
    }

    function setDragBoxAroundEndPoint() {
        m_iStartX = m_iEndX - 2;
        m_iStartY = m_iEndY - 2;
        update( m_iEndX + 2, m_iEndY + 2 );
    }

    function hide() {
        m_divZoomBox.style.visibility = 'hidden';
    }

    function tooSmall() {
        var tooSmall = 4;
        return ((Math.abs(getStartX() - getEndX()) < tooSmall) && (Math.abs(getStartY() - getEndY()) < tooSmall));
    }


    function getStartX()    { return m_iStartX; }
    function getStartY()    { return m_iStartY; }
    function getEndX()      { return m_iEndX; }
    function getEndY()      { return m_iEndY; }
    function isInProgress() { return m_bInProgress; }
}
