( PowerUp = function()
{
    this.POWERUPUNIDIRECIONAL = 1;
    this.POWERUPBIDIRECIONAL = 2;
    this.POWERUPCROSS = 3;
    this.POWERUPESPIRAL = 4;
    this.POWERUPLWAVE = 5;
    this.POWERUPMAGNET = 6;

    this.table = null;
    this.denyLeft = null;
    this.denyRight = null;
    this.denyBottom = null;

    this.level = 1;
    this.type = 0;
    this.superPowers = undefined;
    this.cooldown = 0;
    this.lastPop = 0;

    this.init = function( $table, $type, $level, $superPower )
    {
        this.type = $type;
        this.level = $level;
        this.table = $table;

        this.superPowers = $superPower.superPowers;
        this.cooldown = $superPower.cooldown;
        this.denyLeft = $superPower.denyLeft;
        this.denyRight = $superPower.denyRight;
        this.denyBottom = $superPower.denyBottom;

        if ( this.superPowers == null )
        {
            var stop = 0;
        }


    }

    this.pop = function()
    {
        lastPop = Tools.getNow();
    }

    this.getRandomSuperPower = function( $pos )
    {
        if ( $pos == null )
        {
            return this.superPowers[Math.floor( Math.random() * this.superPowers.length )];
        }
        else
        {
            //return 1;
            var arr = new Array();
            for ( var i = 0; i < this.superPowers.length; i++ )
            {
                var sp = this.superPowers[i];
                var deny = false;

                if ( $pos.x == 0 ) deny = deny || ( this.denyLeft != null && this.denyLeft.indexOf( sp ) > -1 );
                if ( $pos.x == this.table.tableWidth - 1 ) deny = deny || ( this.denyRight != null && this.denyRight.indexOf( sp ) > -1 );
                if ( $pos.y == this.table.tableHeight - 1 ) deny = deny || ( this.denyBottom != null && this.denyBottom.indexOf( sp ) > -1 );

                if ( !deny )
                {
                    arr.push( sp );
                }

            }
            return arr[Math.floor( Math.random() * arr.length )];
        }
    }

    this.isOnCooldown = function()
    {
        return ( Tools.getNow() - this.lastPop ) < this.cooldown;
    }

    this.clone = function()
    {
        var p = new PowerUp()
        p.init( this.table, this.type, this.level, new SuperPower( this.superPowers, this.cooldown, this.denyLeft, this.denyRight, this.denyBottom ) );
        return p;
    }

} );