function Heart()
{
    var $heart = $('#heart');
    var $wave = $('#wave');
    
    var pos = $heart.position();
    this.x = pos.left;
    this.y = pos.top;
    this.width = $heart.width();
    this.height = $heart.height();
    this.halfWidth = Math.round(this.width / 2);
    this.halfHeight = Math.round(this.height / 2);
    
    this.active = true;
    
    var heartScale = 1;
    var waveScale = 1;
    var waveScaleEnd;
    
    var opening = false;
    var pumping = false;
    
    var self = this;
    
    this.open = function ()
    {
        if (self.active && !pumping)
        {
            opening = true;
        }
    }
    
    this.pump = function ()
    {
        if (self.active && !pumping)
        {
            pumping = true;
            opening = false;
            waveScale = 1;
            waveScaleEnd = heartScale * 2;
            heartScale = 1;
            $wave.show();
        }
    }
    
    this.destroys = function (whitecell)
    {
        if (pumping)
        {
            if
            (
                Math.abs((whitecell.x + whitecell.halfWidth) - (heart.x + heart.halfWidth)) < 25 * waveScale
                && Math.abs((whitecell.y + whitecell.halfHeight) - (heart.y + heart.halfHeight)) < 25 * waveScale
            )
            {
                return true;
            }
        }
        
        return false;
    }

    this.isDestroyedBy = function (whitecell)
    {
        if (!pumping)
        {
            if
            (
                Math.abs((whitecell.x + whitecell.halfWidth) - (heart.x + heart.halfWidth)) < 27 * heartScale
                && Math.abs((whitecell.y + whitecell.halfHeight) - (heart.y + heart.halfHeight)) < 27 * heartScale
            )
            {
                return true;
            }
        }
        
        return false;
    }
    
    this.die = function ()
    {
        opening = false;
        pumping = false;
        self.active = false;
        $heart.css('background-position', 'bottom left');
    }

    this.move = function ()
    {
        if (opening)
        {
            heartScale += 0.05;
        }
        else if (pumping)
        {
            waveScale += 0.15;
            
            if (waveScale >= waveScaleEnd)
            {
                $wave.hide();
                pumping = false;
            }
        }
    }
    
    this.draw = function ()
    {
        $heart.scale(heartScale);
        
        if (pumping)
        {
            $wave.scale(waveScale);
            $wave.css('opacity', 1 - (waveScale / waveScaleEnd));
        }
    }
}