/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 
    le.imageSet.js - image handling objects loaded in the data pre-load

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/

function ColorImage(colorCode, imageName) {
	this.colorCode = colorCode;
	this.imageName = imageName;

}

function ImageSet(imageSetId, w, h, zoomRegion, isLegacy) {
	this.imageSetId = imageSetId;
	this.height = h;
	this.width = w;
	this.isLegacy = isLegacy;
	//x, y, width, height
	this.zoomRegion = zoomRegion;
    this.colorImages = new Array();
    
    this.getColorImage = function(colorCode) {
    	var i;
    	for (i=0; i<this.colorImages.length; i++) {
    		if (this.colorImages[i].colorCode == colorCode) {
    			return this.colorImages[i].imageName;
    		}
    	}
    	return null;
    };
}

function ImageSetGroup () {
	this.imageSetList = new Array();
	this.currentImageSetId = "";
	
	this.getImageSetById = function (imageSetId) {
		var i;
	    for (i=0; i<this.imageSetList.length; i++) {
    		if (this.imageSetList[i].imageSetId == imageSetId) {
    			return this.imageSetList[i];
    		}
    	}
    	return null;
	};
	this.getImageSetByColor = function (colorCode) {
		var i;
	    for (i=0; i<this.imageSetList.length; i++) {
	    	var colorImage = this.imageSetList[i].getColorImage(colorCode);
    		if (colorImage !== null) {
    			return this.imageSetList[i];
    		}
    	}
    	return null;
	};
	this.getColorImageForISB = function (colorCode) {
		var i;
		var colorImage = null;
		// this.imageSetList.length - 1 because we don't want swatch images
	    for (i=0; i<this.imageSetList.length - 1; i++) {
	    	colorImage = this.imageSetList[i].getColorImage(colorCode);
    		if (colorImage !== null) {
    			return colorImage;
    		}
    	}
    	return this.imageSetList[0].colorImages[0].imageName;
	};
}
      