CloneInterfaceUpdater = {

    update: function(field, value, add) {
        field = $('#interface_'+field);
        if(field.attr('src')){
            field.attr('src', value);
            return;
        }
        if (field.length == 0)
            return false;
        if (add) {
            field_value = Number(field.html());

            if (isNaN(field_value)) {
                field_value = 0;
            }

            value = field_value + value;
        }
        field.html(value);
        if(field.attr('id') == 'interface_gold' || field.attr('id') == 'interface_altin' ){
            $('.'+field.attr('id')).html(value);
        }
        return value;
    },
    
    createEmptyLi: function () {
        var el = document.createElement('li');
        el.innerHTML = 'Отсутствует';
        el.id = 'empty_li';
        el.className = 'empty_li';
        return el;
    },

    redrawAllHolders: function() {
        return;
        var skip = true;
        var parent = this;
        $("div.add_list ul").each(function(){
            if (!skip) {
                var zebra = false;
                var visible = 0;
                $(this).children('.empty_li').remove();
                $(this).find('li').each(function(){
                    /*
                    if ($(this).attr('id') == 'empty_li') {
                        $(this).remove();
                    }
                    */
                    if ($(this).find('dfn').html()!=0) {
                        visible++;
                        $(this).css({'display':'block'});
                        if (zebra) {
                            $(this).addClass('zebra');
                        } else {
                            $(this).removeClass('zebra');
                        }
                        zebra = !zebra;
                    } else {
                        $(this).css({'display':'none'});
                        //visible--;
                    }
                })                
                if (visible <= 0) {
                    $(this).append(parent.createEmptyLi());
                }
            } else {
                skip = false;
            }
        });
    },

    updateResource: function(resource_type, value, add) {
        this.update('resource_' + resource_type, value, add);
        this.redrawAllHolders();
    },

    updateObject: function(obj) {        
        $.each(obj, function(field,value){
            CloneInterfaceUpdater.update(field, value);
        });
        /*
        $.each(obj.resources, function(type, value){
            CloneInterfaceUpdater.updateResource(type, value, 0);
        });

        var tmp='';
        $.each(obj.education, function (type, name){
            if (!isNaN(type)) {
                tmp += '<li><img alt="'+name+'" src="/i/education/'+type+'.gif"/> '+name+'</li>';
            } else {
                tmp += '<li><img alt="'+name+'" src="/i/'+type+'.gif"/> '+name+'</li>';
            }
        });
        $('ul#clone_education').html(tmp);

        tmp='';
        $.each(obj.job, function (ico, name){
            tmp += '<li><img alt="'+name.replace(/<.*?>/g,'')+'" src="'+ico+'" width="21"/> '+name+'</li>';
        });
        $('ul#clone_job').html(tmp);

        this.redrawAllHolders();
        */
    },

    updateStatus : function(value, add){
        this.update('status', value, add)
    },

    updateGold : function(value, add) {
        this.update('gold', value, add)
        this.update('gold_1', value, add)
    },

    updateAltin : function(value, add) {
        this.update('altin', value, add)
    },

    updateCharisma: function(value, add) {
        this.update('charisma', value, add)
    },

    updateDiscretion: function(value, add) {
        this.update('discretion', value, add)
    },

    updateExerience: function(value, add) {
        this.update('experience', value, add)
    },

    updateEfficiency: function(value, add) {
        this.update('efficiency', value, add)
    },

    updateHealth: function(value, add) {
        this.update('health', value, add)
    },

    updateSost: function(value, add) {
        this.update('sost', value, add)
    },

    updateSocial: function(value, add) {
        this.update('social', value, add)
    },


    updateWoodcutting: function(value, add) {
        this.update('woodcutting', value, add)
    },

    updateAgronoming: function(value, add) {
        this.update('agronoming', value, add)
    },

    updateStoneMining: function(value, add) {
        this.update('stone_mining', value, add)
    },

    updateOreMining: function(value, add) {
        this.update('ore_mining', value, add)
    },

    updateLogistics: function(value, add) {
        this.update('logistics', value, add)
    },

    updateCutting: function(value, add) {
        this.update('cutting', value, add)
    },

    updateJeweller: function(value, add) {
        this.update('jeweller', value, add)
    },

    updateMedicine: function(value, add) {
        this.update('medicine', value, add)
    },

    updateSmithy: function(value, add) {
        this.update('smithy', value, add)
    },

    updateSeaman: function(value, add) {
        this.update('seaman', value, add)
    },

    setCloneName: function (name) {
        $('.active_clone_name').html(name);
    }
}