if (typeof(wsZoom)=="undefined") wsZoom={};
wsZoom.templates=new Array("t","s","m","l","o");
wsZoom.instances = new Array();
wsZoom.altImages = new Array();
wsZoom.link=function(sImgURL,newTemplate,oldTemplate) {
	imgURL=sImgURL.toString();
	var idx=imgURL.indexOf(".jpg")-1;
	if (typeof(oldTemplate)=="undefined") oldTemplate=imgURL.substring(idx,idx+1);
	newTemplate=newTemplate.toString().toLowerCase();
	oldTemplate=oldTemplate.toString().toLowerCase();	
	imgURL=imgURL.replace("/"+oldTemplate+"/","/"+newTemplate+"/");
	imgURL=imgURL.replace("_"+oldTemplate+".jpg","_"+newTemplate+".jpg");
	imgURL=imgURL.replaceAll(" ","%20");
	//alert(sImgURL+'\n'+idx+' :: '+oldTemplate+' --> '+newTemplate+'\n\n'+imgURL);
	return(imgURL);
}
wsZoom.add = function (productDisplayID, targetClientID, thumbsClientID, infoID, zoomEnabled) {
    wsZoom.instances[wsZoom.instances.length] = new Array(productDisplayID, targetClientID, thumbsClientID, infoID, zoomEnabled);
    wsZoom.setup(productDisplayID);
}
wsZoom.getInstance=function(productDisplayID) {
	for (j=0; j<wsZoom.instances.length; j++) 
		if (wsZoom.instances[j][0] == productDisplayID)
			return(wsZoom.instances[j]);
}
wsZoom.debug = function () {
    smsg = "";
    for (j = 0; j < wsZoom.instances.length; j++)
        smsg += wsZoom.instances[j].toString() + "\n";
    alert(smsg);
}
wsZoom.setup = function (productDisplayID) {
    oInstance = wsZoom.getInstance(productDisplayID);
    thumbsObj = document.getElementById(oInstance[2]);
    infoObj = document.getElementById(oInstance[3]);
    numAltImages = 0;
    for (j = 0; j < wsZoom.altImages.length; j++)
        if (wsZoom.altImages[j][0] == productDisplayID)
            numAltImages++;

    if (oInstance[4] == false)
        infoObj.style.display = "none";

    if (numAltImages == 0) {

    } else if (numAltImages > 1) {
        ihtml = "<div class='zoomImgTitle'>Product Views:</div>";
        for (i = 0; i < wsZoom.altImages.length; i++)
            if (wsZoom.altImages[i][0] == productDisplayID)
                ihtml += "<a class='zoomAltImg' href=\"javascript:wsZoom.updateZoom('" + oInstance[0] + "','" + wsZoom.link(wsZoom.altImages[i][1], 'l') + "');\"><img src='" + wsZoom.link(wsZoom.altImages[i][1], 't') + "' alt='Click to View' /></a>";
        thumbsObj.innerHTML = ihtml;
    } else {
        thumbsObj.style.display = "none";
    }
}
wsZoom.updateZoom = function (productDisplayID, swatch) {
    oInstance = wsZoom.getInstance(productDisplayID);
    if (oInstance[4] == true) {
        MagicZoomPlus.update(oInstance[1], wsZoom.link(swatch, "o"), swatch, 'show-title: false;show-loading:true;');
    }
    else {
        document.getElementById(oInstance[1]).firstChild.src = swatch;
    }
}

