/**
 * Кнопка со стоимостью вывоза
 *
 * @property CalcClass calc
 *           калькулятор, к которому относится
 * @property jQuery nodeButton
 *           кнопка с ценой
 * @property jQuery nodeNo
 *           кнопка без цены
 * @property bool showed
 *           цена показана
 * @property string garbageType
 * @property float containerVolume
 * @property bool inttk
 * @property float volume
 */
CalcClass.ButtonClass = go.Class({

    '__construct': (function(calc, nodeButton, nodeNo) {
        this.calc       = calc;
        this.nodeButton = $(nodeButton);
        this.nodeNo     = $(nodeNo);
        this.nodePrice  = this.nodeButton.find(".calcprice");
        this.showed     = false;
        this.nodePrice.click(this.onClickOrder);
    }),
    
    'init': (function() {
        this.garbageType     = this.calc.garbageType.getCurrentType();
        this.containerVolume = this.calc.containers.getCurrentContainer();
        this.inttk  = false;
        this.volume = this.calc.slider.volume;
    }),
    
    /**
     * Показать цену
     */
    'show': (function() {
        if (!this.showed) {
            this.showed = true;
            this.nodeButton.show();
            this.nodeNo.hide();
        }
    }),
    
    /**
     * Спрятать цену
     */
    'hide': (function() {
        if (this.showed) {
            this.showed = false;
            this.nodeButton.hide();
            this.nodeNo.show();
        }
    }),
    
    'onGarbageTypeChange': (function(garbageType) {
        this.garbageType = garbageType;
        this.check();
    }),
    
    'onContainerVolumeChange': (function(containerVolume) {
        this.containerVolume = containerVolume;
        this.check();
    }),
    
    'onMapChange': (function(sect, inttk) {
        this.inttk = inttk;
        this.show();
        this.check();
    }),
    
    'onSliderChange': (function(volume) {
        this.volume = volume;
        this.check();
    }),
    
    'onLoadingChange': (function(checked) {
        this.check();
    }),
    
    'check': (function() {
        var count = Math.ceil(this.volume / this.containerVolume);
        if (this.inttk) {
            this.show();
        }
        this.calc.tonns.set(this.containerVolume, count);
        this.calc.withLoading.setCountContainers(count);
        var loading = this.calc.withLoading.isChecked();
        if (this.showed) {
            var price = new CalcClass.PriceClass(this.garbageType, this.containerVolume, count, loading, this.inttk);
            price.calc();
            this.nodePrice.text(CalcClass.Helper.numberFormat(price.price) + " руб.");
            var details = this.calc.details;
            details.show();
            details.setContainer(this.containerVolume);
            details.setCount(count);
            details.setPerPrice(price.per);
        }
    }),
    
    'onClickOrder_bind': (function(e) {
        this.calc.form.show();
        return false;
    }),

    'eoc': null
});

