var RATING_IMG = '/images/star_full.gif';
var RATING_IMG_BG = '/images/star_bg.gif';

function Rating(containingDiv, maxStars, objectName, formName)
{
	//this.ratingElementId = ratingElementId;
		 this.maxStars = maxStars;
		 this.objectName = objectName;
		 this.formName = formName;
		
		 this.starTimer = null;
		 this.starCount = 0;
		
		 // pre-fetch image
		 (new Image()).src = RATING_IMG;
		 (new Image()).src = RATING_IMG_BG;

		function showStars(starNum) {
			 this.clearStarTimer();
			 this.greyStars();
			 this.colorStars(starNum);
		}
		
		function colorStars(starNum) {
			for (var i=0; i < starNum; i++)
			document.getElementById('star_' + (i+1)).src = RATING_IMG;
		}
		
		function greyStars() {
			for (var i=0; i < this.maxStars; i++)
			if (i <= this.starCount)
				document.getElementById('star_' + (i+1)).src = RATING_IMG_BG; // UT_RATING_IMG_REMOVED;
			else
				document.getElementById('star_' + (i+1)).src = RATING_IMG_BG;
		}
		
		function setStars(starNum) {
			this.starCount = starNum;
			this.drawStars(starNum);
			document.forms[this.formName]['rating'].value = this.starCount;
			//var ratingElementId = this.ratingElementId;
			//postForm(this.formName, true, function (req) { replaceDivContents(req, ratingElementId); });
		}
		
		
		function drawStars(starNum) {
			this.starCount=starNum;
			this.showStars(starNum);
		}
		
		function clearStars() {
			this.starTimer = setTimeout(this.objectName + ".resetStars()", 300);
		}
		
		function resetStars() {
			this.clearStarTimer();
			if (this.starCount)
				this.drawStars(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;

}

function rateThanks(id) {
	document.getElementById(id).innerHTML = "<p class='thanks'>Thank you for rating this video</p>";
}