var XT_RATING_IMG = '/images/ratingBlauw.gif';
var XT_RATING_IMG_HALF = '/images/ratingBlauw.gif';
var XT_RATING_IMG_BG = '/images/rating.gif';

function XTRating(ratingElementId, maxStars, objectName, formName) {
	this.ratingElementId = ratingElementId;
	this.maxStars = maxStars;
	this.objectName = objectName;
	this.formName = formName;

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

	function showRatingResult(starNum, message) {
		document.getElementById(this.ratingElementId).style.display='none';
		
		for (var i=1; i <= starNum; i++)
			document.getElementById('result_star_' + i).src = XT_RATING_IMG;
		
		document.getElementById('ratingResultDiv').style.display='block';
		
	}

	function showStars(starNum,starId) {
		this.clearStarTimer();
		for (var i=1; i < this.maxStars + 1; i++)
			document.getElementById('star_' + starId + '_' + i).src = XT_RATING_IMG_BG;
			
		for (var i=1; i <= starNum; i++)
			document.getElementById('star_' + starId + '_' + i).src = XT_RATING_IMG;

	}

	function setStars(starNum) {
		this.starCount = starNum;
		this.clearStarTimer();
		this.showStars(starNum);
		document.forms[this.formName]['rating'].value = this.starCount;
		var ratingElementId = this.ratingElementId;
		makeHttpRequest(this.formName, ratingResXML);
	}

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

	function resetStars() {
		this.clearStarTimer();
		if (this.starCount) {
			this.clearStarTimer();			
			this.showStars(this.starCount);
		} else {
			for (var i=1; i < this.maxStars + 1; i++)
				document.getElementById('star_' + i).src = XT_RATING_IMG_BG;
	
		}
		
	}

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

	this.showRatingResult = showRatingResult;
	this.clearStars = clearStars;
	this.clearStarTimer = clearStarTimer;
	this.resetStars = resetStars;
	this.setStars = setStars;
	this.showStars = showStars;

}

