/*** COPYRIGHT 2009  BY CUTSEY BUSINESS SYSTEMS LTD. - ALL RIGHTS RESERVED ***/
/* product.js -- Product Page Javascript                                     */
/*****************************************************************************/
/* C030004 08/27/10 APY- Color rollover description fix.                     */
/* C030003 08/18/10 APY- Correction for AltViews display.                    */
/* C030002 07/22/10 MS - Removed setting selectedSize in displayMultiSizes() */
/* C030001 07/05/10 JZ - Small display mods.                                 */
/* C030000 05/29/10 APY- Multi Product / ensemble mods.                      */
/*****************************************************************************/
/* C020100 04/29/10 APY- Add PreSell Display.                                */
/* C020002 04/19/10 APY- Remove hostDomain from AJAX call.                   */
/* C020001 04/16/2010 APY - Correction for OOS msg in non multi size display.*/
/* C020000 04/13/2010 PMS - Re-merging back some changes from cam-web-js     */
/*                        - corrected paramter problem not showing OOSMsg    */
/* C010100 06/23/09 PMS-Added update price on mouseover for swatch           */
/*****************************************************************************/
/* 040002 03/01/10 JZ - Site option for defaulting selection of first color. */
/* 040001 02/22/10 JD2- Don't redisplay comparables here.                    */
/*                    - Updated goStyle to just call golink for short urls.  */
/* 040000 02/10/10 JD2- Merged changes from TEA. T010010,T010009,T010008,    */
/*                      T010007.                                             */
/*                    - T010006: Added validation for ttSize fullDesc/desc.  */
/*****************************************************************************/
/*T010010 10/06/09 APY- Update avail-sizes display when selecting color.     */
/*T010009 07/30/09 JD2- PERM - Unforce disclaimer display for all sales.     */
/*                      Fixed in super-get-price.                            */
/*T010008 07/01/09 APY- TEMP - Force disclaimer display for all sales untill */
/*                      disclaimer is fixed in super-get-price.              */
/*T010007 04/06/09 JZ - Tooltip for selecting size and scroll to top when    */
/*                      something is added to the bag.                       */
/*T010006 03/11/09 APY- Styling changes.                                     */
/*****************************************************************************/
/* 030205 02/02/10 APY- Add logic to set color from cookie or hash.          */
/* 030204 01/28/10 APY- Fix for when vMaxUnits is 0 / not set.               */
/* 030203 01/22/10 JD2- Updated flashembed for transparency.                 */
/* 030202 01/22/10 JD2- Update hideVideo to stop the video when playing.     */
/* 030201 01/10/10 JD2- Added showVideo and hideVideo functions.             */
/* 030200 01/17/10 JD2- Added product review functions.                      */
/* 030101 01/07/10 APY- Add max qty limit checks.                            */
/* 030100 12/21/09 JB - Changes to stock checking (E020000).                 */
/* 030000 12/17/09 JD2- Template changes. Build comparables on the server.   */
/*****************************************************************************/
/* 020000 11/16/09 APY- MagicZoom upgrade, add start/stop and alt image zoom.*/
/*****************************************************************************/
/* 010103 09/22/09 SB - Delete a stray line from last check-in.              */
/* 010102 09/22/09 SB - Allow setColor back to style (no-color) default.     */
/* 010101 05/15/09 JD2- Use ttItem.order-limit.                              */
/* 010100 05/01/09 JZ - Static catalog mods.                                 */
/* 010010 04/07/09 JB - Use new enviro vars, new swatch error type.          */
/*        04/14/09 APY- Fix pricing display on comparables.                  */
/* 010009 04/03/09 JB - Change "hide" to "swatch" for image replacement.     */
/* 010008 04/02/09 JB - Added conditions for product mode.                   */
/* 010007 03/30/09 JD2- Added default price.                                 */
/* 010006 03/17/09 APY- If only a single size select by default.             */
/* 010005 03/17/09 APY- Reduce avail qty when successfully adding to cart.   */
/* 010004 02/26/09 SB - Add color name under swatch display grid.            */
/* 010003 02/09/08 APY- Updated default multi dim size when on 1 detail rec. */
/* 010002 12/30/08 APY- Corrected swatchHex, add altView update Comparables  */
/* 010001 12/16/08 APY- Add Multi-view, nocache, use hostURL and appURL      */
/*                    - Add alternate comparables display location           */
/* 010000 12/03/08 APY- Created.                                             */
/*****************************************************************************/
/****** Globals JS Vars Defined in product.w ******
var allStylesObj = new Object();
var styleObj     = new Object();
var vLockedImg = "";
var vDefaultWhse  = "";
var vComparableDir = "";
var vSelectedProd = "";
var vSelectedSize  = "";
var vSelectedColor = "";
var vSelectedSizeDesc  = "";
var vSelectedColorDesc = "";
var vSelectedPrice = "";
var vSelectedMultiSize = new Array();
var vRegPriceLabel  = "";
var vRegOnSaleLabel = "";
var vIsRetail = true/false;
var vDispColorDesc = true/false;
var vBrowseParam = ""
var vSponsorCode = ""
var vProdType = "s" or "i"
var vOrderLimit = 0
var vOrderLimitMsg = ""
var vTotalOrderQty = 0
var vPreSellCopy = "" - marketing copy for preSell items             C020100
var vSelectFirstColor = get-option(v-select-first-color) - yes/no        040002
** - hostDomain and appPath js vars used from header **              010010
******************************************/
var vStyleList = new Array();
var colorHash = {}; /* C010100 */
var zoomObj;
var vImgHtml = "";                                                 /* 030200 */
var vVideoEmbed = "";                                              /* 030202 */
var vToday = new Date();                                           /* C020100 */
//========--------   Load / Display   --------========\\
function loadStyle(vStyle,vSponsor){
 var vFoundStyle = false;
 zoomObj = document.getElementById('zoom1');
 $.each(vStyleList,function(j){
   if(vStyleList[j] != null && vStyleList[j].styleCode == vStyle &&
      vStyleList[j].styleColor && vStyleList[j].styleColor[0] != null &&
      vStyleList[j].styleSize  && vStyleList[j].styleSize[0] != null)
   { styleObj = vStyleList[j]; vFoundStyle = true; }
 });
 if(vFoundStyle){
  displayStyle();

  if (vSelectFirstColor)                                           /* 040002 */
   setColor(vSelectedColor,"","");                                 /* 040002 */
 }
 else{
  var vCurrTime = new Date();
  var vCurrSecs  = (((vCurrTime.getHours() * 60) + vCurrTime.getMinutes()) * 60) + vCurrTime.getSeconds();
  var vNoCache = "&nocache=" + vCurrSecs;
  var vTmpObj;
  $.ajax({
    type: "GET",
    url: appPath + "/olc/get-style.w?style=" + vStyle + "&frames=no&target=main&sponsor=" + vSponsor + vNoCache,  /* 010010 */ /* 020002 */
    dataType: "xml",
    complete: function(data) {
       allStylesObj = $.xmlToJSON(data.responseXML); // Save XML in JSON
       if(typeof(allStylesObj.ttStyle) == "undefined" ){document.location.replace("/404.html");} /* C030000 */
       //Return a single style Object
       $.each(allStylesObj.ttStyle,function(i){
          vTmpObj = prodInit();  /* C030000 */ //Create Closure
          vTmpObj.load(allStylesObj.ttStyle[i]);
          $("#" + vTmpObj.styleCode).data("product",vTmpObj);
          allStylesObj.ttStyle[i] = vTmpObj;  /* C030000 */
          $("#" + vTmpObj.styleCode).data("product").displayStyle();
          vTmpObj = {};
       });
    }
  });
 }
}

function switchComp(vType,curObj){
 $(".compTypeContainerH").hide();
 $(".compSelected").removeClass("compSelected");
 $(curObj).addClass("compSelected");
 vType = "#" + vType;
 $(vType).fadeIn(250);
}

function goStyle(vStyleCode,vStyleColor){
   golink("b2c/product.w?product=" + vStyleCode + "&color=" + vStyleColor + vBrowseParam,"main"); /* 040001 */
}

/****** Retail Add to Cart ******/
function retailAddToCart(vProduct,vColor,vSize,vOrderType){
  var vOrderQty = $("#qty" + vProduct).attr("value"); /* C030000 */
  if(vProdType=="S")  /* 010008 */
  {
   if(vColor == "" || vColor == "none" || vColor == null){
     $(".cartError").html("Please choose a color to continue.");
     return;  }
   if(vSize == "" || vSize == "none" || vSize == null) {
     $(".cartError").html("Please choose a size to continue.");
     return;  }
  }
  if (vOrderQty == "" ) {
    $(".cartError").html("Please enter a quantity before adding item(s) to shopping bag.");
    return;  }
  if (isNumeric(vOrderQty) == false) {
    $(".cartError").html("Please enter a numeric quantity before adding item(s) to shopping bag.");
    $("#qty" + vProduct).attr("value","").focus(); /* C030000 */
    return;  }
  if (vOrderQty <= 0)  {
    $(".cartError").html("Please enter a quantity before adding item(s) to shopping bag.");
    return;  }
  /******v 010101 v******/
  if (vOrderLimit > 1 && (vTotalOrderQty + parseFloat(vOrderQty))  > vOrderLimit) {
     if (vOrderLimitMsg.indexOf("<qty>") != -1)
        vOrderLimitMsg = vOrderLimitMsg.replace("<qty>",vOrderLimit);
     alert(vOrderLimitMsg);
     return;
  }
  /******^ 010101 ^******/
  var invAvail=0;  /* 010008 */
  if(vProdType=="S") invAvail = parseInt(checkStock(vColor,vSize));  /* 010008 */
  if(vProdType=="I") invAvail = parseInt(checkStockItem());
  /***vv 030101 vv***/
  if (vMaxUnits > 0 && vOrderQty > vMaxUnits) /* 030204 */
  {
    alert("The maximum number of units that may be purchased at one time is " + vMaxUnits.toString() + ".  Please contact our customer service department to order more than " + vMaxUnits.toString() + ".");
    invAvail = vMaxUnits;
    $("#qty" + vProduct).attr("value",invAvail).focus(); /* C030000 */
    return;
  }
  /***^^ 030101 ^^***/
  if(invAvail < vOrderQty)  {
    if (invAvail <= 0)
     $(".cartError").html("The selected item is currently out of stock.");
    else{
     var alertMsg = "You have ordered " + vOrderQty + " however only ";
     if (invAvail == 1)
       alertMsg += "1 is available.";
     else
       alertMsg += invAvail + " are available.";
     alert(alertMsg);
    }
    if (invAvail <= 0 )
       invAvail = 1;
    $("#qty" + vProduct).attr("value",invAvail).focus(); /* C030000 */
    return;
  }
  addToCart(vProduct,vColor,vSize,vOrderQty,vOrderType);
  document.body.scrollTop = 0;                                     /* T010007 */
  if(vProdType=="S") setStock(vColor,vSize,vOrderQty);  /* 010008 */
  if(vProdType=="I") setStockItem(vOrderQty);  /* 010008 */
  vTotalOrderQty += + parseFloat(vOrderQty); /* 010101 */
}
/*===---- Retail Functions ----===*/
function bookmarkMe(){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(location.href,document.title);
  }
  else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(document.title,location.href,"");
  }
  else {
   if(agt.indexOf("opera")!= -1)
    alert("Press CTRL-T to bookmark this page.");
   else
    alert("Press CTRL-D to bookmark this page.");
  }
}

function openBlogText(vDescription,vImgPth,vFullDesc){
 if (styleObj){
   if (styleObj.description)
     vDescription = styleObj.description;
   if (styleObj.fullDesc != "" && styleObj.fullDesc != null)
     vFullDesc = styleObj.fullDesc;
   if (styleObj.imageTh != "" && styleObj.imageTh != null)
     vImgPth = styleObj.imageTh;
 }
 var vBlogHTML = "<table cellspacing='0' cellpadding='0' border='0' class='blogTable'>" +
                 "<tr><td colspan='2' style='font-weight:bold;font-size:12pt;'>" + document.title +
                 "</td></tr><tr><td rowspan='2'><img src='" + vImgPth + "' alt=''></td>" +
                 "<td style='text-align:center;vertical-align:top;height:25px;'><a style='font-weight:bold;font-size:11pt;' href='" + appPath + "/site.w?location=b2c/product.w&product=" + vSelectedProd +   /* 010010 */
                 "&frames=no&target=main&sponsor=" + vSponsorCode + "'>" + vDescription + "</a>" +
                 "</td><tr><td style='vertical-align:top;'>" + vFullDesc + "</td></tr></table>";
 vBlogHTML = "<div style='width:400px;text-align:center;margin:none;pading:none;'><table cellspacing='0' cellpadding='0' border='0' style='width:400px'><tr><td class='blogInstructions' style='text-align:center;'>Copy and paste the HTML text below to share this product on your blog or online profile.</td></tr></table>" + vBlogHTML + "<br/> <textarea>" + vBlogHTML + "</textarea></div>";
 if(!document.getElementById("blogPost")){
   $("body").append("<div id='blogPost' title='Blog HTML' style='width:400px;' />");
   $("#blogPost").html(vBlogHTML);
   $("#blogPost").dialog({width:450,height:475,resizable:false} );
 }
 else
   $("#blogPost").dialog("open");
}

/***vv C020100 vv***/
//Date Parsing Functions
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x){return(x<0||x>9?"":"0")+x}
function isDate(val,format){var date=getDateFromFormat(val,format);if(date==0){return false;}return true;}
function compareDates(date1,dateformat1,date2,dateformat2){var d1=getDateFromFormat(date1,dateformat1);var d2=getDateFromFormat(date2,dateformat2);if(d1==0 || d2==0){return -1;}else if(d1 > d2){return 1;}return 0;}
function formatDate(date,format){format=format+"";var result="";var i_format=0;var c="";var token="";var y=date.getYear()+"";var M=date.getMonth()+1;var d=date.getDate();var E=date.getDay();var H=date.getHours();var m=date.getMinutes();var s=date.getSeconds();var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;var value=new Object();if(y.length < 4){y=""+(y-0+1900);}value["y"]=""+y;value["yyyy"]=y;value["yy"]=y.substring(2,4);value["M"]=M;value["MM"]=LZ(M);value["MMM"]=MONTH_NAMES[M-1];
  value["NNN"]=MONTH_NAMES[M+11];value["d"]=d;value["dd"]=LZ(d);value["E"]=DAY_NAMES[E+7];value["EE"]=DAY_NAMES[E];value["H"]=H;value["HH"]=LZ(H);if(H==0){value["h"]=12;}else if(H>12){value["h"]=H-12;}else{value["h"]=H;}value["hh"]=LZ(value["h"]);if(H>11){value["K"]=H-12;}else{value["K"]=H;}value["k"]=H+1;value["KK"]=LZ(value["K"]);value["kk"]=LZ(value["k"]);if(H > 11){value["a"]="PM";}else{value["a"]="AM";}value["m"]=m;value["mm"]=LZ(m);value["s"]=s;value["ss"]=LZ(s);
  while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(value[token] != null){result=result + value[token];}else{result=result + token;}}return result;}
function _isInteger(val){var digits="1234567890";for(var i=0;i < val.length;i++){if(digits.indexOf(val.charAt(i))==-1){return false;}}return true;}
function _getInt(str,i,minlength,maxlength){for(var x=maxlength;x>=minlength;x--){var token=str.substring(i,i+x);if(token.length < minlength){return null;}if(_isInteger(token)){return token;}}return null;}
function getDateFromFormat(val,format){val=val+"";format=format+"";var i_val=0;var i_format=0;var c="";var token="";var token2="";var x,y;var now=new Date();var year=now.getYear();var month=now.getMonth()+1;var date=1;var hh=now.getHours();var mm=now.getMinutes();var ss=now.getSeconds();var ampm="";while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}
  if(token=="yyyy" || token=="yy" || token=="y"){if(token=="yyyy"){x=4;y=4;}if(token=="yy"){x=2;y=2;}if(token=="y"){x=2;y=4;}year=_getInt(val,i_val,x,y);if(year==null){return 0;}i_val += year.length;if(year.length==2){if(year > 70){year=1900+(year-0);}else{year=2000+(year-0);}}}else if(token=="MMM"||token=="NNN"){month=0;for(var i=0;i<MONTH_NAMES.length;i++){var month_name=MONTH_NAMES[i];if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase())
  {if(token=="MMM"||(token=="NNN"&&i>11)){month=i+1;if(month>12){month -= 12;}i_val += month_name.length;break;}}}if((month < 1)||(month>12)){return 0;}}else if(token=="EE"||token=="E"){for(var i=0;i<DAY_NAMES.length;i++){var day_name=DAY_NAMES[i];if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val += day_name.length;break;}}}else if(token=="MM"||token=="M"){month=_getInt(val,i_val,token.length,2);
  if(month==null||(month<1)||(month>12)){return 0;}i_val+=month.length;}else if(token=="dd"||token=="d"){date=_getInt(val,i_val,token.length,2);if(date==null||(date<1)||(date>31)){return 0;}i_val+=date.length;}else if(token=="hh"||token=="h"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>12)){return 0;}i_val+=hh.length;}else if(token=="HH"||token=="H"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>23))
  {return 0;}i_val+=hh.length;}else if(token=="KK"||token=="K"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>11)){return 0;}i_val+=hh.length;}else if(token=="kk"||token=="k"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>24)){return 0;}i_val+=hh.length;hh--;}else if(token=="mm"||token=="m"){mm=_getInt(val,i_val,token.length,2);if(mm==null||(mm<0)||(mm>59)){return 0;}i_val+=mm.length;}else if(token=="ss"||token=="s"){ss=_getInt(val,i_val,token.length,2);
  if(ss==null||(ss<0)||(ss>59)){return 0;}i_val+=ss.length;}else if(token=="a"){if(val.substring(i_val,i_val+2).toLowerCase()=="am"){ampm="AM";}else if(val.substring(i_val,i_val+2).toLowerCase()=="pm"){ampm="PM";}else{return 0;}i_val+=2;}else{if(val.substring(i_val,i_val+token.length)!=token){return 0;}else{i_val+=token.length;}}}if(i_val != val.length){return 0;}if(month==2){if( ((year%4==0)&&(year%100 != 0) ) ||(year%400==0) ){if(date > 29){return 0;}}else{if(date > 28){return 0;}}}
  if((month==4)||(month==6)||(month==9)||(month==11)){if(date > 30){return 0;}}if(hh<12 && ampm=="PM"){hh=hh-0+12;}else if(hh>11 && ampm=="AM"){hh-=12;}var newdate=new Date(year,month-1,date,hh,mm,ss);return newdate.getTime();}
function parseDate(val){var preferEuro=(arguments.length==2)?arguments[1]:false;generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');var d=null;for(var i=0;i<checkList.length;i++)
  {var l=window[checkList[i]];for(var j=0;j<l.length;j++){d=getDateFromFormat(val,l[j]);if(d!=0){return new Date(d);}}}return null;}
/***^^ C020100 ^^***/
/*********vv C030000 vv*********/
var prodInit = function(){
  //Private Attributes
  var selectedColor='';
  var selectedSize='';
  var selectedMultiSize=[];
  var selectedSizeDesc='';
  var selectedColorDesc = '';
  var selectedPrice = '';
  var lockedImg = '';
  var imgHtml = '';
  var colorHash = {};

  //Future use - all options should be in a single object with defaults
  var opts = { isRetail: true,
               prodType: 's',
               orderLimit: -1,
               selectFirstColor: true };

  //Default ttStyle Object
  var ttStyle = {ttColor: [],
                 ttSize: [],
                 ttSizeScale: [{ ttSizeScaleValue : [] }],
                 ttItem: [],
                 ttAltView: [],
                 ttCompType: [{ ttCompDetail : [] }]
  };


  //Private Functions
  function checkItem(vColorCode,vSizeCode){
    var vFound = false;
    for (k=0;k<ttStyle.ttItem.length;k++){
      if(ttStyle.ttItem[k].colorCode == vColorCode && ttStyle.ttItem[k].sizeCode == vSizeCode)
      { vFound = true; k = ttStyle.ttItem.length; }
    }
    return vFound;
  }
  //---------------------------------------------------------------------------
  function multiSizeCheckItem(vIndex,vDimValue){
    var vFound = false;
    var vTempSize = "";
    var vSize     = "";
    if(selectedColor == ""){ return true; }

    $.each(selectedMultiSize,function(k){
       if (k != vIndex)
          vTempSize += selectedMultiSize[k];
       if (k == vIndex)
          vSize += vDimValue;
       else
          vSize += selectedMultiSize[k];
    });
    if (vTempSize == ""){ return true; }
    return checkItem(selectedColor,vSize);
  }
  //---------------------------------------------------------------------------
  function priceColor(pColorCode){
    var newPrice = "";
    if (typeof(colorHash[pColorCode])!="number") return;
    if(ttStyle.ttColor[colorHash[pColorCode]].salePrice <= 0 ){
        $(".salePriceDiv:first",$("#" + ttStyle.styleCode)).hide();
        $(".regPriceStrike:first",$("#" + ttStyle.styleCode)).addClass("regPrice");
        $(".regPriceStrike:first",$("#" + ttStyle.styleCode)).removeClass("regPriceStrike");
        newPrice = parseFloat(ttStyle.ttColor[colorHash[pColorCode]].regPrice);
        $(".regPrice:first",$("#" + ttStyle.styleCode)).html("$" + newPrice.toFixed(2));
        $(".regPriceLabel:first",$("#" + ttStyle.styleCode)).html(vRegPriceLabel);
        selectedPrice = newPrice.toFixed(2);
    }
    else{
        newPrice = parseFloat(ttStyle.ttColor[colorHash[pColorCode]].regPrice);
        $(".regPriceLabel:first",$("#" + ttStyle.styleCode)).html(vRegOnSaleLabel);
        $(".regPrice:first",$("#" + ttStyle.styleCode)).html("$" + newPrice.toFixed(2));
        $(".regPrice:first",$("#" + ttStyle.styleCode)).addClass("regPriceStrike");
        $(".regPrice:first",$("#" + ttStyle.styleCode)).removeClass("regPrice");
        newPrice = parseFloat(ttStyle.ttColor[colorHash[pColorCode]].salePrice);
        selectedPrice = newPrice.toFixed(2);
        $(".salePrice:first",$("#" + ttStyle.styleCode)).text("$" + newPrice.toFixed(2));
        $(".salePriceDiv:first",$("#" + ttStyle.styleCode)).show();
    }
    return;
  }
  //---------------------------------------------------------------------------
  function priceItem(vColorCode,vSizeCode,vItemNumber){
    var newPrice = "";
    $.each(ttStyle.ttItem,function(k){
      if((ttStyle.ttItem[k].colorCode == vColorCode && ttStyle.ttItem[k].sizeCode == vSizeCode) || vItemNumber == ttStyle.ttItem[k].itemNumber){
        if(ttStyle.ttItem[k].salePrice <= 0 ){

          $(".disclaimer:first",$("#" + ttStyle.styleCode)).hide();
          $(".salePriceDiv:first",$("#" + ttStyle.styleCode)).hide();
          $(".regPriceStrike:first",$("#" + ttStyle.styleCode)).addClass("regPrice");
          $(".regPriceStrike:first",$("#" + ttStyle.styleCode)).removeClass("regPriceStrike");
          newPrice = parseFloat(ttStyle.ttItem[k].regPrice);
          $(".regPrice:first",$("#" + ttStyle.styleCode)).html("$" + newPrice.toFixed(2));
          $(".regPriceLabel:first",$("#" + ttStyle.styleCode)).html(vRegPriceLabel);
          selectedPrice = newPrice.toFixed(2);
        }
        else{
          newPrice = parseFloat(ttStyle.ttItem[k].regPrice);
          $(".regPriceLabel:first",$("#" + ttStyle.styleCode)).html(vRegOnSaleLabel);
          $(".regPrice:first",$("#" + ttStyle.styleCode)).html("$" + newPrice.toFixed(2));
          $(".regPrice:first",$("#" + ttStyle.styleCode)).addClass("regPriceStrike");
          $(".regPrice:first",$("#" + ttStyle.styleCode)).removeClass("regPrice");
          newPrice = parseFloat(ttStyle.ttItem[k].salePrice);
          selectedPrice = newPrice.toFixed(2);
          $(".salePrice:first",$("#" + ttStyle.styleCode)).text("$" + newPrice.toFixed(2));
          $(".salePriceDiv:first",$("#" + ttStyle.styleCode)).show();
          if(ttStyle.ttItem[k].disclaimer == "true")
           $(".disclaimer:first",$("#" + ttStyle.styleCode)).show();
          else
           $(".disclaimer:first",$("#" + ttStyle.styleCode)).hide();

        }
        return;
      }
    });
  }
  //---------------------------------------------------------------------------
  function multiSizeCheckPreSell(vIndex,vDimValue){
    var vTempSize = "";
    var vSize     = "";

    vStreetDate = parseDate(ttStyle.streetDate);
    if(ttStyle.preSell && vStreetDate > vToday){
       return true;
    }

    if(selectedColor == "") return false;

    $.each(selectedMultiSize,function(k){
       if(k != vIndex) vTempSize += selectedMultiSize[k];
       if(k == vIndex) vSize += vDimValue;
       else vSize += selectedMultiSize[k];
    });
    if (vTempSize == ""){ return false; }

    var vTmpItem = $(ttStyle.ttItem).filter(function(){
       if(this.colorCode==selectedColor&&this.sizeCode==vSize)
         return true;
    });
    if(vTmpItem.length==1){
      vStreetDate = parseDate(vTmpItem[0].streetDate);
      if(vTmpItem[0].preSell && vStreetDate > vToday )
       return true;
    }
    else
     return false;
  }
  //---------------------------------------------------------------------------
  function checkPreSell(vColorCode,vSizeCode){
    var vPreSell = false;

    if( (vColorCode==""||vColorCode==null||typeof(vColorCode)=="undefined") &&
        (vSizeCode==""||vSizeCode==null||typeof(vSizeCode)=="undefined") )
    {
      //Style
      vStreetDate = parseDate(ttStyle.streetDate);
      if(ttStyle.preSell && vStreetDate > vToday){
        vPreSell = true;
        setPreSell(ttStyle.preSellDesc,ttStyle.streetDate);
      }
      else
        clearPreSell();
    }
    else if(vSizeCode==""||vSizeCode==null||typeof(vSizeCode)=="undefined"){
      //Color
      $.each(ttStyle.ttColor,function(k){
        if(ttStyle.ttColor[k].colorCode == vColorCode && ttStyle.ttColor[k].sizeCode == vSizeCode){
          vStreetDate = parseDate(this.streetDate);
          if(this.preSell && vStreetDate > vToday){
            vPreSell = true;
            setPreSell(this.preSellDesc,this.streetDate);
          }
          else
            clearPreSell();
          return;
        }
      });
    }
    else{
      //Item
      $.each(ttStyle.ttItem,function(k){
        if(ttStyle.ttItem[k].colorCode == vColorCode && ttStyle.ttItem[k].sizeCode == vSizeCode){
          vStreetDate = parseDate(this.streetDate);
          if(this.preSell && vStreetDate > vToday){
            vPreSell = true;
            setPreSell(this.preSellDesc,this.streetDate);
          }
          else
            clearPreSell();
          return;
        }
      });
    }
    return vPreSell;
  }
  //---------------------------------------------------------------------------
  function setPreSell(vPreSellDesc,vStreetDate){
    vStreetDate = formatDate(parseDate(vStreetDate),"MM/dd/yyyy");
    $(".presellDesc:first",$("#" + ttStyle.styleCode)).html(vPreSellDesc).slideDown();
    $(".streetDate:first",$("#" + ttStyle.styleCode)).html(vStreetDate).slideDown();
    $(".preSellCopy:first",$("#" + ttStyle.styleCode)).html(vPreSellCopy).slideDown();
  }
  //---------------------------------------------------------------------------
  function clearPreSell(){
    $(".presellDesc:first",$("#" + ttStyle.styleCode)).slideUp();
    $(".streetDate:first",$("#" + ttStyle.styleCode)).slideUp();
    $(".preSellCopy:first",$("#" + ttStyle.styleCode)).slideUp();
  }
  //---------------------------------------------------------------------------
  function checkStock(vColorCode,vSizeCode,vWhse){
    var vAvailQty = -1;
    $.each(ttStyle.ttItem,function(i){
      if(ttStyle.ttItem[i].colorCode == vColorCode && ttStyle.ttItem[i].sizeCode == vSizeCode) {
        if (ttStyle.ttItem[i].availQty == null)
          vAvailQty = -1;
        else
          vAvailQty = ttStyle.ttItem[i].availQty;
        return; // returns from $.each function
      }
    });
    return vAvailQty;
  }
  //---------------------------------------------------------------------------
  function checkStockItem()
  {
   var vAvailQty = 0;
    $.each(ttStyle.ttItem,function(i)
    {
        if (ttStyle.ttItem[i].availQty == null)
          vAvailQty = 1;
        else
          vAvailQty = ttStyle.ttItem[i].availQty;
        return; // returns from $.each function
    });
    return vAvailQty;
  }
  //---------------------------------------------------------------------------
  function setStock(vColorCode,vSizeCode,vQty){
    var vAvailQty = 0;
    $.each(ttStyle.ttItem,function(i){
      if(ttStyle.ttItem[i].colorCode == vColorCode && ttStyle.ttItem[i].sizeCode == vSizeCode) {
        ttStyle.ttItem[i].availQty -= vQty;
        return; // returns from $.each function
      }
    });
  }
  //---------------------------------------------------------------------------
  function setStockItem(vQty){
    var vAvailQty = 0;
    $.each(ttStyle.ttItem,function(i){
        ttStyle.ttItem[i].availQty -= vQty;
        return; // returns from $.each function
    });
  }
  //---------------------------------------------------------------------------
  function multiSizeCheckStock(vIndex,vDimValue,vWhse){
    var vAvailQty = 0;
    var vTempSize = "";
    var vSize     = "";

    //return true if no other size dimension is selected
    $.each(selectedMultiSize,function(k){
       if (k != vIndex)
          vTempSize += selectedMultiSize[k];
       if (k == vIndex)
          vSize += vDimValue;
       else
          vSize += selectedMultiSize[k];
    });
    if (vTempSize == "")
    { return 1; }

    $.each(ttStyle.ttItem,function(i){
      if(ttStyle.ttItem[i].colorCode == selectedColor && ttStyle.ttItem[i].sizeCode == vSize) {
        if (ttStyle.ttItem[i].availQty == null)
          vAvailQty = 1;
        else
          vAvailQty = ttStyle.ttItem[i].availQty;
        return; // returns from $.each function
      }
    });
    return vAvailQty;
  }
  //---------------------------------------------------------------------------
  function checkItem(vColorCode,vSizeCode){
    var vFound = false;
    $.each(ttStyle.ttItem,function(k){
      if(ttStyle.ttItem[k].colorCode == vColorCode && ttStyle.ttItem[k].sizeCode == vSizeCode)
      { vFound = true; return; }
    });
    return vFound;
  }
  //---------------------------------------------------------------------------
  function multiSizeCheckItem(vIndex,vDimValue){
    var vFound = false;
    var vTempSize = "";
    var vSize     = "";
    //return true if no color or other size dimension is selected
    if(selectedColor == "")
    { return true; }
    $.each(selectedMultiSize,function(k){
       if (k != vIndex)
          vTempSize += selectedMultiSize[k];
       if (k == vIndex)
          vSize += vDimValue;
       else
          vSize += selectedMultiSize[k];
    });
    if (vTempSize == "")
    { return true; }
    return checkItem(selectedColor,vSize);
  }
  //---------------------------------------------------------------------------
  function displayFeatIcons(){
    if(ttStyle.ttFeatIcon){
      $.each(ttStyle.ttFeatIcon,function(i){
       $(".prodIcons:first",$("#" + ttStyle.styleCode)).append("<img src='" + ttStyle.ttFeatIcon[i].icon + "' class='featureIcon' alt='" + ttStyle.ttFeatIcon[i].description + "' />");
      });
    }
  }
  //---------------------------------------------------------------------------
  function showAltViews(vColorCode){
   //More work required to support multiple product image displays per page
   var vAltViewHTML = "";
   var vFound = false; /* C030003 */
   var vAlt;
   var zoomObj = document.getElementById('zoom1');
   if(document.getElementById("altViews")){
     $("#altViews").html('');
     $.each(ttStyle.ttAltView,function(i){
       if(ttStyle.ttAltView[i].colorCode == vColorCode){
          vAlt = $($(document.createElement("div")));
          vAlt.attr("id","altView" + ttStyle.ttAltView[i].altId)
              .attr("colorCode",vColorCode)
              .attr("rel","zoom-id:zoom1")
              .attr("rev",ttStyle.ttAltView[i].imageLg)
              .attr("href",ttStyle.ttAltView[i].imageZm)
              .mouseover(function(){ swapImg(ttStyle.ttAltView[i].imageLg,true); })
              .mouseout(function(){ restoreImg(); })
              .click(function(){
                  lockedImg=ttStyle.ttAltView[i].imageLg;
                  if(ttStyle.ttAltView[i].imageZm != ""){
                    MagicZoom.stop(zoomObj);
                    MagicZoom.update(zoomObj,ttStyle.ttAltView[i].imageZm,ttStyle.ttAltView[i].imageLg);
                    MagicZoom.start(zoomObj);
                  }
                  else{
                    MagicZoom.stop(zoomObj);
                  }
               })
              .html("<img src='" + ttStyle.ttAltView[i].imageSm + "' alt='' />");

          $("#altViews").append(vAlt);
          vFound = true; /* C030003 */
       }
     });
     if(!vFound && vColorCode != ''){ showAltViews(''); return; } /* C030003 */
     if ($(".altViewSide"))
       $(".prodDesc").width($(".prodDesc").width() - $(".altViewSide").outerWidth() );
     $("#altViews").css("display","block");
   }
  }
  //---------------------------------------------------------------------------
  function switchAltViews(vColorCode){
   //More work required to support multiple product image displays per page
   var vAltViewHTML = "";
   var vAltViewId;
   var zoomObj = document.getElementById('zoom1');
   if(!document.getElementById("altViews")){ return; }
   $("#altViews").html('');
   $.each(ttStyle.ttAltView,function(i){
     if(ttStyle.ttAltView[i].colorCode == vColorCode){
        vAlt = $($(document.createElement("div")));
        vAlt.attr("id","altView" + ttStyle.ttAltView[i].altId)
            .attr("colorCode",vColorCode)
            .attr("rel","zoom-id:zoom1")
            .attr("rev",ttStyle.ttAltView[i].imageLg)
            .attr("href",ttStyle.ttAltView[i].imageZm)
            .mouseover(function(){ swapImg(ttStyle.ttAltView[i].imageLg,true); })
            .mouseout(function(){ restoreImg(); })
            .click(function(){
                lockedImg=ttStyle.ttAltView[i].imageLg;
                if(ttStyle.ttAltView[i].imageZm != ""){
                  MagicZoom.stop(zoomObj);
                  MagicZoom.update(zoomObj,ttStyle.ttAltView[i].imageZm,ttStyle.ttAltView[i].imageLg);
                  MagicZoom.start(zoomObj);
                }
                else{
                  MagicZoom.stop(zoomObj);
                }
             })
            .html("<img src='" + ttStyle.ttAltView[i].imageSm + "' alt='' />");

        $("#altViews").append(vAlt);
     }
   });
   //reset all non color specific altViews to defaults
   $.each(ttStyle.ttAltView,function(i){
     if(ttStyle.ttAltView[i].colorCode == "" && !document.getElementById("altView" + ttStyle.ttAltView[i].altId) ){
        vAlt = $($(document.createElement("div")));
        vAlt.attr("id","altView" + ttStyle.ttAltView[i].altId)
            .attr("colorCode",vColorCode)
            .attr("rel","zoom-id:zoom1")
            .attr("rev",ttStyle.ttAltView[i].imageLg)
            .attr("href",ttStyle.ttAltView[i].imageZm)
            .mouseover(function(){ swapImg(ttStyle.ttAltView[i].imageLg,true); })
            .mouseout(function(){ restoreImg(); })
            .click(function(){
                lockedImg=ttStyle.ttAltView[i].imageLg;
                if(ttStyle.ttAltView[i].imageZm != ""){
                  MagicZoom.stop(zoomObj);
                  MagicZoom.update(zoomObj,ttStyle.ttAltView[i].imageZm,ttStyle.ttAltView[i].imageLg);
                  MagicZoom.start(zoomObj);
                }
                else{ MagicZoom.stop(zoomObj); }
             })
            .html("<img src='" + ttStyle.ttAltView[i].imageSm + "' alt='' />");
        $("#altViews").append(vAlt);
     }
   });
  }
  //---------------------------------------------------------------------------
  function showOOSMsg(vColor,vSize,vQty){
    var $OOS = $(".imgMessage:first",$("#" + ttStyle.styleCode));
    if (vQty==-1) return;
    var vPosition   = $(".imgUpper:first",$("#" + ttStyle.styleCode)).position();
    if(vPosition==null){ return; }
    if(vQty==0)
    $(".imgMessageText:first",$("#" + ttStyle.styleCode)).html(vColor + " is currently out of stock in " + vSize);
    else
    if(!vIsRetail)
      $(".imgMessageText:first",$("#" + ttStyle.styleCode)).html(vColor + " currently has " + vQty + " available in " + vSize);

    var vTopOffset  = ( $(".prodImgInner:first",$("#" + ttStyle.styleCode)).outerHeight() - $OOS.outerHeight() - ( $OOS.outerHeight()/2) );
    var vLeftOffset = ( $(".imgUpper:first",$("#" + ttStyle.styleCode)).outerWidth() - $OOS.outerWidth() )/2;

    $OOS.css("top",vPosition.top + vTopOffset);
    $OOS.css("left",vPosition.left + vLeftOffset);
    $OOS.stop().fadeTo(300,0.8);
  }
  //---------------------------------------------------------------------------
  function showMultiSizeOOSMsg(vColor,vIndex,vDimValue){
    var vSize     = "";
    var vSizeDesc = "";
    $.each(selectedMultiSize,function(k){
       if (k == vIndex)
          vSize += vDimValue;
       else
          vSize += selectedMultiSize[k];
    });
    $.each(ttStyle.ttSize,function(i){
       if(ttStyle.ttSize[i].sizeCode == vSize){
          if (ttStyle.ttSize[i].fullDesc != "") vSizeDesc = ttStyle.ttSize[i].fullDesc;
          else vSizeDesc = ttStyle.ttSize[i].description;
          return;
       }
    });
    showOOSMsg(vColor,vSizeDesc,0);
  }
  //---------------------------------------------------------------------------
  function hideOOSMsg(){
    $(".imgMessage:first",$("#" + ttStyle.styleCode)).stop().fadeTo(300,0);
  }
  //---------------------------------------------------------------------------
  function swapImg(vNewImg,vNoLock){
    resetFlash();
    if(vNewImg && vNewImg != "" ){
      if(!vNoLock)
        lockedImg = $(".imageCell:first",$("#" + ttStyle.styleCode)).attr("src");
      $(".imageCell:first",$("#" + ttStyle.styleCode)).attr("src",vNewImg);
    }
  }
  //---------------------------------------------------------------------------
  function restoreImg(){
    if(lockedImg != "" && $(".imageCell:first",$("#" + ttStyle.styleCode)).attr("src") != lockedImg)
    { $(".imageCell:first",$("#" + ttStyle.styleCode)).attr("src",lockedImg); }
  }
  //---------------------------------------------------------------------------
  function productFlash(vFlash) {
    imgHtml = $(".prodImg:first",$("#" + ttStyle.styleCode)).html();
    $(".prodImg:first",$("#" + ttStyle.styleCode)).html("");
    $(".prodImg:first",$("#" + ttStyle.styleCode)).flashembed({
       src: vFlash,
       wmode: "transparent"
    });
  }
  //---------------------------------------------------------------------------
  function resetFlash() {
     if (imgHtml != '') {
        $(".prodImg:first",$("#" + ttStyle.styleCode)).html(imgHtml);
        imgHtml = '';
     }
  }
  //---------------------------------------------------------------------------
  function showVideo(vVideo,vHideSection) {
     if ($("#" + vVideo).html() == "")                               /* 030202 */
        $("#" + vVideo).html(vVideoEmbed);                           /* 030202 */
     $("#" + vVideo).show();
     vVideoEmbed = $("#" + vVideo).html();                           /* 030202 */
     if (vHideSection != null)
        $("#" + vHideSection).hide();
  }
  //---------------------------------------------------------------------------
  function hideVideo(vVideo,vHideSection) {
     $("#" + vVideo).html("");                                       /* 030202 */
     $("#" + vVideo).hide();
     if (vHideSection != null)
        $("#" + vHideSection).show();
  }
  //---------------------------------------------------------------------------
  function clearmessage(){
    $(".cartError:first",$("#" + ttStyle.styleCode)).html("");
  }
  //---------------------------------------------------------------------------
  function enterCheck(event,id)
  {
    if(event.keyCode == 13)
    {
      $(".retailAddToCart:first",$("#" + ttStyle.styleCode)).click();
      return false;
    }
    return true;
  }
  //---------------------------------------------------------------------------
  //===========================================================================
  //Public Functions
  return {
  styleCode: this.styleCode,
  //===========================================================================
  load: function(styleObj){
    $.extend(true,ttStyle,styleObj);
    this.styleCode = ttStyle.styleCode;
    selectedProd = ttStyle.styleCode;
    this.preSell = (this.preSell == "true") ? true : false;
    for (i=0;i<ttStyle.ttColor.length;i++){
      ttStyle.ttColor[i].preSell = (ttStyle.ttColor[i].preSell == "true") ? true : false;
    }
    for (i=0;i<ttStyle.ttItem.length;i++){
      ttStyle.ttItem[i].preSell = (ttStyle.ttItem[i].preSell == "true") ? true : false;
    }
  },
  //===========================================================================
  init: function(initObj){  /* Future use - all options shold be in a single object with defaults */
    $.extend(true,opts,initObj);
  },
  //===========================================================================
  displayStyle: function(){
     var vZoomInit = "";
     ttStyle.hasImage = $(".prodImg:first",$("#" + ttStyle.styleCode) ).length ? true : false;

     if(ttStyle.hasImage){
       if (selectedColor != ""){
         for (i=0;i<ttStyle.ttColor.length;i++){
           if (ttStyle.ttColor[i].colorCode == selectedColor && ttStyle.ttColor[i].imageLg != "" ) {
             $(".imageCell").attr("src",ttStyle.ttColor[i].imageLg);
             lockedImg = ttStyle.ttColor[i].imageLg;
             if(ttStyle.ttColor[i].imageZm != "")
               vZoomInit = ttStyle.ttColor[i].imageZm;
           }
         }
       }
       if (lockedImg == "" || lockedImg == null){
         if (ttStyle.ttColor[0]&&ttStyle.ttColor[0].imageLg != "" && ttStyle.ttColor[0].imageLg != null){
           $(".imageCell").attr("src",ttStyle.ttColor[0].imageLg);
           lockedImg = ttStyle.ttColor[0].imageLg;
           if (ttStyle.ttColor[0].imageZm != "" && ttStyle.ttColor[0].imageZm != null)
             vZoomInit = ttStyle.ttColor[0].imageZm;
         }
         else{
           $(".imageCell").attr("src",this.imageLg);
           lockedImg = this.imageLg;
           if (this.imageZm != "" && this.imageZm != null)
             vZoomInit = this.imageZm;
         }
       }
     } //End hasImage

     $.each(ttStyle.ttColor,function(i){
        colorHash[ this.colorCode ] = i;
        this.regPrice = 0;
        this.salePrice = 0;
     });
     $.each(ttStyle.ttItem,function(i){
        if(ttStyle.ttColor[colorHash[this.colorCode]].regPrice == 0 |
           ttStyle.ttColor[colorHash[this.colorCode]].regPrice > this.regPrice)
           ttStyle.ttColor[colorHash[this.colorCode]].regPrice = this.regPrice;
        if(ttStyle.ttColor[colorHash[this.colorCode]].salePrice == 0 |
           ttStyle.ttColor[colorHash[this.colorCode]].salePrice > this.salePrice)
           ttStyle.ttColor[colorHash[this.colorCode]].salePrice = this.salePrice;
     });

     var hashCheck = getHash();
     var vHasHashColor = false;
     $(hashCheck).each(function(){
       if(this.name=="color" && this.value){
          selectedColor = this.value;
          vHasHashColor = true;
       }
     });
     if (!vHasHashColor){
      var vCookieColor = getCookie("prodColor");
      vCookieColor = vCookieColor.split(",");
      if (vCookieColor.length==2 && vCookieColor[0].toLowerCase() == ttStyle.styleCode)
        selectedColor = vCookieColor[1];
     }
     if (this.imageMill != "" && this.imageMill != null)
       $(".prodMillImg:first",$("#" + ttStyle.styleCode) ).html('<img src="' + this.imageMill + '" alt="">');
     this.displayColors();
     if(ttStyle.ttSizeScale && ttStyle.ttSizeScale.length > 1){
       ttStyle.ttSizeScale.sort(function(a,b){ return a.sortIndex - b.sortIndex }); //Ensure array is Sorted by sortIndex
       for (i=0;i<ttStyle.ttSizeScale.length;i++){
          if(ttStyle.ttSizeScale[i].ttSizeScaleValue.length == 1)
            selectedMultiSize[i] = ttStyle.ttSizeScale[i].ttSizeScaleValue[0].dimValue;
          else
            selectedMultiSize[i] = "";
       }
       this.displayMultiSizes();
     }
     else if(ttStyle.ttSize.length)
       this.displaySizes();
     displayFeatIcons();
     if(ttStyle.hasImage && ttStyle.ttAltView.length)
       showAltViews(selectedColor); /* C030003 */

     if(ttStyle.hasImage && vZoomInit != "" && vZoomInit != null)
        $(".MagicZoomBigImageCont:first > div > img",$("#" + ttStyle.styleCode)).attr("src",vZoomInit);

     if (vShowImgLib)
        showImgLib(selectedProd,selectedColor);

     if(typeof(vDefaultPrice)=="boolean" && vDefaultPrice){
       priceItem("","",ttStyle.ttItem[0].itemNumber);
     }
     else
        priceColor(selectedColor);

     if ( ttStyle.ttItem.length == 1 && selectedProd == ttStyle.ttItem[0].itemNumber  ) {

        if (isNaN(ttStyle.ttItem[0].orderLimit) == false)
           vOrderLimit = parseFloat(ttStyle.ttItem[0].orderLimit);

        if (isNaN(ttStyle.ttItem[0].orderQty) == false)
           vTotalOrderQty = parseFloat(ttStyle.ttItem[0].orderQty);

        if (vOrderLimit == 1) {
           $("#qty" + ttStyle.styleCode).val("1");
           $(".prodQty:first",$("#" + ttStyle.styleCode) ).hide();
           $(".prodOrder:first",$("#" + ttStyle.styleCode) ).show();
        }
        else if (vOrderLimit == -1)
           $(".prodOrder:first",$("#" + ttStyle.styleCode) ).hide();
        else
           $(".prodOrder:first",$("#" + ttStyle.styleCode) ).show();
     }
     else
        $(".prodOrder:first",$("#" + ttStyle.styleCode) ).show();

  }, //End displayStyle
  //===========================================================================
  displayColors: function(){
     var vColorHTML = "";
     var vColorDesc ="";
     var vClass;
     var vStockQty=-1;
     var vSwitchImgLg;
     var vSwitchImgZm;

     var vHexPercent2 = "75,25";
     var vHexPercent3 = "50,25,25";
     var vHexPercent4 = "25,25,25,25";

     if (vSelectFirstColor && selectedColor == "" && ttStyle.ttColor[0])
       this.setColor(ttStyle.ttColor[0].colorCode,"",false);

     for(var i=0; i<ttStyle.ttColor.length; i++){
       //Show all colors if no size is selected otherwise only show available colors
       if(selectedSize == "" || checkItem(ttStyle.ttColor[i].colorCode,selectedSize) ) {

         //If no color Selected blank out selected label
         if(selectedColor=='' && i==0 && document.getElementById("color" + ttStyle.styleCode))
              document.getElementById("color" + ttStyle.styleCode).value = '';

         if(selectedColor==ttStyle.ttColor[i].colorCode) {
           //Set selected Color desciption
           selectedColorDesc = ttStyle.ttColor[i].description;
           if (ttStyle.ttColor[i].fabDesc != "" && ttStyle.ttColor[i].fabDesc != null)
           { selectedColorDesc += " " + ttStyle.ttColor[i].fabDesc; }
           $(".selectedColor:first",$("#" + ttStyle.styleCode)).html(selectedColorDesc);

           vStreetDate = parseDate(ttStyle.ttColor[i].streetDate);
           vStockQty=checkStock(ttStyle.ttColor[i].colorCode,selectedSize,vDefaultWhse)
           if(selectedSize == "" || vStockQty > 0 || vStockQty==-1)
            vClass = "colorOuterSelected";
           else
            vClass = "colorOuterOOSSelected";
           if(ttStyle.ttColor[i].preSell && vStreetDate > vToday ){
             if(selectedSize == "" || vStockQty > 0 || vStockQty==-1)
              vClass = "colorOuterPreSellSelected";
             else
              vClass = "colorOuterPreSellOOSSelected";
           }
           else if(ttStyle.ttColor[i].preSell)
             vClass = "colorOuterSelected";
         } else {
           vStreetDate = parseDate(ttStyle.ttColor[i].streetDate);
           vStockQty=checkStock(ttStyle.ttColor[i].colorCode,selectedSize,vDefaultWhse)
           if(selectedSize == "" || vStockQty > 0 || vStockQty==-1){
             if(ttStyle.ttColor[i].preSell && vStreetDate > vToday )
               vClass = "colorOuterPreSell";
             else
               vClass = "";
           }
           else{
             if(ttStyle.ttColor[i].preSell && vStreetDate > vToday )
               vClass = "colorOuterPreSellOOS";
             else
               vClass = "colorOuterOOS";
           }
         }

         vColorDesc = ttStyle.ttColor[i].description;
         if (ttStyle.ttColor[i].fabDesc != "" && ttStyle.ttColor[i].fabDesc != null)
           { vColorDesc += " " + ttStyle.ttColor[i].fabDesc; }

         if(ttStyle.hasImage){
           if (ttStyle.ttColor[i].imageLg != ""){
              vSwitchImgLg = ttStyle.ttColor[i].imageLg;
              vSwitchImgZm = ttStyle.ttColor[i].imageZm;
           }
           else{
             vSwitchImgLg = ttStyle.imageLg;
             vSwitchImgZm = ttStyle.imageZm;
           }
         }

         vColorHTML += '<a class="colorOuter" ';
         if(ttStyle.hasImage){
            if(vSwitchImgZm!="")
              vColorHTML += 'href="' + vSwitchImgZm + '" ';
            else
              vColorHTML += 'href="#" onclick="return false;" ';
            vColorHTML += 'rel="zoom-id:zoom1;" ' +
                          'rev="' + vSwitchImgLg + '"';
         }
         else
            vColorHTML += 'href="#" onclick="return false;" ';
         vColorHTML += 'colorCode="' + ttStyle.ttColor[i].colorCode + '"' +
                       'colorDesc="' + vColorDesc + '"' +
                       '>';

         if (vDispColorDesc) {
           vColorHTML += '<div class="swatchbox">';
           vColorHTML += '<div class="swatchcenter">';
         }

         vColorHTML += '<div class="colorOuter ' + vClass + '">';

         if (ttStyle.ttColor[i].imageSw == "" || ttStyle.ttColor[i].imageSw == null ){
           if (ttStyle.ttColor[i].hexColor != "" && ttStyle.ttColor[i].hexColor != null && ttStyle.ttColor[i].hexColor.indexOf(",") != -1){ //Check for multiple hex values
             vHexArray = ttStyle.ttColor[i].hexColor.split(",");
             switch(vHexArray.length){
               case 2:
                 vHexPerArray = vHexPercent2.split(",");
                 break;
               case 3:
                 vHexPerArray = vHexPercent3.split(",");
                 break;
               case 4:
                 vHexPerArray = vHexPercent4.split(",");
                 break;
               default:
                 vHexPerArray = vHexPercent2.split(",");
             }
             vColorHTML += '<div class="colorInner">';
             for(var j=0; j<vHexArray.length; j++){
                vColorHTML += '<div style="margin:0px;padding:0px;float:left;height:100%;width:' + vHexPerArray[j] + '%;background-color:#' + vHexArray[j] + ';"></div>';
             }
             vColorHTML += '</div>';
           }
           else
             vColorHTML += '<div class="colorInner" style="background-color:#' + ttStyle.ttColor[i].hexColor + ';"></div>';
         }
         else
           vColorHTML += '<img src="' + ttStyle.ttColor[i].imageSw + '" onerror="top.ImageError(this,\'swatch\')" alt="" class="colorImg"/>';

         if (vDispColorDesc) {
           vColorHTML += '</div>'; // colorOuter
           vColorHTML += '</div>'; // swatchcenter
           vColorHTML += '<span class="swatchboxtxt">' + ttStyle.ttColor[i].description + '</span>';
         }

         vColorHTML += '</div></a>'; // swatchbox || colorOuter
       }
     }
     if(ttStyle.ttColor[0])
       $(".prodColors:first",$("#" + ttStyle.styleCode) ).html(vColorHTML);
  }, //End displayColors
  //===========================================================================
  displaySizes: function(){
    var $sizeHTML;
    var vClass;
    var vStockQty=-1;
    var vSizeDesc="";

    //If only 1 size force to be selected
    if (ttStyle.ttSize.length==1){
      selectedSize = ttStyle.ttSize[0].sizeCode;
      selectedSizeDesc = ttStyle.ttSize[0].description;
      $(".selectedSize:first",$("#" + ttStyle.styleCode)).html(selectedSizeDesc);
    }

    $(".prodSizes:first",$("#" + ttStyle.styleCode)).empty();

    for(var i=0; i<ttStyle.ttSize.length; i++){
      if( checkItem(selectedColor,ttStyle.ttSize[i].sizeCode) )
      {
       var vTmpItem = $(ttStyle.ttItem).filter(function(){
          if(this.colorCode==selectedColor&&this.sizeCode==ttStyle.ttSize[i].sizeCode)
            return true;
       });
       vStockQty=checkStock(selectedColor,ttStyle.ttSize[i].sizeCode,vDefaultWhse);
       if(selectedSize==ttStyle.ttSize[i].sizeCode){
          if(vStockQty==-1 || vStockQty > 0)
           vClass = "sizeOuterSelected";
          else
           vClass = "sizeOuterOOSSelected";
          if(vTmpItem.length==1){
            vStreetDate = parseDate(vTmpItem[0].streetDate);
            if(vTmpItem[0].preSell && vStreetDate > vToday ){
              if(vStockQty==-1 || vStockQty > 0)
               vClass = "sizeOuterPreSellSelected";
              else
               vClass = "sizeOuterPreSellOOSSelected";
            }
          }
        }
        else{
          if(vStockQty==-1 || vStockQty > 0 || selectedColor == "")
           vClass = ""; //Always using sizeOuter for class as needed for 'delegate'
          else
           vClass = "sizeOuterOOS";
          if(vTmpItem.length==1){
            vStreetDate = parseDate(vTmpItem[0].streetDate);
            if(vTmpItem[0].preSell && vStreetDate > vToday ){
              if(vStockQty==-1 || vStockQty > 0)
               vClass = "sizeOuterPreSell";
              else
               vClass = "sizeOuterPreSellOOS";
            }
          }
        }
        if (!vIsRetail) { vClass += " sizeb2b"; }

        if(ttStyle.ttSize[i].fullDesc != "")
          vSizeDesc = ttStyle.ttSize[i].fullDesc;
        else
          vSizeDesc = ttStyle.ttSize[i].description;

        // Using new method to create elements so that 'data' can be attached
        // IE/Opera issue when setting class - requires quotes as it is a reserved keyword
        // Equivilent to '<div class="sizeOuter"><div class="sizeInner">sizeDesc</div></div>' but without 'data' added
        $sizeHTML = $("<div>",{ 'class': "sizeOuter " + vClass,
                                data: { sizeCode: ttStyle.ttSize[i].sizeCode,
                                        sizeDesc: vSizeDesc }
                              }).append( $("<div>",{ 'class': "sizeInner",
                                                     text: ttStyle.ttSize[i].description }) );
        $(".prodSizes:first",$("#" + ttStyle.styleCode)).append( $sizeHTML );

      }
    }
    if(selectedColor == "") this.displayColors();
  }, //End displaySizes
  //===========================================================================
  displayMultiSizes: function(){
    var $sizeHTML;
    var vClass="";
    var vSizeDesc="";
    var vFullSizeCode;
    var vFullSize;
    var $sizeTarget = $(".prodSizes:first",$("#" + ttStyle.styleCode));
    $sizeTarget.empty();
    //$(".sizeHeading:first",$("#" + ttStyle.styleCode)).hide();

    for(var i=0; i<ttStyle.ttSizeScale.length; i++){
       if(ttStyle.ttSizeScale[i].description!="&nbsp;")
         $sizeTarget.append("<div class='sizeHeading" + i + "'>" + ttStyle.ttSizeScale[i].description + "</div><div class='prodSizes'>"); /* C030001 */
       for(var j=0; j<ttStyle.ttSizeScale[i].ttSizeScaleValue.length; j++){
          if(multiSizeCheckItem(i,ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue)){
             if(selectedMultiSize[i]==ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue){
               if(multiSizeCheckStock(i,ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue) > 0){
                 if(multiSizeCheckPreSell(i,ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue))
                   vClass = "sizeOuterPreSellSelected" + i;
                 else
                   vClass = "sizeOuterSelected" + i;
               }
               else{
                 if(multiSizeCheckPreSell(i,ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue))
                   vClass = "sizeOuterPreSellOOSSelected" + i;
                 else
                   vClass = "sizeOuterOOSSelected" + i;
               }
             }
             else{
               if(multiSizeCheckPreSell(i,ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue))
                 vClass = "sizeOuterPreSell" + i;
               else if(multiSizeCheckStock(i,ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue) > 0)
                 vClass = "sizeOuter" + i;
               else
                 vClass = "sizeOuterOOS" + i;
             }

             vFullSize = true;
             vFullSizeCode = "";
             $.each(selectedMultiSize, function(k){
                if(i==k){
                  vFullSizeCode += ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue;
                }
                else{
                  vFullSizeCode += selectedMultiSize[k];
                  if(selectedMultiSize[k] == "")
                    vFullSize = false;
                }
             });

             if(vFullSize){
               /* C030002 - do not set selectedSize here! */
               $.each(ttStyle.ttSize,function(k){
                 if (ttStyle.ttSize[k].sizeCode == vFullSizeCode) { /* C030002 */
                   if (ttStyle.ttSize[k].fullDesc != "")
                     vSizeDesc = ttStyle.ttSize[k].fullDesc;
                   else
                     vSizeDesc = ttStyle.ttSize[k].description;
                 }
               });
             }
             else{ vSizeDesc = ""; }

             // Using new method to create elements so that 'data' can be attached
             // IE/Opera issue when setting class - requires quotes as it is a reserved keyword
             // Equivilent to '<div class="sizeOuter"><div class="sizeInner">sizeDesc</div></div>' but no 'data' added
             $sizeHTML = $("<div>",{ 'class': "multiSizeOuter " + vClass,
                                     data: { dimIndex: i,
                                             dimValue: ttStyle.ttSizeScale[i].ttSizeScaleValue[j].dimValue,
                                             sizeDesc: vSizeDesc }
                                   }).append( $("<div>",{ 'class': "sizeInner",
                                                          text: ttStyle.ttSizeScale[i].ttSizeScaleValue[j].description }) );
             $sizeTarget.append( $sizeHTML );

          }
       }
    }
    if(selectedColor == "") this.displayColors();
  }, //End displayMultiSizes
  //===========================================================================
  setSize: function(vSizeCode,vThis){
    var vStockQty=-1;
    if(vSizeCode=="none" || !vIsRetail ) { return; }
    $(".cartError:first",$("#" + ttStyle.styleCode)).html("");
    selectedSize = vSizeCode;
    if(document.getElementById("size" + this.styleCode))
      document.getElementById("size" + this.styleCode).value = vSizeCode;

    // Set var for context to find only current products sizes
    var $prodSize = $(".prodSizes:first",$("#" + ttStyle.styleCode));
    $(".sizeOuterSelected",$prodSize).attr("class","sizeOuter");
    $(".sizeOuterOOSSelected",$prodSize).attr("class","sizeOuter sizeOuterOOS");
    $(".sizeOuterPreSellSelected",$prodSize).attr("class","sizeOuter sizeOuterPreSell");
    $(".sizeOuterPreSellOOSSelected",$prodSize).attr("class","sizeOuter sizeOuterPreSellOOS");

     vStockQty=checkStock(selectedColor,selectedSize,vDefaultWhse);
     if(vStockQty > 0 || vStockQty==-1){
       if(checkPreSell(selectedColor,selectedSize))
         vClass="sizeOuterPreSellSelected";
       else
         vClass="sizeOuterSelected";
     }
     else{
       if(checkPreSell(selectedColor,selectedSize))
         vClass="sizeOuterPreSellOOSSelected";
       else
         vClass="sizeOuterOOSSelected";
     }

    if(vThis == "")
      $("div[sizeCode='" + vSizeCode + "']",$prodSize).addClass(vClass);
    else
      $(vThis).addClass(vClass);

    $.each(ttStyle.ttSize,function(i){
      if (ttStyle.ttSize[i].sizeCode == vSizeCode) {
        if (ttStyle.ttSize[i].fullDesc != "") selectedSizeDesc = ttStyle.ttSize[i].fullDesc;
        else selectedSizeDesc = ttStyle.ttSize[i].description;
        $(".selectedSize:first",$("#" + ttStyle.styleCode)).html(selectedSizeDesc);
      }
    });

    if (selectedSize != "" && selectedColor != "") {
      if (vTooltipSettings != "") {
         /* Hide the tool tip for selected a size. */
         $("#tip").remove();
         $(".btnShoppingBag:first",$("#" + ttStyle.styleCode)).cluetip({});
         $(".btnWishlist:first",$("#" + ttStyle.styleCode)).cluetip({});
      }
      priceItem(selectedColor,selectedSize);
    }

    this.displayColors();
  }, //End setSize
  //===========================================================================
  setColor: function(vColorCode,vThis,vImgSwitch){
    if(vColorCode=="none" || vColorCode == selectedColor) { return; }
    resetFlash();
    var vStockQty=-1;
    var newLgImg;
    var newZmImg;
    var vColorObj;
    var zoomObj = document.getElementById('zoom1');

    $(".cartError:first",$("#" + ttStyle.styleCode)).html("");
    if(document.getElementById("#imgLibDiv")) $("#imgLibDiv").hide();

    selectedColor = vColorCode;

    if(document.getElementById("color" + this.styleCode))
      document.getElementById("color" + this.styleCode).value = vColorCode;

    $.each(ttStyle.ttColor,function(i){
      if (ttStyle.ttColor[i].colorCode == vColorCode) {
        vColorObj = ttStyle.ttColor[i];
        return;
      }
    });

    selectedColorDesc = '';
    if (vColorObj) {
      selectedColorDesc = vColorObj.description;
      if (vColorObj.fabDesc != '' && vColorObj.fabDesc != null)
        selectedColorDesc += ' ' + vColorObj.fabDesc;
    }
    $(".selectedColor:first",$("#" + ttStyle.styleCode)).html(selectedColorDesc);

    //Only run image logic if primary product
    if(ttStyle.hasImage){
       if(vColorCode == '') {
         newLgImg = ttStyle.imageLg;
         newZmImg = ttStyle.imageZm;
       }

       if (vColorObj.imageLg && vColorObj.imageLg != "" && vColorObj.imageLg != null ){
         newLgImg = vColorObj.imageLg;
         newZmImg = vColorObj.imageZm;
       }else{
         newLgImg = ttStyle.imageLg;
         newZmImg = ttStyle.imageZm;
       }
       $(".prodSizeRange:first",$("#" + ttStyle.styleCode)).html(vColorObj.availSizes);

       if(vImgSwitch)
          swapImg(newLgImg);

       if(newZmImg != "" && newZmImg != null){
         MagicZoom.stop(zoomObj);
         MagicZoom.update(zoomObj,newZmImg,newLgImg);
         MagicZoom.start(zoomObj);
       }
       else
         MagicZoom.stop(zoomObj);

       lockedImg = $(".imageCell:first",$("#" + ttStyle.styleCode)).attr("src");
    }

    // Set var for context to find only current products colors
    var $prodColor = $(".prodColors:first",$("#" + ttStyle.styleCode));

    $(".colorOuterSelected",$prodColor ).attr("class","colorOuter");
    $(".colorOuterOOSSelected",$prodColor ).attr("class","colorOuter colorOuterOOS");
    $(".colorOuterPreSellSelected",$prodColor ).attr("class","colorOuter colorOuterPreSell");
    $(".colorOuterPreSellOOSSelected",$prodColor ).attr("class","colorOuter colorOuterPreSellOOS");

    vStockQty=checkStock(selectedColor,selectedSize,vDefaultWhse);
    if(selectedSize == "" || vStockQty > 0 || vStockQty==-1){
      if(checkPreSell(vColorCode))
        vClass="colorOuterPreSellSelected";
      else
        vClass="colorOuterSelected";
    }
    else{
      if(checkPreSell(vColorCode))
        vClass="colorOuterPreSellOOSSelected";
      else
      vClass="colorOuterOOSSelected";
    }

    if(vThis == "")
      $("div[colorCode='" + vColorCode + "']:first",$prodColor).addClass(vClass);
    else
      $(vThis).find("div.colorOuter").addClass(vClass);

    if (selectedSize != "" && selectedColor != "")
    { priceItem(selectedColor,selectedSize); }
    if(ttStyle.ttSizeScale && ttStyle.ttSizeScale.length > 1)
      this.displayMultiSizes();
    else if(ttStyle.ttSize.length)
      this.displaySizes();
    if(ttStyle.hasImage && ttStyle.ttAltView)
      switchAltViews(vColorCode);
  }, //End setColor
  //===========================================================================
  setMultiSize: function(vIndex,vDimValue,vThis){
    if(!vIsRetail ) { return; }
    var vFullSizeCode = "";
    var vFullSize = true;

    $(".cartError:first",$("#" + ttStyle.styleCode)).html("");

    selectedMultiSize[vIndex] = vDimValue;
    $(".sizeOuterSelected" + vIndex + ":first",$("#" + ttStyle.styleCode)).attr("class","multiSizeOuter sizeOuter" + vIndex);
    vThis.className="sizeOuterSelected" + vIndex;
    $.each(selectedMultiSize, function(i){
       vFullSizeCode += selectedMultiSize[i];
       if(selectedMultiSize[i] == "")
         vFullSize = false;
    });

    if(vFullSize){
      selectedSize = vFullSizeCode;
      $.each(ttStyle.ttSize,function(i){
        if (ttStyle.ttSize[i].sizeCode == selectedSize) {
          if (ttStyle.ttSize[i].fullDesc != "")
            selectedSizeDesc = ttStyle.ttSize[i].fullDesc;
          else
            selectedSizeDesc = ttStyle.ttSize[i].description;
          $(".selectedSize:first",$("#" + ttStyle.styleCode)).html(selectedSizeDesc);
        }
      });
      this.displayColors();
    }
    else
      selectedSize = "";

    if (selectedSize != "" && selectedColor != "")
    { priceItem(selectedColor,selectedSize); }
    this.displayMultiSizes();
  }, //End setMultiSize
  //===========================================================================
  retailAddToCart: function(vOrderType){
    var vOrderQty = $("#qty" + this.styleCode).attr("value");
    if(vProdType=="S")
    {
     if(selectedColor == "" || selectedColor == "none" || selectedColor == null){
       $(".cartError:first",$("#" + ttStyle.styleCode)).html("Please choose a color to continue.");
       return;  }
     if(selectedSize == "" || selectedSize == "none" || selectedSize == null) {
       $(".cartError:first",$("#" + ttStyle.styleCode)).html("Please choose a size to continue.");
       return;  }
    }
    if (vOrderQty == "" ) {
      $(".cartError:first",$("#" + ttStyle.styleCode)).html("Please enter a quantity before adding item(s) to shopping bag.");
      return;  }
    if (isNumeric(vOrderQty) == false) {
      $(".cartError:first",$("#" + ttStyle.styleCode)).html("Please enter a numeric quantity before adding item(s) to shopping bag.");
      $("#qty" + this.styleCode).attr("value","").focus();
      return;  }
    if (vOrderQty <= 0)  {
      $(".cartError:first",$("#" + ttStyle.styleCode)).html("Please enter a quantity before adding item(s) to shopping bag.");
      return;  }

    if (vOrderLimit > 1 && (vTotalOrderQty + parseFloat(vOrderQty))  > vOrderLimit) {
       if (vOrderLimitMsg.indexOf("<qty>") != -1)
          vOrderLimitMsg = vOrderLimitMsg.replace("<qty>",vOrderLimit);
       alert(vOrderLimitMsg);
       return;
    }
    var invAvail=0;
    if(vProdType=="S") invAvail = parseInt(checkStock(selectedColor,selectedSize));
    if(vProdType=="I") invAvail = parseInt(checkStockItem());

    if (vMaxUnits > 0 && vOrderQty > vMaxUnits)
    {
      alert("The maximum number of units that may be purchased at one time is " + vMaxUnits.toString() + ".  Please contact our customer service department to order more than " + vMaxUnits.toString() + ".");
      invAvail = vMaxUnits;
      $("#qty" + this.styleCode).attr("value",invAvail).focus();
      return;
    }

    if(invAvail < vOrderQty)  {
      if (invAvail <= 0)
       $(".cartError:first",$("#" + ttStyle.styleCode)).html("The selected item is currently out of stock.");
      else{
       var alertMsg = "You have ordered " + vOrderQty + " however only ";
       if (invAvail == 1)
         alertMsg += "1 is available.";
       else
         alertMsg += invAvail + " are available.";
       alert(alertMsg);
      }
      if (invAvail <= 0 )
         invAvail = 1;
      $("#qty" + this.styleCode).attr("value",invAvail).focus();
      return;
    }
    addToCart(this.styleCode,selectedColor,selectedSize,vOrderQty,vOrderType);
    document.body.scrollTop = 0;
    if(vProdType=="S") setStock(selectedColor,selectedSize,vOrderQty);
    if(vProdType=="I") setStockItem(vOrderQty);
    vTotalOrderQty += + parseFloat(vOrderQty);
  },
  //===========================================================================
  colorEnter: function(vThis){
   var $inner = $(vThis).find("div:first");
   if($inner.hasClass("colorOuterOOS") ||
      $inner.hasClass("colorOuterOOSSelected") ||
      $inner.hasClass("colorOuterPreSellOOS") ||
      $inner.hasClass("colorOuterPreSellOOSSelected") )
   {
      var vStockQty=checkStock($(vThis).attr("colorCode"),selectedSize,vDefaultWhse);
      showOOSMsg($(vThis).attr("colorDesc"),selectedSizeDesc,vStockQty);
   }
   priceColor($(vThis).attr("colorCode"));
   $(".selectedColor:first",$("#" + ttStyle.styleCode)).html($(vThis).attr("colorDesc"));
   if(ttStyle.hasImage){ swapImg($(vThis).attr("rev")); }
  },
  //===========================================================================
  colorLeave: function(vThis){
    hideOOSMsg();
    priceColor(selectedColor);
    $(".selectedColor:first",$("#" + ttStyle.styleCode)).html(selectedColorDesc); /* C030004 */
    if(ttStyle.hasImage){ restoreImg(); }
  },
  //===========================================================================
  multiSizeEnter: function(vThis){
    var vDimIdx = $(vThis).data("dimIndex");
    var vSizeDesc = $(vThis).data("sizeDesc");
    if(vSizeDesc!=''){ $('.selectedSize:first',$("#" + ttStyle.styleCode)).html( vSizeDesc ); }
    if( $(vThis).hasClass("sizeOuterOOS" + vDimIdx) ||
        $(vThis).hasClass("sizeOuterOOSSelected" + vDimIdx) ||
        $(vThis).hasClass("sizeOuterPreSellOOS" + vDimIdx) ||
        $(vThis).hasClass("sizeOuterPreSellOOSSelected" + vDimIdx) )
    {
       showMultiSizeOOSMsg(selectedColorDesc,vDimIdx,$(vThis).data("dimValue"));
    }
  },
  //===========================================================================
  multiSizeLeave: function(vThis){
    if(selectedSizeDesc!='')
      $('.selectedSize:first',$("#" + ttStyle.styleCode)).html(selectedSizeDesc);
    else
      $('.selectedSize:first',$("#" + ttStyle.styleCode)).html('');
    hideOOSMsg();
  },
  //===========================================================================
  sizeEnter: function(vThis){
    $('.selectedSize:first',$("#" + ttStyle.styleCode)).html( $(vThis).data("sizeDesc") );
    if( $(vThis).hasClass("sizeOuterOOS") ||
        $(vThis).hasClass("sizeOuterOOSSelected") ||
        $(vThis).hasClass("sizeOuterPreSellOOS") ||
        $(vThis).hasClass("sizeOuterPreSellOOSSelected") )
    {
       showOOSMsg(selectedColorDesc,$(vThis).data("sizeDesc"),0);
    }
  },
  //===========================================================================
  sizeLeave: function(vThis){
    $('.selectedSize:first',$("#" + ttStyle.styleCode)).html( selectedSizeDesc );
    hideOOSMsg();
  },
  //===========================================================================
  report: function(){ //Used to check internal Data at runtime
    if(console && console.log){
       console.log("product=" + this.styleCode + " selectedColor=" + selectedColor + " selectedSize= " + selectedSize);
    }
  }
 }; //End return

}// End prodInit

//Event delegation - find closest parent prodDisplay and call functions from "product" stored in $.data
//MagicZoom steals the click event for colorOuter so change use MouseUp instead
$(".prodDisplay").delegate("a.colorOuter","mouseup",function(e){
                   if(e.which!=1){ return false; } // if not left mouse btn return
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.setColor($(this).attr("colorCode"),this,false);
                   return false;
                 })
                 .delegate("a.colorOuter","click",function(e){
                   return false;
                 })
                 .delegate("a.colorOuter","mouseenter",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.colorEnter(this);
                 })
                 .delegate("a.colorOuter","mouseleave",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.colorLeave(this);
                 })
                 .delegate(".sizeOuter","click",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.setSize($(this).data("sizeCode"),this);
                   return false;
                 })
                 .delegate(".sizeOuter","mouseenter",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.sizeEnter(this);
                 })
                 .delegate(".sizeOuter","mouseleave",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.sizeLeave(this);
                 })
                 .delegate(".multiSizeOuter","click",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.setMultiSize($(this).data("dimIndex"),$(this).data("dimValue"),this);
                   return false;
                 })
                 .delegate(".multiSizeOuter","mouseenter",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.multiSizeEnter(this);
                 })
                 .delegate(".multiSizeOuter","mouseleave",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.multiSizeLeave(this);
                 })
                 .delegate(".retailAddToCart","click",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.retailAddToCart('C');
                   return false;
                 })
                 .delegate(".retailAddToWishlist","click",function(){
                   prod = $(this).closest(".prodDisplay").data("product");
                   prod.retailAddToCart('Q');
                   return false;
                 });

/*
// jQuery Context:  $(selector,$(context))  ==  $(context).find(selector)

$(".prodDisplay").each(function(){
  $(this).data("product").report();
});

*/
