/*
   RollableImage Object, 
   API for image rollovers
   gcpeters Wed., 10/03/01

   Copyright (c) 2001 Grant Peters.
   This code is free for use, and modify 
   with the precept that this copyright information
   remains with all implementations of this source code.
   
   Thank you, and enjoy.

*/

function RollableImage(theDocument, rootDir, name, prefix) {
    this.theDocument  = theDocument;
    this.rootDir      = rootDir;
    if(this.rootDir.charAt(this.rootDir.length - 1) != '/')
        this.rootDir += '/';
    this.name         = name;
    this.prefix       = prefix;
    this.ovrId        = (arguments.length >= 5) ? arguments[4] : '-ovr';
    this.sufix        = (arguments.length == 6) ? arguments[5] : '.gif';
    this.offImage     = new Image();
    this.offImage.src = this.rootDir + this.prefix + this.name + this.sufix;
    this.ovrImage     = new Image();
    this.ovrImage.src = this.rootDir + this.prefix + this.name + this.ovrId + this.sufix;
    this.isOff = true;
}
RollableImage.prototype.showImages = function() {
                                        var s = '';
                                        for(var i=0;i<this.theDocument.images.length;i++)
                                            s += this.theDocument.images[i].name + '\n';
                                        alert(s);
                                    }
RollableImage.prototype.getOffStateSrc = function(){return this.offImage.src;}
RollableImage.prototype.getOvrStateSrc = function(){return this.ovrImage.src;}
RollableImage.prototype.setOffStateSrc = function(src){this.offImage.src = src;}
RollableImage.prototype.setOvrStateSrc = function(src){this.ovrImage.src = src;}
RollableImage.prototype.matchName      = function(name) {return this.name == name;}
RollableImage.prototype.roll           = function () {
                                             this.theDocument.images[this.name].src = (this.isOff) ? 
                                                                                         this.getOvrStateSrc() : 
                                                                                         this.getOffStateSrc();
                                             this.isOff = !this.isOff;
                                         }