

function RecordRating(objectName, starIdPrefix, fullImage, emptyImage, defaultCount) {
    //create a RecordRating object:
    // Usage = var r = new RecordRating(...);

    this.starIdPrefix = starIdPrefix;
    this.fullImage = fullImage;
    this.emptyImage = emptyImage;
    this.objectName = objectName;
    this.maxStars = 5;
    this.starTimer = null;
    this.defaultCount = defaultCount;

    // pre-fetch image
    (new Image()).src = fullImage;
    (new Image()).src = emptyImage;

    function showStars(starNum) {
        this.clearStarTimer();
        this._showStars(starNum);
    }
    function _showStars(starNum) {
        for (var i=1; i <= this.maxStars; i++)  {
            var element = getElementById(this.starIdPrefix + i)
            if (i <= starNum)
                element.src = this.fullImage;
            else
                element.src = this.emptyImage;
        }
    };

    function clearStars() {
        this.starTimer = setTimeout(this.objectName + ".resetStars()", 300);
    }

    function resetStars() {
        this.clearStarTimer();
        this._showStars(this.defaultCount);
    }

    function clearStarTimer() {
        if (this.starTimer) {
            clearTimeout(this.starTimer);
            this.starTimer = null;
        }
    }

    //Now make these functions my methods.
    this.showStars = showStars;
    this._showStars = _showStars;
    this.clearStars = clearStars;
    this.clearStarTimer = clearStarTimer;
    this.resetStars = resetStars;
}