
var product = {

    selectedColorId: null,
    multipleColors: null,
    multipleColorSwatches: null,
    
    //PHP Provided Variables
    colorsArray: null,
    styleNum: null,
    productImagePrefix: null,
    numAngles: null,
    selectedAngleNumSuffix: null,
    defaultColorNameSuffix: null,
    
    initSelectors: function() {

        //TODO: potentially handle numAngles errors from items imported from SB
        if("" != this.numAngles && isNaN(this.numAngles)) {
            this.numAngles = 0;
        }

        this.loadImageAngles();

    },

    
    loadImageAngles: function() {
        if(this.numAngles > 0) {
            var colorNameSuffix = "";
            if(this.multipleColors) {
                if(null != this.selectedColorId && this.multipleColorSwatches) {
                    var colorKey = this.selectedColorId.substr("colorSelector_".length);
                    colorNameSuffix = this.colorsArray[colorKey]['colorNameSuffix'];
                } else {
                    colorNameSuffix = this.defaultColorNameSuffix
                }
            }

            anglesHTML = "";
           
            for(var i=1; i<=this.numAngles; i++) {
                var angleThumbSrc = this.productImagePrefix + this.styleNum + '_YPAT' + colorNameSuffix + '_'+i+'.jpg';

                anglesHTML += '<img src="'+ angleThumbSrc + '"\n'+
                              '     onmouseover="this.style.cursor = \'pointer\'; product.loadImage(null, \'_'+i+'\')"' +
                              '     class="imageViewThumb"/>\n';

            }

            $('imageViews').update(anglesHTML);
        }
    },

    /**
     * Swaps out the product image and its zoom counterpart.
     */
    loadImage: function(colorNameSuffix, angleNumSuffix) {
        if(this.numAngles > 0) {
            if(null == angleNumSuffix) {
                angleNumSuffix = "_1";
            }
        } else {
            angleNumSuffix = "";
        }

        if(null == colorNameSuffix) {
            colorNameSuffix = "";

            if(this.multipleColors) {
                if(null != this.selectedColorId && this.multipleColorSwatches) {
                    var colorKey = this.selectedColorId.substr("colorSelector_".length);
                    colorNameSuffix = this.colorsArray[colorKey]['colorNameSuffix'];
                } else {
                    colorNameSuffix = this.defaultColorNameSuffix;
                }
            }
        }

        $('imgThumbBox').src = this.productImagePrefix + this.styleNum + '_YPXL' + colorNameSuffix + angleNumSuffix + '.jpg';
        $('imgThumbBox').name = this.productImagePrefix + this.styleNum + '_YPZM' + colorNameSuffix + angleNumSuffix + '.jpg';
        illZoom.refreshImage();

        this.selectedAngleNumSuffix = angleNumSuffix;
    }
    
}



