﻿// ==
// == banner.js 
// ==
// == Select a random banner based on various factors
// ==
// == Copyright (c) 2010 David McAdams, Jefferson City, Missouri. This document may be reproduced
// == for non-commercial educational use only. Attribution must be made on this and
// == all derivative works.
// ==
// == http://www.lifeisastoryproblem.org
// == http://www.allmathwords.org
// ==

// ==
// == cls_banner: Object that contains information on an individual banner.
// ==
// == Uses:
// ==   none
// ==
// == Used by:
// ==   cls_banners
// ==
// == Parameters:
// ==   banner code, banner percentile.
// ==
// == Attributes:
// ==   this.bannercode: ASCII text to display banner and allow it to go to another web page.
// ==   this.percentile: A number between 0 and 100.
// ==
// == Methods:
// ==   getPercentile()
// ==     gets the percentile assignment for the banner
// ==   getCode()
// ==     gets the banner code to insert.
// ==
function cls_banner( bannercodein, bannerpercentilein )
{
  this.bannercode = bannercodein;
  this.bannerpercentile = bannerpercentilein;
}

function cls_banner_getpercentile()
{
  return( this.bannerpercentile );
}

function cls_banner_getcode()
{
  return( this.bannercode );
}
cls_banner.prototype.getPercentile = cls_banner_getpercentile;
cls_banner.prototype.getCode = cls_banner_getcode;

// ==
// == cls_banners: Object that contains information on all banners
// ==
// == Uses:
// ==   cls_banner
// ==
// == Used by:
// ==   function GetBanner
// ==
// == Parameters:
// ==   none.
// ==
// == Attributes:
// ==   this.bannerarray: array of information on each banner.
// ==
// == Methods:
// ==   getbanner()
// ==     gets the banner code to insert.
// ==
function cls_banners()
{
  this.bannerarray = new Array();
  // INSERT BANNERS HERE
  this.bannerarray[ this.bannerarray.length ] = new cls_banner( '<a href="../sponsoredproducts.html"><img src="../images/banners/dictionarybanner01.png" alt="Coming soon! All Math Words Dictionary and Study Guide"></a>', 10 );
  this.bannerarray[ this.bannerarray.length ] = new cls_banner( '<a href="../sponsoredproducts.html"><img src="../images/banners/dictionarybanner02.png" alt="Coming soon! All Math Words Dictionary and Study Guide"></a>', 35 );
  this.bannerarray[ this.bannerarray.length ] = new cls_banner( '<a href="../sponsoredproducts.html"><img src="../images/banners/dictionarybanner03.jpg" alt="Math Study Guide and Dictionary. You need this!"></a>', 60 );
  this.bannerarray[ this.bannerarray.length ] = new cls_banner( '<a href="../sponsoredproducts.html"><img src="../images/banners/dictionarybanner04.jpg" alt="Math Study Guide and Dictionary. We can help!"></a>', 100 );
  // END INSERT BANNERS
}

function cls_banners_getbanner( )
{
  var idx;
  var random;

  var random = Math.random() * 100;
  var bannerid = this.bannerarray.length - 1; // default is the last banner
  for ( idx = this.bannerarray.length - 1; idx >= 0; idx-- )
  {
     if ( random <= this.bannerarray[ idx ].getPercentile() )
       bannerid = idx;
  }
  
  return( this.bannerarray[ bannerid ].getCode() );
}
cls_banners.prototype.getBanner = cls_banners_getbanner;

// ==
// == function GetBanner
// ==
// == returns a randomly selected banner
// ==
function GetBanner()
{
  var bannerobj;
  var bannertext;
  var bannerelem;

  bannerobj = new cls_banners();
  bannertext = bannerobj.getBanner();
  bannerelem = document.getElementById( 'lbnr' )
  if ( bannerelem != null )
    bannerelem.innerHTML = bannertext;
}


