
function Extents() {
    this.persistExtent = persistExtent;
    this.getNext       = getNext;
    this.getPrev       = getPrev;
    this.addExtent     = addExtent;
    this.zoomPrev      = zoomPrev;
    this.zoomNext      = zoomNext;
    
    this.isInStack     = false;
    this.extentStack   = new Array();
    this.currentExtent = -1;
    this.maxLength     = 6;
    
    
    function persistExtent() {
        if(!this.isInStack)
            this.addExtent( agiMapViewer.getExtent() );
        this.isInStack = false;
    }
    
    function getNext() {
        if (this.currentExtent == this.extentStack.length -1)
            return null;
        this.isInStack = true;
        return this.extentStack[++this.currentExtent];
    }
    
    function getPrev() {
        if (this.currentExtent <= 0)
            return null;
        this.isInStack = true;
        return this.extentStack[--this.currentExtent];
    }
    
    function addExtent(aRect) {
        if (this.extentStack.length == this.maxLength)
            this.extentStack.splice( 0, 1 );
        
        this.extentStack.push( aRect );
        this.currentExtent = this.extentStack.length -1;
    }
    
    function zoomPrev() {
        var aRect = this.getPrev();
        if (aRect) {
            agiMapViewer.setExtent( aRect );
            requestMap();
        }
        else
            alert("No previous extent exists.");
    }
    
    function zoomNext() {
        var aRect = this.getNext();
        if (aRect) {
            agiMapViewer.setExtent( aRect );
            requestMap();
        }
        else
            alert("You are already at the last saved extent.");
    }
}
