if ((navigator.appVersion.indexOf('MSIE') > -1) && (typeof window.XMLHttpRequest == 'undefined')) {
imgExt = '.gif';
}
else
{
//imgExt = '.gif';
imgExt = '.png';
}
var UT_RATING_IMG = 'http://www.tranceproject.com/design/icn_star_full_19x20'+imgExt;
var UT_RATING_IMG_HOVER = 'http://www.tranceproject.com/design/star_hover.gif';
var UT_RATING_IMG_HALF = 'http://www.tranceproject.com/design/icn_star_half_19x20'+imgExt;
var UT_RATING_IMG_BG = 'http://www.tranceproject.com/design/icn_star_empty_19x20'+imgExt;
var UT_RATING_IMG_REMOVED = 'http://www.tranceproject.com/design/star_removed.gif';

function UTRating(lid, ratingElementId1, ratingElementId2, ratingElementId3, ratingElementId4, maxStars, objectName, formName, componentSuffix, size, language)
{
	this.lid = lid;
	this.ratingElementId1 = ratingElementId1;
	this.ratingElementId2 = ratingElementId2;
	this.ratingElementId3 = ratingElementId3;
	this.ratingElementId4 = ratingElementId4;
	this.maxStars = maxStars;
	this.objectName = objectName;
	this.formName = formName;
//	this.ratingMessageId = ratingMessageId
	this.componentSuffix = componentSuffix

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

	if(size=='S') {
		UT_RATING_IMG      = 'http://www.tranceproject.com/design/icn_star_full_11x11.gif'
		UT_RATING_IMG_HALF = 'http://www.tranceproject.com/design/icn_star_half_11x11.gif'
		UT_RATING_IMG_BG   = 'http://www.tranceproject.com/design/icn_star_empty_11x11.gif'
	}
	
	// pre-fetch image
	(new Image()).src = UT_RATING_IMG;
	(new Image()).src = UT_RATING_IMG_HALF;

	function showStars(starNum, skipMessageUpdate) {
		this.clearStarTimer();
		this.greyStars();
		this.colorStars(starNum);
		/*
		if(!skipMessageUpdate)
			this.setMessage(starNum);
			*/
	}

	/*
	function setMessage(starNum) {
		messages_us = new Array("Rate this track", "Poor", "Nothing special", "Worth listening", "Pretty cool", "Awesome!");
		messages_fr = new Array("Notez ce track", "Pauvre", "Rien de spécial", "Mérite l'écoute", "(très) Bien", "Excellent!");
		if(language == 'fr')
		{
			document.getElementById(this.ratingMessageId).innerHTML = messages_fr[starNum];
		}
		else
		{
			document.getElementById(this.ratingMessageId).innerHTML = messages_us[starNum];
		}
	}
	*/

	function colorStars(starNum) {
		for (var i=0; i < starNum; i++) {
			document.getElementById('star'+this.lid+'_'  + 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.lid+'_' + this.componentSuffix + "_"  + (i+1)).src = UT_RATING_IMG_BG;
			}
			else
			{
				document.getElementById('star'+this.lid+'_' + this.componentSuffix + "_"  + (i+1)).src = UT_RATING_IMG_BG;
			}
	}

	function setStars(starNum) {
		var inner = document.getElementById('ratingS'+this.lid);
		inner.innerHTML = "<img src=http://www.tranceproject.com/design/ico_spin.gif>";
		
		this.starCount = starNum;
		this.drawStars(starNum);
		document.forms[this.formName]['rtrk_rating'].value = this.starCount;
		var ratingElementId1 = this.ratingElementId1;
		
		postForm(this.formName, true, function (req) { replaceDivContents4(req, ratingElementId1, ratingElementId2, ratingElementId3, ratingElementId4); });
	}

	function removeStars() {
		var inner = document.getElementById('ratingS'+this.lid);
		inner.innerHTML = "<img src=http://www.tranceproject.com/design/ico_spin.gif>";
	
		this.starCount = 0;
		document.forms[this.formName]['rtrk_rating'].value = this.starCount;
		var ratingElementId1 = this.ratingElementId1;
		postForm(this.formName, true, function (req) { replaceDivContents4(req, ratingElementId1, ratingElementId2, ratingElementId3, ratingElementId4); });
		this.drawStars(0);
	}

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

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

	function resetStars() {
		this.clearStarTimer();
		if (this.starCount)
			this.drawStars(this.starCount);
		else
			this.greyStars();
		//this.setMessage(0);
	}

	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.removeStars = removeStars;
	this.drawStars = drawStars;
	this.showStars = showStars;
	//this.setMessage = setMessage;

}



