
// BANNER OBJECT
function Banner(objName) 
{
  this.obj = objName;
  this.aNodes = [];
  this.currentBanner = 0;
};

// ADD NEW BANNER
Banner.prototype.add = function(bannerPath, height, width)
{
  this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bannerPath, '', 'embed', height, width);
};

// ADD NEW BANNER
Banner.prototype.addimg = function(bannerPath, linkCode, height, width)
{
  this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+ this.aNodes.length, bannerPath, linkCode, 'img', height, width);
};

// Node object
function Node(name, bannerPath, linkCode, bannerType, height, width) {
  this.name = name;
  this.bannerPath = bannerPath;
  this.linkCode = linkCode;
  this.bannerType = bannerType;
  this.height = height
  this.width = width;
};

// Outputs the banner to the page
Banner.prototype.toString = function() {
  var str = ""
  for (var iCtr=0; iCtr < this.aNodes.length; iCtr++){
    str = str + '<span name="' + this.aNodes[iCtr].name + '" ';
    str = str + 'id="' + this.aNodes[iCtr].name + '" ';
    str = str + 'class="m_banner_hide" ';
    str = str + 'bgcolor="#FFFFFF" ';  // CHANGE BANNER COLOR HERE
    str = str + ' >\n';
    if (this.aNodes[iCtr].bannerType == 'embed')
    {
      str = str + '<EMBED wmode="transparent"';
      str = str + ' src="' + this.aNodes[iCtr].bannerPath + '"';
      str = str + ' quality=high';
      str = str + ' WIDTH="' + this.aNodes[iCtr].width + '"';
      str = str + ' HEIGHT="' + this.aNodes[iCtr].height + '"';
      str = str + ' NAME="bnr_'+this.aNodes[iCtr].name+'"';
      str = str + ' TYPE="application/x-shockwave-flash"';
      str = str + ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"';
      str = str + ' />';
    }
    else if (this.aNodes[iCtr].bannerType == 'img')
    {
      str = str + '<a href="' + this.aNodes[iCtr].linkCode + '" target="_blank">';
      str = str + '<img src="' + this.aNodes[iCtr].bannerPath + '"';
      str = str + ' WIDTH="' + this.aNodes[iCtr].width + '"';
      str = str + ' HEIGHT="' + this.aNodes[iCtr].height + '"';
      str = str + ' /></a>';
    }
    str += '</span>';
  }
  return str;
};

// START THE BANNER ROTATION
Banner.prototype.start = function(){
  this.changeBanner();
}

// CHANGE BANNER
Banner.prototype.changeBanner = function(){
  whichBanner = Math.floor(Math.random()*(this.aNodes.length));
  document.getElementById(this.aNodes[whichBanner].name).className = "m_banner_show";
}
