
function Banner(src, alt, href) {
	this.src = src;
	this.alt = alt;
	this.href = href;
}
Banner.prototype.src;
Banner.prototype.alt;
Banner.prototype.href;
Banner.prototype.setImage = function() {
    document.images['bannerImg'].src = 'images/banners/' + this.src;
    document.images['bannerImg'].alt = this.alt;
}
Banner.prototype.openWindow = function() {
    open(this.href);
}

function InfoBox() {
    this.step = 2;
    this.div = document.getElementById("infoBox");
    this.state = this.oldState = this.stateTypes.PAUSE;
    this.pauseTimeCounter = 0;
}
InfoBox.prototype.step;
InfoBox.prototype.div;
InfoBox.prototype.stateTypes = { SCROLL : 0, PAUSE : 1, HALT : 2 };
InfoBox.prototype.state;
InfoBox.prototype.oldState;
InfoBox.prototype.timeCounter;
InfoBox.prototype.animate = function() {
    if (this.state == this.stateTypes.HALT) {
        return;
    }
    if (this.state == this.stateTypes.PAUSE) {
        if (this.pauseTimeCounter < 240) {
            this.pauseTimeCounter++;
            return;
        }
        this.state = this.stateTypes.SCROLL;
        this.pauseTimeCounter = 0;
    }
    this.div.scrollTop += this.step;
    if (this.div.scrollTop >= this.div.scrollHeight - this.div.offsetHeight) {
        this.div.scrollTop = 0;
    }
    sectionHeight = this.div.offsetHeight * 2;
    scrollTop = this.div.scrollTop;
    if (scrollTop % sectionHeight == 0) {
        this.state = this.stateTypes.PAUSE;
    }
}
InfoBox.prototype.halt = function(isHalted) {
    if (isHalted) {
        this.oldState = this.state;
        this.state = this.stateTypes.HALT;
    } else {
        this.state = this.oldState;
    }
}

var banner;
var banners;
var infoBox;        
var timeCounter;


function init()
{
    banners = new Array
    (
        new Banner("africanancestrydnatesting.gif", "African Ancestry DNA Testing", "africanancestrydnatesting.php"),
        new Banner("ic3exodusbanner11.gif", "iC3tv Exodus", "exodus.htm"),
        new Banner("ic3adoptionbanner.gif", "iC3tv Adoption", "adoption.htm"),
        //new Banner("uncef_banners.jpg", "", ""),
        //new Banner("ic3phonebanner.gif", "", ""),
        ////new Banner("ic3talkbanner8.gif", "iC3 Talk", "talk.html"),
        new Banner("ic3macthmaker_banner.gif", "iC3 Match Maker", "match.htm"),
        //new Banner("FixMyRatesbanner.jpg", "", ""),
        new Banner("ic3homecarebanne1r.gif", "iC3 Home Care", "homecareinfo.htm"),
        ////new Banner("ic3talkbanner.gif", "iC3 Talk", "talk.html"),
        //new Banner("unicefbannere.jpg", "", ""),
        new Banner("ic3macthmaker_banner.gif", "iC3 Match Maker", "match.htm"),
        //new Banner("cabanner1.gif", "", ""),
        new Banner("ic3donorsbanner.gif", "iC3 Donors", "donor.htm"),
        ////new Banner("ic3talkbanner2.gif", "iC3 Talk", "talk.html"),
        //new Banner("ringtone_banner.jpg", "", ""),
        new Banner("ic3exodusbanner.gif", "iC3tv Exodus", "exodus.htm"),
        new Banner("ic3donorbanner8.gif", "iC3 Donors", "donor.htm"),
        new Banner("ic3homecarebanner.gif", "iC3 Home Care", "homecareinfo.htm"),
        new Banner("ic3carebanner.gif", "iC3 Home Care", "homecareinfo.htm")
    )
    
    banner = banners[0];
    banner.setImage();

    var programmSelection = document.getElementById("programmSelection");
    if (programmSelection) {
        programmSelection.scrollTop = getCookie('programmSelectionPos');
        infoBox = new InfoBox();
        init2();
    }

    timeCounter = 0;
    window.setTimeout('timerLoop()', 50); 
}

function deinit()
{
    var programmSelection = document.getElementById("programmSelection");
    if (programmSelection) {
        var expires = new Date();
        expires.setTime(expires.getTime() + 3600000 * 24 * 1);
        setCookie('programmSelectionPos', programmSelection.scrollTop, expires);
    }
    
}

function timerLoop() {
    timeCounter++;
    if (infoBox) {
        infoBox.animate();
    }
    if (timeCounter % 1000 == 0) {
        banner = banners[Math.floor(Math.random() * (banners.length))];
        banner.setImage();
    }
    window.setTimeout('timerLoop()', 10); 
}

function startPlayback(file) {
    player2 = document.getElementById("player2");
    if (player2) {
        // page needs reloading
        return;
    }
    msplayer = document.getElementById("player");
    msplayer.URL= file;
}

function stopPlayback() {
    player = document.getElementById("player");
    player.controls.Pause();
}

function pausePlayback() {
    player = document.getElementById("player");
    player.controls.Pause();
}

    /*
    player.PlayState;
	player.controls.CurrentPosition;
	player.controls.Duration;
	*/

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        (expires ? "; expires=" + expires.toGMTString() : "") +
        (path ? "; path=" + path : "") +
        (domain ? "; domain=" + domain : "") +
        (secure ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) {
            return null;
        }
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function delCookie(name, path, domain)
{
    if (getCookie(name)) {
        var date = new Date("January 01, 2000 00:00:01");
        setCookie(name, "", date, path, domain);
    }
}

function loadWindow(url) 
{
    document.location = url;
}