imgExt = '.gif';

var UT_RATING_IMG = '/images/stars/goldw'+imgExt;
var UT_RATING_IMG_HOVER = '/images/stars/goldw.gif';
var UT_RATING_IMG_HALF = '/img/icn_star_half_19x20'+imgExt;
var UT_RATING_IMG_BG = '/images/stars/greyw'+imgExt;

function UTRating(ratingElementId, maxStars, objectName, formName, formKey, componentSuffix, size)
{
	this.ratingElementId = ratingElementId;
	this.maxStars = maxStars;
	this.objectName = objectName;
	this.formName = formName;
        this.formKey = formKey;
	this.componentSuffix = componentSuffix

	this.starTimer = null;
	this.starCount = 0;

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

	function showStars(starNum, alwaysShow) {
		this.clearStarTimer();
		this.greyStars();
		this.colorStars(starNum);
	}

	function colorStars(starNum) {
		for (var i=0; i < starNum; i++) {
			document.getElementById('star_'  + this.componentSuffix + "_" + (i+1)).src = UT_RATING_IMG;
		}
	}

	function greyStars() {
		for (var i=0; i < this.maxStars; i++)
			if (i <= this.starCount) {
				document.getElementById('star_' + this.componentSuffix + "_"  + (i+1)).src = UT_RATING_IMG_BG;
			}
			else
			{
				document.getElementById('star_' + this.componentSuffix + "_"  + (i+1)).src = UT_RATING_IMG_BG;
			}
	}

	function setStars(starNum) {
		this.starCount = starNum;
		this.drawStars(starNum);
		document.forms[this.formName][this.formKey].value = this.starCount;
		var ratingElementId = this.ratingElementId;
		this.showStars(starNum, 1);
	}


	function drawStars(starNum) {
		this.starCount=starNum;
	}

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

	function resetStars() {
		this.clearStarTimer();
		if (this.starCount) {
			this.drawStars(this.starCount);
			this.showStars(this.starCount);
		} else {
			this.greyStars();
		}
	}

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

	this.clearStars = clearStars;
	this.clearStarTimer = clearStarTimer;
	this.greyStars = greyStars;
	this.colorStars = colorStars;
	this.resetStars = resetStars;
	this.setStars = setStars;
	this.drawStars = drawStars;
	this.showStars = showStars;
}


