// resize popup window to fit image
function ResizeToFit(dlg, picHeight, picWidth) {
 var imgWidth;
 var imgHeight;
 imgWidth = picWidth + 60; 
 imgHeight = picHeight + 145;
 dlg.resizeTo(imgWidth, imgHeight);
}

// build popup window
function mssDisplayImages(img, name, width, height){
 features = 
    "toolbar=no,location=no,directories=no,status=no,menubar=no," +
    "scrollbars=no,resizable=no,width=" + width + ",height=" + height;
 dlg = window.open ("","Details",features);
 dlg.document.write("<html><head><title>" + name + " Zoom</title></head>");
 dlg.document.write("<body bgcolor=white onLoad=\"javascript:opener.ResizeToFit(self,  picImg.height, picImg.width);\"><center>");
 dlg.document.write("<table width=100% height=100%>");
 dlg.document.write("<tr><td align=center valign=middle>");
 dlg.document.write("<b><font size=2 face=Arial>" + name + "</font></b><br><br><img name=\"picImg\" src=" + img + ">");
 dlg.document.write("</td></tr>");
 dlg.document.write("<tr><td align=center valign=middle>");
 dlg.document.write("<a href=# onClick=window.close();>");
 dlg.document.write("<font size=1 face=Arial>Click to close</font></a>");
 dlg.document.write("</td></tr>");
 dlg.document.write("</table></body></html>");
 dlg.document.close();
}

// switch alt image view
function changeImage(img) {
 var imageName;
 for (i = 1; i <= 9; i++) {
  imageName = "image" + i; 
  if (document.getElementById(imageName)) {
   document.getElementById(imageName).style.display='none';
  }
 }
 document.getElementById(img).style.display='block';
}


function changeMainImage(id, index, value, swap){
   id = id.toLowerCase();
   var img = document.getElementById('image1');
   img.firstChild.href = "http://site.perfectmatchboutique.com/images/"+id+"/"+value+".jpg";
   img.firstChild.firstChild.src = "http://site.perfectmatchboutique.com/images/"+id+"/"+value+"-s.jpg";
   img.firstChild.firstChild.removeAttribute("width");
   img.firstChild.firstChild.removeAttribute("height");
   if(document.getElementById('mss-multi-image-id')){
      document.getElementById('mss-multi-image-id').getElementsByTagName('a')[0].href = "http://site.perfectmatchboutique.com/images/"+id+"/"+value+".jpg";
   }
   changeImage('image1');
   
   if(swap != null && swap){
      $('mss-image-switch-select').options[0].selected=true;
   }

}
