﻿/*
* Controller for the progress bar on the microsite
* Requires prototype and scriptaculous
* Tom Elmore
*/

var ProgressController = Class.create();
ProgressController.prototype =
{
    reachedPage: 0,
    barInner: null,
    numericProgress: null,

    initialize: function() {
        this.totalPages = arguments[0] != null ? arguments[0] : 0;
        this.percentage = 0;

        this.calcPercentage();
    },

    setTotalPages: function(pages) {
        this.totalPages = pages;
    },

    setPB_barInnerId: function(id) {
        this.barInner = $(id);
    },

    setPB_numericProgressId: function(id) {
        this.numericProgress = $(id);
    },

    setPage: function(page) {
        page = page - 1;
        if (this.reachedPage < page) { this.reachedPage = page; }
        this.calcPercentage();
        
        this.barInner.style.width = Math.round((207 / 100) * this.percentage) + "px";
        this.numericProgress.innerHTML = this.percentage + "%";
    },

    calcPercentage: function() {
        if (this.totalPages > 0) {
            this.percentage = Math.round((this.reachedPage / this.totalPages) * 100);
        } else {
            this.percentage = 100;
        }
    }
};

