﻿    var request = window.location.search;
    var today = new Date();
    var months = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sept:8,oct:9,nov:10,dec:11};
    var banners = new Array();
    
    // Overide todays date with a simple 
    // query for testing (eg. ?day=01-jan)
    if (request) {
        request = request.substring(1);
        var r = request.split("&");
        
        for (var i = 0; i < r.length; i++) {
            var d = r[i].split("=");
            if (d[0] == "day") {
               d = d[1].split("-");
               today = new Date(today.getYear(), months[d[1]], d[0]); 
            }
        }
    }
    // function to add banner to array
    function addEventBanner(start, end, filename) {
        banners.push(new eventBanner(start, end, filename));
    }
    // function to find todays banner 
    // "tagetDate" is optional argument of type "Date"
    function findEventBanner(targetDate) {
        var t = targetDate || today;
        
        for (var i = 0; i < banners.length; i++) {
            if (banners[i].dateTest(t)) {
                return banners[i];
            }
        }
    }
    // eventBanner object
    // expects 3 arguments:
    // start - in the format "01-jan"
    // end - in the format "01-feb"
    // filename - a string to hold the file name of the banner
    function eventBanner(start, end, filename) {
        var s = start.split("-");
        var e = end.split("-");
        
        this.start = new Date(today.getYear(), months[s[1]], s[0]);
        this.end = new Date(today.getYear(), months[e[1]], e[0]);
        
        //check to see if it ends next year
        if (this.start > this.end) {
            this.end.setFullYear(this.end.getFullYear() + 1);
        }
        this.filename = filename;
    }
    // event banner test function to determin if a 
    // date falls within it's range
    eventBanner.prototype.dateTest = function(testDate) {
        
        return (this.start <= testDate && this.end >= testDate);
    }
    
