//-------------------------------------------------------------------//
/* Vote Handler */
//-------------------------------------------------------------------//

var voteHandler = Class.create();
voteHandler.prototype = {

	//-------------------------------------------------------------------//

	initialize: function() {
		this.aid = 0;
		this.parent = null;
	},

	//-------------------------------------------------------------------//

	doVote: function(aid,num) {
		this.ajaxVote(aid,num);
	},

	//-------------------------------------------------------------------//

	ajaxVote: function(aid,num) {
		this.aid = aid;
		this.parent = $(aid+'-stars');

		var ajax = new Ajax.Request(
											'/ajax',
											{
												method: 'post',
												parameters: 'aid='+aid+'&num='+num+'&vote=1',
												onComplete: this.ajaxVoteComplete.bindAsEventListener(this)
											}
											);
	},

	//-------------------------------------------------------------------//

	ajaxVoteComplete: function(o) {
		if(o.responseText > 0) {
			$('a-vote-num').update(parseInt($('a-vote-num').innerHTML) + 1);
			Element.update(this.parent,'<li class="current-rating" style="width:'+(o.responseText * 20)+'%;">'+o.responseText+'</li>');
			dialogHND.showVoteDialog();
		}
	}

	//-------------------------------------------------------------------//

}

//-------------------------------------------------------------------//
