﻿function banner(imgSource, url, alt, chance) {
    this.imgSource = imgSource;
    this.url = url;
    this.alt = alt;
    this.chance = chance;
}

banners = new Array();
///////////////////////////////////////////////////
// banners[x] = new banner(<banner source image>,     										
// 						   <url to link to when the banner is clicked>,                     
//                         <alt>                                                            
//                         <the chance this banner has in which to be randomly selected>);  
// To increase the chance of a banner being randomly selected, increase it's corresponding 'chance' property relative to the other banners.
///////////////////////////////////////////////////

i = 0;
banners[i] = new banner("/banners/blueman_banner.gif",
    	                    "/redir.aspx?goto=http://www.blueman.com",
        	                "Blue Man Group",
            	            50);
i++;
banners[i] = new banner("/banners/neaq_banner.gif",
    	                    "/redir.aspx?goto=http://www.neaq.org/",
        	                "New England Aquarium",
            	            50);
i++;
banners[i] = new banner("/banners/mbe-library-web-banner.jpg",
    	                    "/redir.aspx?goto=http://www.mbelibrary.org/",
        	                "The Mary Baker Eddy Library",
            	            50);


i++;
banners[i] = new banner("/banners/SamAdamsTourBanner.jpg",
    	                    "/redir.aspx?goto=http://www.samueladams.com/contact_tour.aspx",
        	                "Samuel Adams Boston Brewery Tour",
            	            50);

i++;
banners[i] = new banner("/banners/test.gif",
    	                    "/redir.aspx?goto=http://www.trolleytours.com/boston/index.asp?bostonguide468x60",
        	                "Trolley Tours",
            	            50);



sum_of_all_chances = 0;

for (i = 0; i < banners.length; i++) {
    sum_of_all_chances += banners[i].chance;
}

function randomBanner() {
    if (site_root == '/')
        site_root = '';
    chance_limit = 0;
    randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) + 1;
    for (i = 0; i < banners.length; i++) {
        chance_limit += banners[i].chance;
        if (randomly_selected_chance <= chance_limit) {
            document.getElementById("banner").innerHTML = "<a href='" + site_root + banners[i].url + "'><img src='" + site_root + banners[i].imgSource + "' border='0' alt='" + banners[i].alt + "' style='float: right;'/></a>";
            break;
        }
    }
}
randomBanner();
setInterval("randomBanner()", 30000);

