/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 
    le.photoViewer.js - Handles the image viewer
 
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
var sj_codebase = "http://s7.landsend.com/is-viewers/dhtml/";
function sbg() {} //make le.js:init() not error out
 
///////////////////////////////////////////////fixed method
SjPicture.prototype.load = function(inURL) {
 if (inURL == this.img.src) {
  if ((this.loaded == true)&&(this.img.complete==true)){
   eval('document.' + this.img._uId + '.onload=this.onLoad;');
   eval('document.' + this.img._uId + '.style.width=this._imageWidth;');
   eval('document.' + this.img._uId + '.style.height=this._imageHeight;');
   eval('document.' + this.img._uId + '.onload();');
  }
  return;
 }
 this.loaded = false;
 if (document.all) {
  sjGetElement(this.img._uId).outerHTML=this.img.str;
  this.imageElm = sjGetElement(this.img._uId);
  this.imageElm._parent = this;
  this.img._parent = this;
 }else{
  eval('document.' + this.img._uId + '.style.width="";');
  eval('document.' + this.img._uId + '.style.height="";');
 } 
 eval('document.' + this.img._uId + '.onload=null;'); 
 eval('document.' + this.img._uId + '.onerror=null;'); 
 eval('document.' + this.img._uId + '.onabort=null;'); 
 this.img.src = inURL;
 eval('document.' + this.img._uId + '.onload=this.onLoad;');
 eval('document.' + this.img._uId + '.onerror=this.onError;');
 eval('document.' + this.img._uId + '.onabort=this.onAbort;');
 eval('document.' + this.img._uId + '.src = inURL;');
 this.imageElm.useMap = this.useMap;
};
/////////////////////////////////////////////////////////////////end fixed
 
function createPhotoViewer (imageName) {
 var s7zoom = new SjZViewer("http://s7.landsend.com/is/image/LandsEnd/", imageName+"?op_sharpen=1", 268, 405);
 // initialize an internal s7 variable which was causing 404 requests in Apache logs
 s7zoom.zviewer.navloadURL = "http://aka.landsend.com/images/clear.gif?x=1";
 s7zoom.enableNav(3, null, null, 40, 50);
 s7zoom.setZoomStep(1);
 s7zoom.setMaxZoom(100);
 s7zoom.instructionsDisplayed = true;
 s7zoom.displayingSwatch = false;
 s7zoom.scale = 1;
 
 s7zoom.onEvent.onImageZoomedOut = function(x) {
  s7zoom.zoomInButton.className = css.imageViewer.inButtonActive;
  if (x == 1) {
   s7zoom.zoomOutButton.className = css.imageViewer.outButtonInactive;
   s7zoom.fullButton.className = css.imageViewer.fullButtonInactive;
  }
  s7zoom.scale = x;
 };
 
 s7zoom.onEvent.onImageZoomedIn = function(x) {
  if (x != 1) {
   s7zoom.zoomOutButton.className = css.imageViewer.outButtonActive;
   s7zoom.fullButton.className = css.imageViewer.fullButtonActive;
   if (x > 3 && s7zoom.displayingSwatch == false) {
    s7zoom.zoomInButton.className = css.imageViewer.inButtonInactive;
   } else if (x > 1 && s7zoom.displayingSwatch == true) {
    s7zoom.zoomInButton.className = css.imageViewer.inButtonInactive;
   }
  }
  if (s7zoom.instructionsDisplayed === false){
   s7zoom.showInstructionAlert();
   s7zoom.instructionsDisplayed = true;
  }
  s7zoom.scale = x;
 };
 
 s7zoom.onEvent.onImageResetted = function (x) {
  s7zoom.zoomOutButton.className = css.imageViewer.outButtonInactive;
  s7zoom.zoomInButton.className = css.imageViewer.inButtonActive;
  s7zoom.fullButton.className = css.imageViewer.fullButtonInactive;
  s7zoom.scale = x;
 };
 
 s7zoom.changeImage = function(url, w, h) {
  s7zoom.hideAlert();
  url=url+"?op_sharpen=1";
  s7zoom.setImage(url, false, w, h);
  if (w <= 350) {
   s7zoom.displayingSwatch = true; 
  } else {
   s7zoom.displayingSwatch = false;
  }
 };
 
 s7zoom.showColorAlert = function(colorName) {
  if (colorName.length > 1) {
   s7zoom.alertText.innerHTML = "We're sorry, this photograph is not color changeable to " + colorName+".";
  } else {
   s7zoom.alertText.innerHTML = "We're sorry, this photograph is not color changeable to the selected color.";
  }
  s7zoom.photoViewerAlert.className = css.imageViewer.showAlert;
  setTimeout(s7zoom.hideAlert, 3000);
 };
 
 s7zoom.showInstructionAlert = function() {
  s7zoom.alertText.innerHTML = "Click and drag to move image.";
  s7zoom.photoViewerAlert.className = css.imageViewer.showAlert;
  setTimeout(s7zoom.hideAlert, 5000);
 };
 
 s7zoom.hideAlert = function() {
  s7zoom.photoViewerAlert.className = css.imageViewer.hideAlert;
 };
 
 s7zoom.initZoomControls = function() {
  s7zoom.zoomOutButton = document.getElementById("outButton");
  s7zoom.zoomInButton = document.getElementById("inButton");
  s7zoom.fullButton = document.getElementById("fullButton");
  s7zoom.photoViewerAlert = document.getElementById("photoViewerAlert");
  s7zoom.alertText = document.getElementById("alertText");
  
  s7zoom.zoomInButton.className = css.imageViewer.inButtonActive;
  
  s7zoom.zoomOutButton.onclick = function() {
   if (s7zoom.zoomOutButton.className == css.imageViewer.outButtonActive) {
    s7zoom.zoomOut();
   }
  };
  s7zoom.zoomInButton.onclick = function() {
   if (s7zoom.zoomInButton.className == css.imageViewer.inButtonActive) {
    s7zoom.zoomIn();
   }
  };
  s7zoom.fullButton.onclick = function() {
   if (s7zoom.fullButton.className == css.imageViewer.fullButtonActive) {
    s7zoom.reset();
   }
  };
 };
 return s7zoom;
}
 
window.onload = function () {
 top.pViewers[window.name.split("_")[2]] = pViewer;
 pViewer.initZoomControls();
}
