
var maxEnergy=5000;

var EnergyMeter = function(name) {
    this.energyMeter=$("#"+name+"energy");
    this.emptyCallback=function() {};

    this.initialize = function() {
        this.energy = maxEnergy;
        this.energyMeter.css('width', Math.floor(this.energy / maxEnergy * 100) + "%");
    }

    this.reduce = function( amount ) {
        this.energy=Math.max(0,this.energy-amount);
        this.energyMeter.css('width', Math.floor(this.energy / maxEnergy * 100) + "%");
        if(this.energy == 0) { this.emptyCallback(); }
    }

    this.empty = function(callback) {
        this.emptyCallback=callback;
    }

}
