
var UT_cool_IMG = '/images/cool.gif';
var UT_cool_IMG_HOVER = '/images/cool_removed.gif';
var UT_cool_IMG_HALF = '/images/cool_hover.gif';
var UT_cool_IMG_BG = '/images/cool_removed.gif';
var UT_cool_IMG_REMOVED = '/images/cool_removed.gif';
var i;

function UTcool(coolElementId, maxcool, objectName, formName, coolMessageId, componentSuffix, size)
{
	this.coolElementId = coolElementId;
	this.maxcool = maxcool;
	this.objectName = objectName;
	this.formName = formName;
	this.coolMessageId = coolMessageId
	this.componentSuffix = componentSuffix

	this.coolTimer = null;
	this.coolCount = 0;

	if(size=='S') {
		UT_cool_IMG      = '/images/cool.gif'
		UT_cool_IMG_HALF = '/images/cool.gif'
		UT_cool_IMG_BG   = '/images/cool_removed.gif'
	}
	
	// pre-fetch image
	(new Image()).src = UT_cool_IMG;
	(new Image()).src = UT_cool_IMG_HALF;

	function showcool(coolNum, skipMessageUpdate) {
		this.clearcoolTimer();
		this.greycool();
		this.colorcool(coolNum);
		if(!skipMessageUpdate)
			this.setMessagecool(coolNum);
	}

	function setMessagecool(coolNum) {
		messages = new Array("Ajoutez à vos favoris", "Ajoutez à vos favoris", "Nada de especial");
		document.getElementById(this.coolMessageId).innerHTML = messages[coolNum];
	}

	function colorcool(coolNum) {
		for (var i=0; i < coolNum; i++)
			document.getElementById('cool_'  + this.componentSuffix + "_" + (i+1)).src = UT_cool_IMG;
	}

	function greycool() {
		for (var i=0; i < this.maxcool; i++)
			if (i <= this.coolCount)
				document.getElementById('cool_' + this.componentSuffix + "_"  + (i+1)).src = UT_cool_IMG_BG; // UT_cool_IMG_REMOVED;
			else
				document.getElementById('cool_' + this.componentSuffix + "_"  + (i+1)).src = UT_cool_IMG_BG;
	}

	function setcool(coolNum) {
		this.coolCount = coolNum;
		this.drawcool(coolNum);
		document.forms[this.formName]['cool'].value = this.coolCount;
		var coolElementId = this.coolElementId;
		postForm(this.formName, true, function (req) { replaceDivContents(req, coolElementId); });
	}


	function drawcool(coolNum, skipMessageUpdate) {
		this.coolCount=coolNum;
		this.showcool(coolNum, skipMessageUpdate);
	}

	function clearcool() {
		this.coolTimer = setTimeout(this.objectName + ".resetcool()", 300);
	}

	function resetcool() {
		this.clearcoolTimer();
		if (this.coolCount)
			this.drawcool(this.coolCount);
		else
			this.greycool();
		this.setMessagecool(0);
	}

	function clearcoolTimer() {
		if (this.coolTimer) {
			clearTimeout(this.coolTimer);
			this.coolTimer = null;
		}
	}

	this.clearcool = clearcool;
	this.clearcoolTimer = clearcoolTimer;
	this.greycool = greycool;
	this.colorcool = colorcool;
	this.resetcool = resetcool;
	this.setcool = setcool;
	this.drawcool = drawcool;
	this.showcool = showcool;
	this.setMessagecool = setMessagecool;

}