var tIndex = 0;//used when adding elements to the array var slideshowInterval = 10; var cb = 0;//currentbanner var NUM_BANNER_LOCATIONS = 0; var bannerArray = new Array(); var snippetArray = new Array(); function Banner(theImage, theDescription, theLinkText, theURL, theLinkTarget, theLinkLocation, thePopup, thePopupHeight, thePopupWidth, theBannerLocation){ //the banner object this.image = theImage; this.description = theDescription; this.linktext = theLinkText; //theURL == "" ? this.url = "#" : this.url = theURL; this.url = theURL; theLinkTarget == "Current Window" ? this.linktarget = "_self" : this.linktarget = "_blank"; this.linklocation = theLinkLocation; this.popup = thePopup; this.popupHeight = thePopupHeight; this.popupWidth = thePopupWidth; this.bannerlocation = theBannerLocation; this.bannerSnippet = ""; } function addElement(theImage, theDescription, theLinkText, theURL, theLinkTarget, theLinkLocation, thePopup, thePopupHeight, thePopupWidth, theBannerLocation){ //this function takes bannerArray and makes the current subscript (tIndex) a banner object with the given parameters bannerArray[tIndex] = new Banner(theImage, theDescription, theLinkText, theURL, theLinkTarget, theLinkLocation, thePopup, thePopupHeight, thePopupWidth, theBannerLocation); //build the bannerSnippet if(bannerArray[tIndex].popup =="1")//build the snippet to open in a popup window { if(bannerArray[tIndex].linklocation == "image")//if the link location is an image... { if(bannerArray[tIndex].description == "")//if the description is missing bannerArray[tIndex].bannerSnippet = '' + bannerArray[tIndex].image + ''; else//assume there is a description bannerArray[tIndex].bannerSnippet = '' + bannerArray[tIndex].image + '
' + bannerArray[tIndex].description; } if(bannerArray[tIndex].linklocation == "description")//if the link location is the description { if(bannerArray[tIndex].image == "")//if there is no image bannerArray[tIndex].bannerSnippet = bannerArray[tIndex].description + ' '; else//assume there is an image bannerArray[tIndex].bannerSnippet = bannerArray[tIndex].image + '
' + bannerArray[tIndex].description + '
'; if (bannerArray[tIndex].linktext == "")//if there is no link text bannerArray[tIndex].bannerSnippet += 'Click here for more'; else//assume there is link text bannerArray[tIndex].bannerSnippet += bannerArray[tIndex].linktext + ''; } } else//build snippet to open in a regular window { var urlLink; if(bannerArray[tIndex].linklocation == "image")//if the link location is an image... { if(bannerArray[tIndex].description == ""){//if the description is missing //don't generate a link tag if no url is provided bannerArray[tIndex].url == "" ? urlLink = "" : urlLink = ''; bannerArray[tIndex].bannerSnippet = urlLink + bannerArray[tIndex].image; urlLink != "" ? bannerArray[tIndex].bannerSnippet += '':null;//if there is a link, close the tag } else{//assume there is a description //don't generate a link tag if no url is provided bannerArray[tIndex].url == "" ? urlLink = "" : urlLink = ''; bannerArray[tIndex].bannerSnippet = urlLink + bannerArray[tIndex].image; urlLink != "" ? bannerArray[tIndex].bannerSnippet += '':null;//if there is a link, close the tag bannerArray[tIndex].bannerSnippet += '
' + bannerArray[tIndex].description; } } if(bannerArray[tIndex].linklocation == "description")//if the link location is the description { if(bannerArray[tIndex].image == "")//if there is no image bannerArray[tIndex].bannerSnippet = bannerArray[tIndex].description + ' '; else//assume there is an image bannerArray[tIndex].bannerSnippet = bannerArray[tIndex].image + '
' + bannerArray[tIndex].description + '
'; if (bannerArray[tIndex].linktext == "")//if there is no link text bannerArray[tIndex].bannerSnippet += 'Click here for more'; else//assume there is link text bannerArray[tIndex].bannerSnippet += bannerArray[tIndex].linktext + ''; } } //document.write('
'); ++tIndex; } function build2DArray(){ //the 2-dimensional will contain the banner location, and the banners for that location //example: banner[banner_location][banners] var eIndex = 0; for (var i = 1; i <= NUM_BANNER_LOCATIONS; i++){//for every banner location snippetArray[i] = new Array();//create 2 dimensional array for (var e = 0; e < bannerArray.length; e++){//for every banner if (i == parseInt(bannerArray[e].bannerlocation)){//if this banner belongs in the current location snippetArray[i][eIndex] = bannerArray[e]; eIndex++;}//using eIndex instead of e eliminates gaps in the array } eIndex = 0; } } function getNumberOfBanners(){ //this finds the number of banner locations being used var maxNum = 0; for (var i = 0; i < bannerArray.length; i++){ if (parseInt(bannerArray[i].bannerlocation) > maxNum) maxNum = bannerArray[i].bannerlocation; } return maxNum; } function RotateBanners(){ for (var i = 1; i <= NUM_BANNER_LOCATIONS; i++){//for every banner location var BannerID = "banner" + i;//the banner ID that will be replaced cb = bannerArray[i];//bannerArray now hold the current banner for each location if (snippetArray[i].length > 1 ){//only rotate the banner if there is more than one ChangeBanner(BannerID, snippetArray[i][cb].bannerSnippet); bannerArray[i] = (bannerArray[i] + 1) % snippetArray[i].length; } } } function ChangeBanner(id, bannerSnippet) { parentDIV = document.getElementById(id); oldChild = parentDIV.childNodes[0]; newChild = document.createElement('div'); newChild.innerHTML = bannerSnippet; parentDIV.replaceChild(newChild, oldChild); } function pickRandom(banLocation, ID) { /*'banLocation' is the banner location where a random banner will be chosen from if '0' is used, a random banner will be chosen from all avaiable locations*/ /*'ID' is the banner location where the random banner will be displayed*/ NUM_BANNER_LOCATIONS = getNumberOfBanners(); build2DArray(); if (banLocation <= 0 || banLocation > NUM_BANNER_LOCATIONS) //randomly choose a banner location between 1 and the number of banner locations var randBannerLocation = Math.floor(Math.random() * NUM_BANNER_LOCATIONS ) + 1; else randBannerLocation = banLocation; //randomly choose a banner from the location chosen above var randBanner = Math.floor(Math.random() * snippetArray[randBannerLocation].length); ChangeBanner(ID, snippetArray[randBannerLocation][randBanner].bannerSnippet);//display the banner } function initializeBanners(){ //this sets the div's to their initial banner NUM_BANNER_LOCATIONS = getNumberOfBanners(); build2DArray(); for (var i = 1; i <= NUM_BANNER_LOCATIONS; i++){//for every banner location var ID = "banner" + i;//the banner ID that will be replaced ChangeBanner(ID, snippetArray[i][0].bannerSnippet);//this sets the initial banner } //because bannerArray is no longer needed at this point, it will be used to contain the current banner information for (var i = 1; i <= NUM_BANNER_LOCATIONS; i++){//for every banner location bannerArray[i] = 0;//the new current banner is the next banner in the array bannerArray[i] = (bannerArray[i] + 1) % snippetArray[i].length; } setInterval("RotateBanners()",slideshowInterval * 1000); }