var gSpriteId = 0;

function Sprite()
{
    this.x = 0;
    this.y = 0;
    this.speedX = 0;
    this.speedY = 0;
    this.speedMax = 2;
    this.opacity = 100;
    this.gravity = .1;
    this.fadeStep = 3;
    this.elm = document.getElementById("sprite" + gSpriteId++);
}

Sprite.prototype.show = function()
{
    this.elm.style.display = "block";
    this.opacity = 100;
}

Sprite.prototype.hide = function()
{
    this.elm.style.display = "none";
}

Sprite.prototype.move = function()
{
    this.speedY += this.gravity;
    this.limitSpeed();
    this.x += this.speedX;
    this.y += this.speedY;
}

Sprite.prototype.limitSpeed = function()
{
    if (this.speedX < -this.speedMax) {
        this.speedX = -this.speedMax;
    }
    else if (this.speedX > this.speedMax) {
        this.speedX = this.speedMax;
    }

    if (this.speedY < -this.speedMax) {
        this.speedY = -this.speedMax;
    }
    else if (this.speedY > this.speedMax) {
        this.speedY = this.speedMax;
    }
}

Sprite.prototype.render = function()
{
    this.elm.style.MozOpacity = this.opacity / 100;
    this.elm.style.filter = "alpha(opacity= " + this.opacity + ")";
    this.elm.style.left = Math.floor(this.x) + "px";
    this.elm.style.top = Math.floor(this.y) + "px";
}
