ResizePromoBox = function()
{
/*
 Dynamically modifies (width and padding of) merchandising spots on homepage and other pages that use
 ProductMerchantCtrl User Control.
*/
 var trace = false; // when set to true, sends Trace alerts to page.
 ClearTrace();
 if(trace) {
 	Trace("Resize function called " + Date());
 }
 var promoBoxContainerId = "promoBoxCont";
 var promoBoxClassName = "midcolfl";

 if (!document.getElementById(promoBoxContainerId)){return;}

 // this is the smallest width that the centre panel can shrink to
 var minContainerWidth = 200;
 var minPromoBoxWidth = 230;
 var promoboxMarginWidth = 10;

 // returns an array of promobox elements
 var promoBoxArray = getElementsByClass("midcolfl",null,"div");
 var promoBoxClearArray = getElementsByClass("midcolflclr",null,"div");
 var promoBoxCount = promoBoxArray.length;
 var promoBoxClearCount = promoBoxClearArray.length;

 // find out what the current width of the centre panel is
 var centrePanel = document.getElementById(promoBoxContainerId);

 // a DOM bug in Firefox versions prior to 1.5 gives us an incorrect offsetWidth value - this sorts it out!
 if(is_fx && (parseInt(is_minor)<1.5)){centrePanel.style.position = "absolute";}
 var containerWidth = parseInt(centrePanel.offsetWidth);
 if(is_fx && (parseInt(is_minor)<1.5)){centrePanel.style.position = "relative";}

 // compensate for a rendering bug in Opera by making the container width smaller
 if(navigator.userAgent.toLowerCase().indexOf('opera')!=-1){containerWidth -= 20}

 // a safety check to make sure we don't have a smaller centre panel than we expect
 if (containerWidth < minContainerWidth){containerWidth = minContainerWidth;}

 if(trace) {
   Trace("Container width: " + containerWidth);
   Trace("Promo box count: " + promoBoxCount);
   Trace("Promo box clear count: " + promoBoxClearCount);
 }

 // Work out how many promo boxes we can fit on each row
 var promoBoxesPerRow = parseInt(containerWidth / minPromoBoxWidth);
 if (promoBoxesPerRow > 4){promoBoxesPerRow = 4;}
 if (promoBoxesPerRow > promoBoxCount){promoBoxesPerRow = promoBoxCount;}
 // if we calculate 3 boxes per row, but end up with one box orphaned, revert to 2 boxes per row - looks neater
 if (((promoBoxCount%promoBoxesPerRow)==1) && promoBoxesPerRow==3){promoBoxesPerRow = 2}
 // if we calculate 4 boxes per row, but end up with 2 boxes orphaned, revert to 3 boxes per row - looks neater
 if (((promoBoxCount%promoBoxesPerRow)==2) && promoBoxesPerRow==4){promoBoxesPerRow = 3}

 if(trace) {
   Trace("Box Count Modulus: " + (promoBoxCount%promoBoxesPerRow));
 }

 // figure out how wide each promo box should be
 var newPromoBoxWidth = parseInt((containerWidth - ((promoBoxesPerRow-1)*promoboxMarginWidth)) / promoBoxesPerRow);

// // hack for FF rendering issue when there are only 2 boxes available and they both appear on one line
 if((promoBoxCount == 2) && (promoBoxesPerRow == 2) && (is_fx)){newPromoBoxWidth -= 8}



 if(trace) {
   Trace("Boxes per row: " + promoBoxesPerRow);
   Trace("New promo box width: " + newPromoBoxWidth);
 }

 // iterate through the promo boxes applying width and margin to each
 for (var i=0;i<=promoBoxArray.length-1;i++){
   promoBoxClearArray[i].className = "midcolflclr"
   // the end box of each row should be handled differently (ie; 0 margin)
   if (((i+1) / promoBoxesPerRow).toString().indexOf(".") == -1) {
   promoBoxArray[i].style.marginRight = 0;
   promoBoxClearArray[i].className += " clr midcolflclrmaxwidth";
   } else {
     promoBoxArray[i].style.marginRight = promoboxMarginWidth + "px";
   }
   promoBoxArray[i].style.width = newPromoBoxWidth + "px";

   if(trace){
     Trace("PromoBox ClassName: " + promoBoxClearArray[i].className);
   }
 }
}


function Trace(message)
{
    if(!document.getElementById("resizeFeaturedProductsDebug")){return}
    var traceBox = document.getElementById("resizeFeaturedProductsDebug");
    traceBox.innerHTML += message + "<br />";
}

function ClearTrace()
{
    if(!document.getElementById("resizeFeaturedProductsDebug")){return}
    var traceBox = document.getElementById("resizeFeaturedProductsDebug");
    traceBox.innerHTML = "";
}
111