if (app && app.Product) {
	if(typeof jqzoomoptions=="undefined") {
		var jqzoomoptions = {zoomWidth: 585,zoomHeight: 486,xOffset: 4,yOffset: 0,preloadImages:false,position: 'right',title: false,showEffect: 'fadein',fadeinSpeed: 'fast',hideEffect: 'hide',fadeoutSpeed: 'fast'};		
	}
	if(typeof showImageType=="undefined") {
		var showImageType = "large";
	}
	app.Product.doShowImages = function(selectedVal, vals)  {
		var that = this;
		vals = vals || {};
		
		// show swatch related images for the current variation value					
		jQuery.each(vals, function(){
			var imgCounter = -1;
			var thisVal = this;
			if (this.val === selectedVal && this.images) {
				if (this.images.small.length > 0) {
					jQuery(that.containerId+" .productthumbnails:first").html("");
					jq = jQuery(that.containerId+" .productimage a#jqzoom");
					if(jq.length > 0){
						jQuery("img#jqzoom_img").attr("src", thisVal.images[showImageType][0].url.replace(/&amp;/g,"&"));
						jq.attr("href", thisVal.images.xlarge[0].url.replace(/&amp;/g,"&"));
						jq.attr("alt", thisVal.images[showImageType][0].alt);
					}else{
						jQuery(that.containerId+" .productimage").html("").append(
								jQuery("<a>").attr("href", thisVal.images.xlarge[0].url.replace(/&amp;/g,"&")).attr("id", "jqzoom").append(
										jQuery("<img/>").attr("src", thisVal.images[showImageType][0].url.replace(/&amp;/g,"&")).attr('id', 'jqzoom_img').attr('alt', thisVal.images[showImageType][0].alt)
								)
						);
						$('#jqzoom').jqzoom(jqzoomoptions);
					}
				}
				// make sure to show number of images based on the smallest of large or small as these have to have 1-1 correspondence.
				var noOfImages = this.images.large.length >= this.images.thumb.length ? this.images.thumb.length : this.images.large.length;
				// show thumbnails only if more than 1 or if this is a subproduct (bundled/subproduct)
				if (this.images.small.length > 1 || that.isSubProduct()) {
					jQuery.each(this.images.thumb, function(index, value){
						imgCounter++;
						var imageInd = imgCounter;
						if (imgCounter > noOfImages - 1) {
							return;
						}

						jQuery(that.containerId+" .productthumbnails:last").append(jQuery("<img/>").attr("src", this.url.replace(/&amp;/g, '&')).attr("alt", this.alt + ' - ' + (index + 1)).attr("title", this.title).hover(function(e){
								
							jq = jQuery(that.containerId+" .productimage a#jqzoom");
							if(jq.length > 0){
								jQuery("img#jqzoom_img").attr("src", thisVal.images[showImageType][imageInd].url.replace(/&amp;/g,"&"));
								jq.attr("href", thisVal.images.xlarge[imageInd].url.replace(/&amp;/g,"&"));
								jq.attr('alt', thisVal.images.xlarge[imageInd].alt);
								that.zoomImageLink(thisVal.images.large[imageInd]);
							}else{
								jQuery(that.containerId+" .productimage").html("").append(										
									jQuery("<a>").attr("href", thisVal.images.xlarge[imageInd].url.replace(/&amp;/g,"&")).attr("id", "jqzoom").append(
											jQuery("<img/>").attr("src", thisVal.images[showImageType][imageInd].url.replace(/&amp;/g,"&")).attr('id', 'jqzoom_img').attr('alt', thisVal.images[showImageType][imageInd].alt)
									)
								);
								that.zoomImageLink(thisVal.images.large[imageInd]);
								$('#jqzoom').jqzoom(jqzoomoptions);
							}
							
						}));
					});
				}
			}
		});
	}
}

