/******************************************************************************
* promo.js
*
* Creates the promotions section for the different pages.
*
* Requires: dhtml.js and globals.js
******************************************************************************/

var gPromoUrl = 0;
var gPromoLogo = 1;
var gPromoHeight = 2;

var gPromoItems = new Array();

gPromoItems = [
  ['http://www.applebees.com', gUrlBaseName + 'graphics/promos/applebees.gif', gPromoApplebeesHeight],
  ['http://www.dickssportinggoods.com', gUrlBaseName + 'graphics/promos/dicks.gif', gPromoDicksHeight],
/*
  ['http://www.footprintsacademy.com', gUrlBaseName + 'graphics/promos/footprints.jpg', gPromoFootprintsHeight],
  ['http://www.peaceofminddaycare.com', gUrlBaseName + 'graphics/promos/peaceofmind.jpg', gPromoPeaceofmindHeight],
  ['http://www.northwestpackaging.com', gUrlBaseName + 'graphics/promos/northwestpackaging.jpg', gPromoNorthwestPackagingHeight],
  ['http://www.performancepools.com', gUrlBaseName + 'graphics/promos/pps.jpg', gPromoPPSHeight],
  ['http://www.ourteam-remax.com', gUrlBaseName + 'graphics/promos/ourteam-remax.jpg', gPromoOurTeamHeight],
*/
  ['http://www.nickelodeonuniverse.com', gUrlBaseName + 'graphics/promos/nickprimary_nochar4cp.jpg', gPromoNickHeight],
  ['http://www.veolia.com', gUrlBaseName + 'graphics/promos/veolia.gif', gPromoVeoliaHeight],
  ['http://www.patricktrophies.com', gUrlBaseName + 'graphics/promos/patricktrophy.jpg', gPromoVeoliaHeight],
  ['http://www.cmocpa.com', gUrlBaseName + 'graphics/promos/cmocpa.jpg', gPromoCMOHeight]
];



var gRandomOrder = 0;
var gRandomValue = 1;

gPromoRandom = new Array(gPromoItems.length);

function promoInit(layerMain) {
// Returns layer

  var height;
  var heightBody;
  var html;
  var hold;
  var lowindex;
  var ii;
  var jj;
  var layer;
  var width = 0;

  height = 0;
  html  = '\n<!-- Promotions -->\n';
  html += '<table border="0" cellspacing="0" cellpadding="0">\n';

  if (gIncludePrinterFriendly) {
    html += '  <tr>\n';
    html += '    <td align=left>&nbsp;&nbsp;<a href="#" onClick="prepForPrint()"><img src="'
                   + gUrlBaseName
                   + 'graphics/printer.jpg" border=0 width=' + gPrinterJpgWidth
                   + ' height=' + gPrinterJpgHeight
                   + ' alt="Printer">Printer-friendly page<br><br></a></td>\n';
    html += '  </tr>\n';
  }

  if (gIncludeWoodbury) {
    gPreloadImages(gUrlBaseName + 'graphics/promos/links.jpg',
      gUrlBaseName + 'graphics/promos/linksbottom.jpg');
    html += '  <tr>\n';
    html += '    <td align="center">\n';
    html += '      <img src="'+ gUrlBaseName
                   + 'graphics/promos/links.jpg" border="0">\n';
    height += gPromoHeadingHeight;
    html += '    </td>\n';
    html += '  </tr>\n';

    html += '  <tr>\n';
    html += '    <td align="center" height=24>\n';
    html += '      <a href="http://www.ci.woodbury.mn.us/" target="_blank">'
                   + 'City of Woodbury</a>\n';
    height += 24;
    html += '    </td>\n';
    html += '  </tr>\n';


    html += '  <tr>\n';
    html += '    <td align="center" height=24>\n';
    html += '      <a href="http://www2.ci.woodbury.mn.us/InTouch/" target="_blank">'
                   + 'InTouch e-Mail Notification</a>\n';
    height += 24;
    html += '    </td>\n';
    html += '  </tr>\n';

    html += '  <tr>\n';
    html += '    <td align="center" height=24>\n';
    html += '      <a href="http://www.woodburybulletin.com/" target="_blank">'
                   + 'Woodbury Bulletin</a>\n';
    height += 24;
    html += '    </td>\n';
    html += '  </tr>\n';

    html += '  <tr>\n';
    html += '    <td align="center" height=24>\n';
    html += '      <a href="http://www.ci.woodbury.mn.us/woodbury-youth-resource-connection" target="_blank">'
                   + 'Woodbury Youth Resource Connection</a>\n';
    height += 24;
    html += '    </td>\n';
    html += '  </tr>\n';


    html += '  <tr>\n';
    html += '    <td align="center">\n';
    html += '      <img src="'+ gUrlBaseName
                   + 'graphics/promos/linksbottom.jpg" border="0">\n';
    height += gPromoHeadingHeight;
    html += '    </td>\n';
    html += '  </tr>\n';

    if (gIncludePromos) {
      html += '  <tr>\n';
      html += '    <td height="' + gPromosTopMargin + '">\n';
      html += '    </td>\n';
      html += '  </tr>\n';
      height += gPromosTopMargin;
    }
  }

  if (gIncludePromos) {
    gPreloadImages(gUrlBaseName + 'graphics/promos/oursponsors.jpg',
      gUrlBaseName + 'graphics/promos/applebees.gif',
      gUrlBaseName + 'graphics/promos/dicks.gif',
      gUrlBaseName + 'graphics/promos/nickprimary_nochar4cp.jpg',
      gUrlBaseName + 'graphics/promos/pps.jpg',
      gUrlBaseName + 'graphics/promos/cmocpa.jpg',
      gUrlBaseName + 'graphics/promos/veolia.gif',
      gUrlBaseName + 'graphics/promos/patricktrophy.jpg',
      gUrlBaseName + 'graphics/promos/oursponsorsbottom.jpg'
/*
      gUrlBaseName + 'graphics/promos/northwestpackaging.jpg',
      gUrlBaseName + 'graphics/promos/footprints.jpg',
      gUrlBaseName + 'graphics/promos/peaceofmind.jpg',
      gUrlBaseName + 'graphics/promos/acapulco.jpg',
      gUrlBaseName + 'graphics/promos/throwbacks.gif',
      gUrlBaseName + 'graphics/promos/sportsdiamond.jpg'
      gUrlBaseName + 'graphics/promos/holidayinneast.gif',
      gUrlBaseName + 'graphics/promos/meritchev.jpg',
      gUrlBaseName + 'graphics/promos/wendys.gif',
      gUrlBaseName + 'graphics/promos/cunninghams.jpg'
*/
    );
    html += '  <tr>\n';
    html += '    <td align="center">\n';
    html += '      <img src="'+ gUrlBaseName
                   + 'graphics/promos/oursponsors.jpg" border="0">\n';
    height += gPromoHeadingHeight;

    // Randomly order the promotions
    for (ii=0; ii<gPromoRandom.length; ++ii) {
      gPromoRandom[ii] = new Array(gRandomValue + 1);
      gPromoRandom[ii][gRandomOrder] = ii;
      gPromoRandom[ii][gRandomValue] = Math.floor(Math.random()*100);
    }

    // Order the promotions
    for (ii=0; ii<gPromoRandom.length - 1; ++ii) {
      lowindex= ii;
      for (jj=ii+1; jj<gPromoRandom.length; ++jj) {
        if (gPromoRandom[gPromoRandom[jj][gRandomOrder]][gRandomValue] < gPromoRandom[gPromoRandom[lowindex][gRandomOrder]][gRandomValue]) {
          lowindex = jj;
        }
      }

      if (ii != lowindex) {
        hold = gPromoRandom[ii][gRandomOrder];
        gPromoRandom[ii][gRandomOrder] = gPromoRandom[lowindex][gRandomOrder];
        gPromoRandom[lowindex][gRandomOrder] = hold;
      }
    }

    // Add the promotion logos
    for (ii=0; ii<gPromoRandom.length; ++ii) {
      htmlLogo = '      <a href="' + gPromoItems[gPromoRandom[ii][gRandomOrder]][gPromoUrl] + '"'
                     + ' target="_blank"><img src="'+ gPromoItems[gPromoRandom[ii][gRandomOrder]][gPromoLogo]
                     + '" border="0"></a>\n';
      if (ii != 0) {
        html += '<p>';
        height += gParagraphHeight;
      }
      html += htmlLogo;
      height += gPromoItems[gPromoRandom[ii][gRandomOrder]][gPromoHeight];
    } // for ii


    // Add the bottom of the sponsor block
    html += '      <br><img src="'+ gUrlBaseName
                   + 'graphics/promos/oursponsorsbottom.jpg" border="0">\n';
    height += gPromoHeadingHeight;
    html += '    </td>\n';
    html += '  </tr>\n';
  }

  heightBody = getHeight(layerMain);
//  alert("height = " + height + '\n');
//  alert("heightBody = " + heightBody + '\n');
//  alert(html);
  // if the body is longer than the promotions, then fill to bottom of page
  if (heightBody < height) {
    heightBody = height;
  }
  else {
    space = heightBody - height - (gPromosTop - gMainTop) - gBorderWidth;
    if (space > 0) {
      html += '\n<!-- Blank space -->\n';
      html += '  <tr>\n';
      html += '  </tr>\n';
      height += space;
    }
  } // else
  html += '</table>\n';

// alert('html = ' + html + '\n');
  layer = createLayer(html, "promo", gPromosTop, gPromosLeft, height, gPromoHeadingWidth, 1);
  return layer;
}  // promoInit
 

