﻿/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function loadinv(src) {
  var aainvscript = document.createElement("script");
  aainvscript.type = "text/javascript";
  aainvscript.src = src;
  aainvscript.charset = 'ISO-8859-1';
  document.getElementsByTagName('head')[0].appendChild(aainvscript);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function ProductPage(data) {
  this.InstanceID = data.InstanceID;
  this.StyleID = data.StyleID;
  this.GenericCode = data.GenericCode;
  this.Name = data.Name;
  this.FormattedName = data.FormattedName;
  this.Caption = data.Caption;
  this.TemplateID = data.TemplateID;

  this.OnlineStoreID = data.OnlineStoreID;
  this.LanguageID = data.LanguageID;
  
  this.DefaultColor = data.DefaultColor;
  this.CurrentColor = this.DefaultColor;

  this.ColorArray = data.ColorArray;
  this.SizeArray = data.SizeArray;

  this.StoreCart = data.StoreCart;
  this.YahooCode = data.YahooCode;
  this.YahooDone = data.YahooDone;
  this.MsgUnavailble = data.MsgUnavailble;
  this.MsgSelectSize = data.MsgSelectSize;
  this.LanguageID = data.LanguageID;
  this.PageTracker = data.PageTracker;
  this.FULLSCREEN = '';
  this.MorePhotos = [];
  this.CloudZoom = null;
  this.SelectedColorCount = 0;
  this.IsRetail = true;
  if (data.IsRetail == undefined) {
    var d = document.domain;
    if (d) d = d.toString().toLowerCase()
    this.IsRetail = (d != "www.americanapparel.net"
    && d != "dev.americanapparel.net"
    && d != "americanapparel.net"
    );
  }
  else {
    this.IsRetail = data.IsRetail;
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.DestroyCloudZoom = function () {
  var e = this.CloudZoom;
  if (e) {
    e = $(e);
    if (e) {
      e = e.data('zoom');
      if (e && e.destroy) {
        e.destroy();
      }
    }
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.checkMorePhotos = function (attempts) {
    if (this.MorePhotos.length > 0) {
        var end, src, html = '';
        for (var i = 0; i < this.MorePhotos.length; i++) {
            src = this.MorePhotos[i];
            end = src.length - 5;
            start = (src.length - 8);

            //  html += '<img'
            // + (src.substr(end) == 'v.jpg'
            // ? ' class="iframe" onclick="javascirpt:imageSrc(\'' + src.substr(0, end) + '\')"'
            //  : ' onclick="javascript:' + this.InstanceID + '.showMoreImages(this);"'
            //  )
            //  + ' src="http://i.americanapparel.net/storefront/photos/morephotos/' + src + '" />';


            html += '<img'
                 + (src.substr(end) == 'v.jpg'
                   ? ' class="iframe" onclick="javascript:imageSrc(\'http://i.americanapparel.net/storefront/photos/morephotos/Video/?StyleID=\')"'
                   : ' onclick="javascript:' + this.InstanceID + '.showMoreImages(this);"'
                   )
                   + ' src="http://i.americanapparel.net/storefront/photos/morephotos/' + src + '" />';


            //    html += '<img'
            //        + (src.substr(end) == 'v.jpg'
            //          ? ' class="iframe" onclick="javascript:imageSrc(\'http://i.americanapparel.net/storefront/photos/morephotos/' + src.substr(0, end) + 'v.html\')"'
            //           : ' onclick="javascript:' + this.InstanceID + '.showMoreImages(this);"'
            //          )
            //         + ' src="http://i.americanapparel.net/storefront/photos/morephotos/' + src + '" />'
            //       ;






            //  + (src.substr(end) == 'v.jpg'
            //   ? ' class="fancy" href="http://i.americanapparel.net/storefront/photos/morephotos/' + src.substr(0, end) + 'v.html"'
            //   : ' onclick="javascript:' + this.InstanceID + '.showMoreImages(this);"'
            //  )
            // + ' src="http://i.americanapparel.net/storefront/photos/morephotos/' + src + '" />'
            //;




        }
        if (this.MorePhotos.length < 5) {
            e = document.getElementById("divMoreViewStaticImages"); if (e) e.innerHTML = html;
            e = document.getElementById("divMoreViewStatic"); if (e) e.style.display = '';
        }
        else {
            e = document.getElementById("divMoreViewScrollImages"); if (e) e.innerHTML = html;
            e = document.getElementById("divMoreViewScroll"); if (e) e.style.display = '';
            $("#infinite").scrollable().circular();
        }

        if ($("img.fancy") && $("img.fancy").fancybox) {
            $("img.fancy").fancybox({ 'type': 'iframe' });
        }
        //setTimeout(this.InstanceID + '.checkMoreVideos(' + (attempts + 1) + ');', 500);
    }
    else {
        if (attempts < 3) {
            setTimeout(this.InstanceID + '.checkMorePhotos(' + (attempts + 1) + ');', 500);
        }
    }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.checkGarmentSpecs = function (attempts) {
  if (this.GarmentSpecs != undefined) {
    var e;
    if (this.GarmentSpecs) {
      e = document.getElementById("hlkSpecifications");
      if (e) {
        e.href = 'javascript:popUpSize("http://www.americanapparel.net/garmentspecs/Index.asp?GarmentSpecID=' + this.GenericCode
      + (this.OnlineStoreID == 1 ? '' : '&M=1')
      + '&l=' + this.LanguageID
      + '");';
        e.style.display = '';
      }
    }
  }
  else {
    if (attempts < 3) {
      setTimeout(this.InstanceID + '.checkGarmentSpecs(' + (attempts + 1) + ');', 500);
    }
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.showMoreImages = function (img) {
    var e = document.getElementById("im_" + this.StyleID);
    var f = document.getElementById("dv_" + this.StyleID);
    var g = document.getElementById("hlkFullScreen");
    var h = document.getElementById("rolloverImage");
    var i = document.getElementById("videoContainer");
    var j = document.getElementById("rolloverLaunch");
    if (e && img.src) {
        var prefix = img.src.substr(0, img.src.length - 5);
        e.src = prefix + "d.jpg";
        this.setFullScreen(prefix + ".jpg");

        f.style.display = 'block';
        i.style.display = 'none';
        g.style.display = 'block';
        h.style.display = 'block';
        j.style.display = 'block';

    }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.completeThisLook = function() {
  window.open
  ("product/popup/completelook.aspx?style=" + this.StyleID
  , "CompleteThisLook"
  , "width=760,height=680,location=no,scrollbars=yes,menubars=no,toolbars=no,resize=no"
  );
  return false;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.addToWishlist = function () {
  var e = window.open
  ("http://www.americanapparel.net/storefront/mywishlist/wishlist.aspx"
  + "?Style=" + this.StyleID
  + "&color=" + encodeURI(document.getElementById('Color').value).toString().replace(/\+/g, '%2B')
  + "&size=" + encodeURI(document.getElementById('Size').value).toString().replace(/\+/g, '%2B')
  + "&OnlineStoreID=" + this.OnlineStoreID
  , "wishlist"
  , "width=637,height=680,location=no,scrollbars=yes,menubars=no,toolbars=no,resize=no"
  );
  if (e) e.focus();
  return false;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.findInStores = function () {
  var e = window.open
    ("http://www.americanapparel.net/storefront/reservations/default.aspx"
    + "?sid=" + this.StyleID
    + "&c=" + encodeURI(document.getElementById('Color').value).toString().replace(/\+/g, '%2B')
    + "&s=" + encodeURI(document.getElementById('Size').value).toString().replace(/\+/g, '%2B')
    + "&o=" + this.OnlineStoreID
    + "&l=" + this.LanguageID
    , "Popup"
    , "width=650,height=650,location=no,scrollbars=yes,menubars=no,toolbars=no,resize=no"
    );
  if (e) e.focus();
  return false;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.ShowReviews = function () {
  popIt('530', '444', '1', 'Ratings'
  , 'http://www.americanapparel.net/storefront/ratingsreviews/Reviews.aspx'
  + '?r=' + this.OnlineStoreID
  + '&s=' + this.StyleID
  + '&gc=' + this.GenericCode
  + '&dc=' + this.CurrentColor
  );
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.showHide = function(id) {
  var e = document.getElementById(id);
  if (e) {
    e.style.display = (e.style.display == "none" ? "" : "none");
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.setFullScreen = function (url) {
  this.FULLSCREEN = url;
  this.DestroyCloudZoom();
  var e = document.getElementById('imgFullScreen'); if (e) { e.href = url; }
  url = 'http://i.americanapparel.net/storefront/photos/fullscreen.html?l='
      + this.LanguageID
      + '&i='
      + url
      ;
  e = document.getElementById('hlkFullScreen'); if (e) { e.href = url; }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.CheckFullScreen = function () {
  if (this.FULLSCREEN) {
    this._checkFullScreen(this.FULLSCREEN, 0);
    this.FULLSCREEN = '';
  }
  return false;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype._checkFullScreen = function (url, attempts) {
  this.DestroyCloudZoom();
  var e;
  var found = false;
  if (url) {
    var img = new Image();
    img.src = url;
    if (img.height > 50) {
      found = true;
      // Show Full Screen features
      e = document.getElementById('divFullScreen'); if (e) { e.style.visibility = "visible"; e.style.display = ""; }
      //this.CloudZoom = $('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
      this.CloudZoom = $('#imgFullScreen').CloudZoom();

      // Stops further attempts
      attempts = 3;
    }
    else {
      if (attempts < 3) {
        setTimeout(this.InstanceID + '._checkFullScreen("' + url + '", ' + (attempts + 1) + ')', 1000);
      }
    }
  }
  if (!found && attempts > 0) {
    e = document.getElementById('divFullScreen'); if (e) { e.style.visibility = "hidden"; }
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.changeImage = function (color, ignore) {
  var e = document.getElementById("im_" + this.StyleID);
  var f = document.getElementById("dv_" + this.StyleID);
  var g = document.getElementById("hlkFullScreen");
  var h = document.getElementById("rolloverImage");
  var i = document.getElementById("videoContainer");
  var j = document.getElementById("rolloverLaunch");
  if (!ignore) {
    if (f) f.style.display = 'block';
    if (i) i.style.display = 'none';
    if (g) g.style.display = 'block';
    if (h) h.style.display = 'block';
    if (j) j.style.display = 'block';
  }

  this.CurrentColor = color;

  color = color.replace(/ /g, '');
  color = color.replace(/\//g, '_');
  color = color.replace(/è/g, 'e');
  color = color.replace(/é/g, 'e');
  var url = "http://i.americanapparel.net/storefront/photos/detail/serve.asp?media="
  + this.StyleID
  + "_"
  + color
  + (this.IsRetail ? ".jpg" : ".jpg&r=us1")
  ;
  var e = document.getElementById("im_" + this.StyleID);
  if (e && e.src != url) {
    ImageTransition(this.StyleID, url);
  }
  url = "http://i.americanapparel.net/storefront/photos/zoom/serve.asp?media=" + this.StyleID + "_" + color + ".jpg";
  this.setFullScreen(url);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype._changeOption = function (field, value, array, ignore) {
  var i, e, lang;
  if (!ignore) {
    for (i = 0; i < array.length; i++) {
      e = document.getElementById(array[i]);
      if (e) e.className = 'option';
    }
    e = document.getElementById(value);
    if (e) {
      e.className = 'option picked';
      lang = e.title;
    }
    e = document.getElementById(field);
    if (e) e.value = value;
  }
  e = document.getElementById('lbl' + field);
  if (e) {
    e.innerHTML = (lang ? lang : value);
    e.className = 'output';
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype._changeColor = function (value, ignore) {
  this._changeOption('Color', value, this.ColorArray, ignore);
  this.changeImage(value, ignore);
  this.checkAvailability(value, false);
  if (this.ChangeColorTimeoutID) {
    clearTimeout(this.ChangeColorTimeoutID);
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.changeColor = function (value, ignore) {
  if (value) {
    if (!ignore) {
      this.SelectedColor = value;
      this.SelectedColorCount++;
    }
    var change = (this.SelectedColorCount < 2 || !ignore);
    if (change) {
      this._changeColor(value, ignore);
    }
  }
  else {
    var timeout = (this.SelectedColor && this.SelectedColorCount < 2);
    if (timeout) {
      this.ChangeColorTimeoutID = setTimeout(this.InstanceID + "._changeColor("
      + (this.SelectedColor ? "'" + this.SelectedColor + "'" : "false")
      + ",true)", 500);
    }
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.changeSize = function (value) {
  this._changeOption('Size', value, this.SizeArray, false);
  this.checkAvailability();
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.isInsideComboArray = function (comboArray, color, size, tag) {
  var classNameSuffix = ' ' + tag.toLowerCase();
  var i, j, k, e, found = false;

  for (i = 0; i < this.SizeArray.length; i++) {
    e = document.getElementById(this.SizeArray[i]);
    if (e) e.className = e.className.replace(classNameSuffix, "");
  }

  var xcolor, xsize;
  for (i = 0; i < comboArray.length; i++) {
    k = comboArray[i].indexOf("_");
    xcolor = comboArray[i].substring(0, k);
    if (xcolor == color) {
      xsize = comboArray[i].substring(k + 1);
      e = document.getElementById(xsize);
      if (e) {
        e.className += classNameSuffix
      }
      if (xsize == size) {
        found = true;
      }
    }
  }
  return found;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.checkAvailability = function (color, size) {
  var e, ex, eu, eb, ep;

  eu = document.getElementById('divUnavailable');
  eb = document.getElementById('divBackordered');
  ep = document.getElementById('divPreOrder')

  if (eu) eu.style.display = "none";
  if (eb) eb.style.display = "none";
  if (ep) ep.style.display = "none";

  color = (color ? color : document.getElementById('Color').value);
  size = (size ? size : document.getElementById('Size').value);

  var showid = "divSubmit";
  var hideid = "divSubmitDisabled";
  if (this.isInsideComboArray(DeadSKU, color, size, 'Unavailable')) {
    e = eu;
    showid = "divSubmitDisabled";
    hideid = "divSubmit";
  }
  else if (this.isInsideComboArray(BOSKU, color, size, 'Backordered')) e = eb;
  else if (this.isInsideComboArray(POSKU, color, size, 'PreOrder')) e = ep;

  if (e) e.style.display = "";

  e = document.getElementById(showid); if (e) e.style.display = "";
  e = document.getElementById(hideid); if (e) e.style.display = "none";
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.getExactTarget = function (yahoo) {
  var s = ''
  if (getCookie) {
    var j = getCookie("JobID");
    var e = getCookie("EmailAddr");
    var l = getCookie("ListID");
    var u = getCookie("LinkID");
    var jb = getCookie("BatchID");
    var mid = getCookie("MemberID");
    if (j || e || l || u || jb || mid) {
      if (yahoo) {
        s = "-ET"
        + "[j." + (j == undefined ? '' : j)
        + ";e." + (e == undefined ? '' : e)
        + ";l." + (l == undefined ? '' : l)
        + ";u." + (u == undefined ? '' : u)
        + ";jb." + (jb == undefined ? '' : jb)
        + ";mid." + (mid == undefined ? '' : mid)
        + ']'
        ;
      }
      else {
        s
        = "&JobID=" + (j == undefined ? '' : j)
        + "&Email=" + (e == undefined ? '' : e)
        + "&ListID=" + (l == undefined ? '' : l)
        + "&LinkID=" + (u == undefined ? '' : u)
        + "&BatchID=" + (jb == undefined ? '' : jb)
        + "&MemberID=" + (mid == undefined ? '' : mid)
        ;
      }
    }
  }
  return s;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.checkout = function () {
  var i, e, c, s, msg, url = this.StoreCart;
  e = document.getElementById('Quantity');
  var yahoo = (url == 'http://order.store.yahoo.net/cgi-bin/wg-order');
  if (yahoo) {
    url += "?vwitem=" + this.StyleID
         + "&vwcatalog=" + this.YahooCode
         + "&vwquantity=" + e.value
  }
  else {
    url += '?storeid=' + this.OnlineStoreID
         + '&languageid=' + (this.OnlineStoreID == 15 ? 12 : this.LanguageID)
         + '&style=' + this.StyleID
         + '&quantity=' + e.value
         + '&add=' + e.value
  }
  e = document.getElementById('Color'); if (e) c = e.value;
  e = document.getElementById('Size'); if (e) s = e.value;

  if (s) {
    if (yahoo) {
      if (c) {
        url += "&Color=" + (this.OnlineStoreID == 5 || this.OnlineStoreID == 7 ? c.replace(/\+/g, '%2B') : escape(c).replace(/\+/g, '%2B'));
      }
      url += "&Size=" + (this.OnlineStoreID == 5 || this.OnlineStoreID == 7 ? s.replace(/\+/g, '%2B') : escape(s).replace(/\+/g, '%2B'));
    } else {
      url += (c ? "&Color=" + encodeURI(c).replace(/\+/g, '%2B') : "None");
      url += "&Size=" + encodeURI(s).replace(/\+/g, '%2B');
    }
  }
  else {
    if (this.SizeArray.length) {
      msg = this.MsgSelectSize;
    }
    else {
      c = "";
    }
  }

  if (msg) {
    alert(msg);
    return false;
  }
  else {
    i = -1;
    if (document.referrer && document.domain && document.referrer.indexOf) {
      i = document.referrer.indexOf(document.domain);
    }
    var category = '';
    if (-1 < i && i < 10) {
      category = document.referrer;
      category = category.substr(category.indexOf('/', 10) + 1);
      category = category.substr(0, category.indexOf(".html"));
    }
    if (yahoo) {
      var lid = this.LanguageID;
      url += '&.autodone=http%3A%2F%2F'
              + this.YahooDone
              + '%2F'
              + this.StyleID
              + '.html&x='
              + (lid == 1 ? "en" :
                 (lid == 2 ? "fr" :
                  (lid == 3 ? "de" :
                   (lid == 4 ? "ja" :
                    (lid == 5 ? "da" :
                     (lid == 6 ? "nl" :
                      (lid == 7 ? "he" :
                       (lid == 8 ? "it" :
                        (lid == 9 ? "ko" :
                         (lid == 10 ? "es" :
                          (lid == 11 ? "fr" : "en")))))))))))
              + (category ? '-' + category : '')
              + this.getExactTarget(yahoo)
              ;
      window.location = url;
    } else {
      if (!c) url += "&Color=None";
      if (!s) url += "&Size=None";
      if (category) url += '&Category=' + category;
      url += this.getExactTarget(yahoo);
      if (this.PageTracker) {
        this.PageTracker._link(url);
      }
      else {
        window.location = url;
      }
    }
    return true;
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
ProductPage.prototype.init = function () {
  var e;

  if (getQueryStringValue("view") == 1) {
    this._checkFullScreen = function () { return false; }
  }
  this.DestroyCloudZoom();

  loadinv("http://i.americanapparel.net/storefront/inventory/skucheck_extreme.asp?r=" + this.OnlineStoreID + "&s=" + this.StyleID);
  loadinv("http://i.americanapparel.net/storefront/photos/morephotos/index.aspx?v=" + this.InstanceID + ".MorePhotos&s=" + this.StyleID + (this.IsRetail ? "" : "&o=8"));
  loadinv("http://i.americanapparel.net/garmentspecs/check.aspx?gc=" + this.GenericCode + "&v=" + this.InstanceID + ".GarmentSpecs");

  var color = (this.ColorArray && this.ColorArray.length == 1 ? this.ColorArray[0] : this.DefaultColor);
  var parms = window.location.search.substring(1).split('&');
  var queryStringColor;
  for (var i = 0; i < parms.length; i++) {
    pos = parms[i].indexOf('=');
    if (pos > 0 && parms[i].substring(0, pos) == 'c') {
      queryStringColor = parms[i].substring(pos + 1);
      break;
    }
  }

  this.changeColor(queryStringColor ? unescape(queryStringColor) : color);
  if (this.SizeArray && this.SizeArray.length == 1) this.changeSize(this.SizeArray[0]);

  this.CheckFullScreen();
  setTimeout(this.InstanceID + '.checkMorePhotos(0);', 500);

  if (!this.TemplateID) {
    this.TemplateID = getQueryStringValue("TemplateID");
  }
  if (this.TemplateID) {
    e = document.getElementById("divCustomizeItem");
    if (e) e.style.display = "block";
    e = document.getElementById("hlkCustomizeItem");
    if (e) e.href = "http://www.americanapparel.net/storefront/customizeitem/index.aspx?ti=" + this.TemplateID
  + "&gc=" + this.GenericCode
  + "&fn=" + this.FormattedName.replace(/ /g, '+').replace(/</g, '[gt]').replace(/>/g, '[lt]')
  + "&cp=" + this.Caption.replace(/ /g, '+').replace(/</g, '[gt]').replace(/>/g, '[lt]');
  }
  var tid = getQueryStringValue("tid");
  if (tid) {
    e = document.getElementById("createOwnBtn");
    if (e) e.style.display = "block";
    loadinv("http://stage.dabbleapp.com/loaders/instantiation.js?new=true&width=520&height=618&templateId=" + this.TemplateID);
  }
  // Load Specifications link
  if (this.LanguageID != 2) {
    setTimeout(this.InstanceID + '.checkGarmentSpecs(0);', 500);
  }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
