
var Computer = function() {
    this.thumb=new Thumb("t");
    this.lockCallback=function () {};
    this.thumb.lock(bind(this, 'lockCallback'));

    this.energyMeter = new EnergyMeter("computer");
    this.pinnedCallback=function() {};
    this.energyMeter.empty( bind(this, 'pinnedCallback') );


    this.computerMoveTimer = $.timer( 10000, bind(this, 'computerMove') );
    this.computerMoveTimer.stop();

    this.initialize = function (level) {
        this.level=level;
        this.thumb.reset();
        this.energyMeter.initialize();
    }

    this.getComputerResponseTime = function () {
//        return Math.floor(Math.random() * 500) + 500;
        return Math.floor(Math.random() * this.level.delay)
            + this.level.responseTime;
    }

    this.computerMove = function () {
        var position=null;
        if(Math.floor( Math.random() * (5-this.level.aggression))==0) {
            var thumb_pos=$(".thumb_pos:visible").filter(function(index) {
                return $(this).attr('id').substring(0,1)=='b';
            });
            var position=$("#"+$(thumb_pos).attr('id').substring(1,3));
        }
        if(position==null || position.attr('id')==this.thumb.position.attr('id')) {
            var positions=$(".position").not("#"+this.thumb.position.attr('id'));
            position=positions[ Math.floor( Math.random() * positions.length ) ];
        }
        this.thumb.move( $(position) );
    }

    this.stop = function() {
        this.computerMoveTimer.stop();
    }

    this.start = function() {
        this.computerMoveTimer.reset( this.getComputerResponseTime() );
    }

    this.lock = function(callBack) {
        this.lockCallback=callBack;
    }

    this.reduceEnergy = function( damage ) {
        this.energyMeter.reduce(damage);
    }

    this.pinned = function(callback) {
        this.pinnedCallback=callback;
    }

  
}

