// Open detail window
function openWin(s,wn,w,h){
	window.open(s,wn,"top=100,left=200,width="+w+",height="+h+",scrollbars=auto,resizable=yes");
}

//  Creates image object that stores various image states and action information
function ImgRec(bool,name,d,r,s,a,t) {
    this.isSelected = bool;
    this.name = name;
    this.regular = d;
    this.rollover = r;
    this.selected = s;
    this.action = a;
    this.target = t;
    return this;
}


//  Draws a series of images given specific image array
function drawImages(imgArray) {
    var length = imgArray.length;
    var name = "";
    var link = "";
    var target = "";

    for (var i=0; i<length; i++) {
        name = imgArray[i].name;
        link = imgArray[i].action;
        target = imgArray[i].target;

        document.write("<a href=\"\" onmouseout=\"selectImg(imgArray," + i + ",0);return false;\" onmouseover=\"selectImg(imgArray," + i + ",1);return false;\"");

        if (target != "") {
            document.write(" target=\" + target + \"");
        }

        document.write(" onclick=\"selectImg(imgArray," + i + ",2);" + link + "return false;\"><img src=\"" + imgArray[i].regular + "\" valign=\"top\" border=\"0\" name=\"" + name + "\"></a>");

        if (imgArray[i].isSelected) {
            document[name].src = imgArray[i].selected;
        }
    }
}

//  Changes the img src of a given image based on 3 possible states (default, rollover, selected)
function selectImg(array,type,action) {
    var name = array[type].name;

    if (array[type].isSelected != true) {
        if (action == 0) {
            document[name].src = array[type].regular;
        }
        else if (action == 1) {
            document[name].src = array[type].rollover;
        }
        else if (action == 2) {
            array[type].isSelected = true;
            document[name].src = array[type].selected;
            for (var i = 0; i < array.length; i++) {
                if (i != type) {
                    array[i].isSelected = false;
                    document[(array[i].name)].src = array[i].regular;
                }
            }
        }
    }
}


//  Changes the img src of a given img
function changeImg(name, image){
    document[name].src = image;
}

//  Toggles between 2 images specified by passed parameters
function toggleImg(number,a,b) {
    name = "i" + number;
    
    // remove "../" from the image src
    newImgSrc = a.slice(3,a.length);
    if ((document[name].src).indexOf(newImgSrc) != -1) {
        document[name].src = b;
    }
    else {
        document[name].src = a;
    }
}
