// JavaScript Document

<!--

  window.onerror = silentHandler;
  function silentHandler() {return false};

  var push = function() 
  {
    var j = this.length;
    for (var i=0;i<push.arguments.length;++i) 
    {
      this[j] = push.arguments[i]
      j++
    }
  }
  Array.prototype.push = push

  var associativeClass = function(j) 
  {
    for (var i=1;i<=j;++i) 
    {
      this[i] = new associativeObj();
    }
  }
  var associativeObj = function() {}

  var getBannerTemplate = function() 
  {
    // define the total number of banners in the set
    var iBannerTotal = 6;

    // create an implicit array
    var ia = new associativeClass(iBannerTotal); 

    // create an explicit array
    var ar = new Array();

    // define each image within the set (the set must be equal in number to iBannerTotal)
    ia[1].imageName = '/ftproot/images/banner_functionsjuly2010.jpg';
    ia[2].imageName = '/ftproot/images/dj.jpg';
    ia[3].imageName = '/ftproot/images/banner_stiletto.jpg';
    ia[4].imageName = '/ftproot/images/banner_functionsjuly2010.jpg';
    ia[5].imageName = '/ftproot/images/dj.jpg';
    ia[6].imageName = '/ftproot/images/banner_stiletto.jpg';

    // assign a weight to each image in the set 
    ia[1].weight = 1;
    ia[2].weight = 1;
    ia[3].weight = 1;
    ia[4].weight = 2;
    ia[5].weight = 1;
    ia[6].weight = 1;

    // assign background color values to each image in the set
    ia[1].backgroundcolor = '#000000';
    ia[2].backgroundcolor = '#000000';
    ia[3].backgroundcolor = '#000000';
    ia[4].backgroundcolor = '#000000';
    ia[5].backgroundcolor = '#000000';
    ia[6].backgroundcolor = '#000000';

    // assign a url to each image in the set 
    ia[1].url = null;
    ia[2].url = null;
    ia[3].url = null;
    ia[4].url = null;
    ia[5].url = null;
    ia[6].url = null;

    // assign title text to each image in the set 
    ia[1].title = 'Functions at the Chelsea - free room hire';
    ia[2].title = 'DJs every Saturday night!';
    ia[3].title = 'Happy Hour 4pm - 6pm!';
    ia[4].title = 'Functions at the Chelsea - free room hire!';
    ia[5].title = 'DJs every Saturday night!';
    ia[6].title = 'Happy Hour 4pm - 6pm!';

    // assign any other required values to each image in the set
    // ia[1].height = 80;
    // width, border, target, script etc. whatevers needed to build the final script

    // get the sum of the weighted values
    var iWeightTotal = 0;
    for (i in ia) 
    {
      iWeightTotal += ia[i].weight
    }

    // calculate and store the weight percentages
    for (i in ia) 
    {
      ia[i].percentage = Math.round((ia[i].weight / iWeightTotal) * 100);
    }

    // push an implicit array object id onto the explicit array once for each id percentage point 
    for (i in ia) 
    {
      for (var j=0;j<ia[i].percentage;++j) 
      {
         ar.push(i)
      }
    }

    // get a random integer value between 0 and the explicit array length
    var k = Math.round(Math.random()*ar.length)

    // return a weighted imageName object
    // return ia[ar[k]].imageName

    // as an alternative to returning an explicit value embed multiple values within script
    var scriptText = '<table width="900" cellspacing="0" cellpadding="0" border="0" align="">';
    scriptText += '  <tbody>';
    scriptText += '    <tr>';
    scriptText += '      <td style="padding: 5px 5px 2px 5px; background: rgb(0, 0, 0) none repeat scroll 0% 50%; width: 210px;">';
    scriptText += '        <a href="/ChelseaTestPage/520/n/3/0/0/">';
    scriptText += '          <img width="200" height="98" border="0" title="Chelsea Hotel Chatswood" alt="Chelsea Hotel Chatswood" src="/ftproot/images/logo_white_on_black_200.gif" />';
    scriptText += '        </a>';
    scriptText += '      </td>';
    scriptText += '      <td style="background: rgb(0, 0, 0) none repeat scroll 0% 50%; width: 1px;">';
    scriptText += '        <img width="1" src="/images/cs_tm.gif" alt="" />';
    scriptText += '      </td>';
    scriptText += '      <td style="background: #D01A55 none repeat scroll 0% 50%; width: 20px;">';
    scriptText += '        <img width="1" src="/images/cs_tm.gif" alt="" />';
    scriptText += '      </td>';
    scriptText += '      <td style="background: rgb(0, 0, 0) none repeat scroll 0% 50%; width: 1px;">';
    scriptText += '        <img width="1" src="/images/cs_tm.gif" alt="" />';
    scriptText += '      </td>';  

    if (ia[ar[k]].url) 
    { 
      scriptText += '      <td onclick="javascript:location.href=\'' + ia[ar[k]].url + '\'" target="_blank" style="cursor:pointer; background-color: ' + ia[ar[k]].backgroundcolor + '; background-position: top left; background-image: url(' + ia[ar[k]].imageName + '); background-repeat: no-repeat" valign="top" title="' + ia[ar[k]].title + '" width="906"><img height="80" src="/images/cs_tm.gif" width="100%" border="0" /></td>';
    } 
    else 
    {
      scriptText += '      <td style="padding: 5px; background: rgb(0,0,0) url(' + ia[ar[k]].imageName + ') no-repeat scroll left top" title="' + ia[ar[k]].title + '"><img width="1" src="/images/cs_tm.gif" alt="" /></td>';
    }

    scriptText += '    </tr>';  
    scriptText += '  </tbody>';  
    scriptText += '</table>';  


    return scriptText;

  }

  document.write(getBannerTemplate());
// -->












