function imagesManager() {
    this._images_count = 0;
    this._done_count = 0;
    this._error_count = 0;

    this._createImage = function(path) {
        this._images_count += 1;
        var img = document.createElement("img");
        that = this
        img.onerror = function() {
            that._error_count += 1;
        }
        img.onload = function() {
            that._done_count += 1;
        }
        img.src = "images/" + path;
        return img;
    }

    this._createStreetWalking = function(isPlayer)
    {
        retVal = [];
        imgPrefix = (isPlayer? "1":"0") + "_";
        folder = "street/";

        retVal[0] = this._createImage(folder + imgPrefix + "0.png");
        retVal[1] = this._createImage(folder + imgPrefix + "1.png");
        retVal[2] = this._createImage(folder + imgPrefix + "2.png");
        retVal[3] = this._createImage(folder + imgPrefix + "3.png");

        return retVal;
    }

    this._createBodyparts = function() {
        var parts_count = 6;
        var parts_variety = [9, 5, 5, 12, 5, 20];

        var parts_path = "bodyparts/"
        var bodyparts = [];
        for(part = 0; part < parts_count; part++) {
            bodyparts[part] = [];
            part_path = parts_path + part + "/";
            for(variety = 0; variety < parts_variety[part]; variety++) {
                full_path = part_path + variety + ".png";
                bodyparts[part].push(this._createImage(full_path));
            }
        }

        return bodyparts;
    }

    this._createButton = function(buttonsBasePath, buttonName) {
        return {
            plain: this._createImage(buttonsBasePath + buttonName + "_plain.png"),
            pressed: this._createImage(buttonsBasePath + buttonName + "_pressed.png"),
            disabled: this._createImage(buttonsBasePath + buttonName + "_disabled.png")
        }
    }
    
    this._createAllButtons = function() {
        buttonsBasePath = "buttons/";
        buttons = {
            wave: this._createButton(buttonsBasePath, "wave"),
            hide: this._createButton(buttonsBasePath, "hide"),
            more: this._createButton(buttonsBasePath, "more"),
            right: this._createImage(buttonsBasePath + "Right.png"),
            wrong: this._createImage(buttonsBasePath + "Wrong.png"),
        };

        return buttons;
    }

    this._createPhoneImages = function()
    {
        retVal = [];

        retVal[FEED_MSG_ADD] = this._createImage("phone/PhoneGood.png");
        retVal[FEED_MSG_LOST] = this._createImage("phone/PhoneNormal.png");
        retVal[FEED_MSG_MORE] = this._createImage("phone/PhoneMove.png");
        retVal[FEED_MSG_BAD] = this._createImage("phone/PhoneBad.png");

        return retVal;
    }

    //Public images
    this.angzayety = this._createImage("angzayety.png");
    this.background = this._createImage("background.png");
    this.bodyparts = this._createBodyparts();
    this.street = this._createImage("up.png");
    this.buttons = this._createAllButtons();
    this.streetPlayerWalking = this._createStreetWalking(true);
    this.streetPersonWalking = this._createStreetWalking(false);
    this.phoneImages = this._createPhoneImages();
    this.startScreenHand = this._createImage("startScreen/hand.png");
    this.startScreenBackgroud = this._createImage("startScreen/background.png");
    this.endScreenHand = this._createImage("endScreen/hand.png");
    this.endScreenBackgroud = this._createImage("endScreen/background.png");
    

    //Public function
    this.isCompleted = function() {
        if(this._error_count) 
            return "error";

        return this._images_count - this._done_count;
    }
}