/**
  Used to re organise the product panels 
  so they are sorted by department
 **/
// array of previuolsy shown indexes, this restricts repeat items in the panel
aryShownIndices = new Array();

// it prints a single product to the panel named below
// // the first parameter is the department id
function printPanel (nId , sPanelName) {
  sProductOutput = "";
  //alert ( " product out put \n " +sProductOutput+  "\n"  + aryProducts.length);
  // now we have an array like this : 2-6006 
  // where [0] is the dept id and [1] is the product id {getThumbnailImage(featuredproduct)}
  //  [3] is  {featuredproduct['product_link']} [4] is {featuredproduct['product_name']} 
  // generate the formatted products 
  sProductString =""; // show a random product from dept 
  aryDepts = new Array('', 'Womens', 'Mens');
  aryHolder = aryProductsWomens;// defined in the product panel
  sAlign=""; // used to alig one table to the left
  sAlign=' align="left"  ';
  if(nId == 2) {
    aryHolder = aryProductsMens;
  } else if(nId == 1) {
  aryHolder = aryProductsWomens;
  sAlign=' align="left"  ';
  }
  x = getRandomProduct(aryHolder) ;
  // need to catch it here if there's no item 
  if(aryHolder[x] ) {
    sProductString += ' <TABLE class="panel-product-container"  cellpadding="1" cellspacing="0"   border="0"' +  sAlign  + ' width="30%" >';
    sProductString += ' <TR> ' ;
    sProductString += '   <TD  colspan="2" class="panel-dept-heading" align="center" > ' ;  
    // dept id
    sProductString +=  aryDepts[aryHolder[x][0]]  ;// + ' -  ' + x  + '  length ' + aryHolder.length;
    sProductString += ' </TD> ' ;  
    sProductString += ' </TR> ' ;  
    sProductString += ' <TR> ' ;  
    // pic 
    sProductString += '  <TD valign="top" width="80" >'     ;  
    sProductString +=  ' <A href="' +    aryHolder[x][3]  + '" class="panel-product-link" > ';
    sProductString += aryHolder[x][2] ;
    sProductString += '</A>   ' ;  
    sProductString += ' </TD>   ';     
    sProductString += ' <TD  valign="top"  >   ';     
    // brand name
    sProductString +=  '<SPAN class="panel-product-brandname" >'
    sProductString +=  aryHolder[x][6].toLowerCase() ;
    sProductString += '</SPAN> <BR />  ' ;  
    // item name
    sProductString +=  ' <A href="' +    aryHolder[x][3]  + '" class="panel-product-link" > ';

    sProductString +=  aryHolder[x][4] ;
    sProductString += '</A> <BR /><span id="text-regularprice">Regular Price: ' ;  
    // price
    sProductString += '<span class="text-pricestrike">$' + aryHolder[x][7].toFixed(2)  ;
    sProductString += '</span><br></span>';
    sProductString += '<span id="text-yourprice">Your  Price: ' ;  
    // webprice
    sProductString += '<span class="text-price">$' + aryHolder[x][5].toFixed(2)  ;
    sProductString += '</span></span>';
    sProductString += ' </TD> ' ;  
    sProductString += ' </TR> ' ;
    sProductString += ' </TABLE> ' ;
    // populate the panel
    // one panel for specials and one for new prodcuts
    if(document.getElementById(sPanelName) ){
      dPanel = document.getElementById(sPanelName); 
      s = dPanel.innerHTML ;
      dPanel.innerHTML = s  +   sProductString;
    }
  }
}
// get the radom produc id from with mens or womens holder array
function getRandomProduct(aryHolder) {
  nProduct = "";
  nProduct =  Math.round((aryHolder.length-1)* Math.random()) ;
  //if it's not in aryShownIndices then return it other wise we defualt ot 0 which cna never
  // come up this will do as only 3 products are ever shown
if( !aryShownIndices[nProduct]) {
    aryShownIndices.push( nProduct);
    return nProduct;
  } else {
    return 0;
  }
}
