
function Voting2(params)
{
	this.params = params;
	this.params.vid = (this.params.vid ? this.params.vid : 'voting');
	this.params.color = (this.params.color ? this.params.color : 'red');

	//===================================================

	this.select_star = function (star)		// mouse over event
	{
		for(i=star+1;i<5;i++) $("img#"+this.params.vid+"_star"+i).attr("src", "/img/star_gray.gif");
		for(i=0;i<star+1;i++) $("img#"+this.params.vid+"_star"+i).attr("src", "/img/star_"+this.params.color+".gif");
	}

	//===================================================

	this.set_star = function ()		// mouse out event
	{
		//alert(this.params.vote);

		if(this.params.vote) var curvote = Math.round(this.params.vote/20);
		else curvote = 0;

		for(i=0; i<curvote; i++) $("img#"+this.params.vid+"_star"+i).attr("src", "/img/star_"+this.params.color+".gif");
		for(i=curvote; i<5; i++) $("img#"+this.params.vid+"_star"+i).attr("src", "/img/star_gray.gif");
	}

	//===================================================

	this.submit_vote = function(vote)
	{
		this.params.vote = vote;
		var p = this.params;
		xsubmit("voting2", p.elem_type+"=" + p.elem_id + "&vid="+p.vid + "&vote="+vote + (p.update ? "&update="+p.update : "") + (p.total ? "&total="+p.total : "") + (p.gridpos ? "&gridpos="+p.gridpos : ""));
	}

	//===================================================

	this.draw = function()
	{
		var ccolor = this.params.color;
		if(this.params.vote) var curvote = Math.round(this.params.vote/20);
		else var curvote = 0;

		var html = "<table cellspacing=0 cellpadding=0><tr><td width=85px>";
		for(i=0;i<5;i++)
		{
			if(i >= curvote) ccolor = "gray";
			if(this.params.readonly) html += "<img src='/img/star_"+ccolor+".gif' id='"+this.params.vid+"_star"+i+"'>";
			else html += "<img src='/img/star_"+ccolor+".gif' id='"+this.params.vid+"_star"+i+"' onmouseover='"+this.params.vid+".select_star("+i+")' onmouseout='"+this.params.vid+".set_star();' onclick='"+this.params.vid+".submit_vote("+((i+1)*20)+");'>";
		}
		html += "<td>";
		var fc = new Number(this.params.common/20);
		html += "<span id='"+this.params.vid+"_common' class='voting_common'> "+fc.toPrecision(2)+" </span>";
		html += "<small id='"+this.params.vid+"_total'>"+this.params.total+(this.params.total==1 ? " vote" : " votes")+"</small>";
		html += "</td></tr></table>";
		$("div#"+this.params.vid).append(html);
	}
} 


