/*********************************
 SquareAttack - imageManager.js
 Copyright: Marcis Berzins (berzins.marcis@gmail.com), 2013
 This program is licensed under the terms of the GNU General Public License: http://www.gnu.org/licenses/gpl-3.0.txt
 *********************************/

function ImageManager() {
  this.IMAGES = {
    PLAYER_HAPPY: 'images/player_happy.png',
    PLAYER_NEUTRAL: 'images/player_neutral.png',
    PLAYER_ATTACKING: 'images/player_attacking.png',
    PLAYER_DEAD: 'images/player_dead.png',
    ENEMY_NEUTRAL: 'images/enemy_neutral.png',
    ENEMY_ATTACKING: 'images/enemy_attacking.png',
    ENEMY_DEAD: 'images/enemy_dead.png',
    TITLE: 'images/title.png'
  };
  this.loadState = { count: Object.keys(this.IMAGES).length, loaded: 0, ready: false };
  this.init();
}

ImageManager.prototype.init = function() {
  for (var p in this.IMAGES) {
    var i = new Image();
    var that = this;
    i.addEventListener('load', function() {
      that.loadState.loaded++;
      if (that.loadState.loaded >= that.loadState.count) { that.loadState.ready = true; }
    }, false);
    i.src = this.IMAGES[p];
    this[p] = i;
  }
};