    (function($){
        var wsCalc = {
            configs: {
                type: {
                    moto: 1400,
                    lt15 : 1400,
                    gt15lt20 : 1500,
                    gt20: 2000
                },
                perKm: 30,
                perHour: 500,
                perWheel: 300
            },
            defaults: {
                type: 'moto',
                km: 0,
                hours: 0,
                wheels: 0
            },
            getVar: function(v, r) {
                var r = r ? r :$('#ws-'+v).val();
                switch(v) {
                    case 'type' :
                        r = (this.configs.type[r] != undefined) ? r : this.defaults.type;
                    break;
                    case 'hours':
                    case 'km':
                    case 'wheels':
                        r = parseInt(r);
                        if ( isNaN(r) || r < 0 ) {
                            r = this.defaults[v];
                        }
                    break;
                }
                return r;
            },
            calc: function() {
                var c = wsCalc.configs;

                var r = 0;
                r += c.type[this.getVar('type')];
                r += this.getVar('km') * c.perKm;
                r += this.getVar('wheels') * c.perWheel;
                r += this.getVar('hours') * c.perHour;

                $('#ws-result').html(r + ' руб.');
            },
            init: function() {
                $.each(this.defaults, function(i ,v){
                    $('#ws-'+i).val(v);
                });

                $('#ws-calc').delegate('input, select', 'change keyup', function() {
                    wsCalc.calc();
                }).delegate('.ws-input-up, .ws-input-dwn', 'click', function(){
                    var f = $(this).parent().find('input');
                    var r = wsCalc.getVar(/ws-([a-z]+)-.*/.exec($(this).attr('id'))[1], f.val());

                    if ($(this).hasClass('ws-input-up')) {
                        f.val(r+1);
                    } else {
                        f.val(r>0?(r-1):0);
                    }

                    wsCalc.calc();
                });

            }
        };
        $(function(){

            wsCalc.init();
        });
    })(jQuery);
