﻿IMAGELIB_LOADED = true;

if (UTILITY_LOADED == null)
    alert("Utility.js must be loaded before ImageLib.js");

/* class ImageRollovers */

// Note: Second arg must be first image filename, additional filenames must follow
ImageRollovers = function(basePath) {
    this.basePath = basePath + "/";
    this.imageArray = new Array();
    for (var i = 1; i < ImageRollovers.arguments.length; i++) {
        var arg = ImageRollovers.arguments[i];
        var id = "img" + i;
        var url = arg;
        var img = new Image();
        if (arg.indexOf("|") > -1) {
            var splitString = arg.split("|");
            id = splitString[0];
            url = splitString[1];
        }
        img.id = id;
        img.name = id;
        img.src = this.basePath + url;
        this.imageArray[id] = img;
    }
}

ImageRollovers.prototype.setImage = function(element, id) {
    if (isString(element))
        element = document.getElementById(element);
    if (element && element.src) {
        if (this.imageArray[id])
            element.src = this.imageArray[id].src;
    }
}

ImageRollovers.prototype.setMouseEvents = function(imgElement, overImageId, outImageId, downImageId, upImageId) {
    if (isString(imgElement))
        imgElement = document.getElementById(imgElement);
    if (element && element.src) {
        var object = this;
        if (overImageId)
            imgElement.onmouseover = function() { object.setImage(imgElement, overImageId) };
        if (outImageId)
            imgElement.onmouseout = function() { object.setImage(imgElement, outImageId) };
        if (downImageId)
            imgElement.onmousedown = function() { object.setImage(imgElement, downImageId) };
        if (upImageId)
            imgElement.onmouseup = function() { object.setImage(imgElement, upImageId) };
    }
}
