// (c) Andrii Vasyliev
// Rating

if (typeof(sol)=="undefined") var sol = new Object();
sol.rating = {
	theid: null,
	oldsrc: [],
	imgnum: null,
	timeout: null,
	stopped: false,
	preload: null,

	init: function (id,num,img) {
		this.theid = id;
		this.imgnum = num;
		this.preload = new Image();
		this.preload.src = img;
		for (var i=1;i<=num;i++)
			this.oldsrc[i] = document.getElementById(id+i).src;
	},

	show: function (cur) {
		if (this.stopped) return;
		clearTimeout(this.timeout);
		this.draw(cur);
	},

	draw: function (cur) {
		for (var i=1;i<=this.imgnum;i++)
			this.eset(i,i<=cur ? this.preload.src : this.oldsrc[i]);
	},

	hide: function () {
		if (this.stopped) return;
		this.timeout = setTimeout("sol.rating.done()",50);
	},

	done: function () {
		if (this.stopped) return;
		for (var i=1;i<=this.imgnum;i++)
			this.eset(i,this.oldsrc[i]);
	},

	stop: function (res) {
		this.stopped = true;
		this.draw(res);
	},

	eset: function (i,s) {
		document.getElementById(this.theid+i).src = s;
	}
};

