var act_rate = 0;
var click_rate = 0;								
var cImgOn = "/img/rating_crown_yellow.gif";
var cImgOff = "/img/rating_crown_grey.gif"


function page_loaded(evt) {
	Event.observe('rating_nodes', 'click', item_clicked, false);
	Event.observe('rating_nodes', 'mouseover', item_over, false);
	Event.observe('rating_nodes', 'mouseout', item_out, false);
}
								
function item_clicked(evt) {
	var child = Event.element(evt);
	var name = child.id;
	click_rate = name.replace('crown', '');
	if($('rating').value != click_rate) {
		$('rating').value = click_rate;
	} else {
		click_rate = 0;
		$('rating').value = 0;
	}
	Event.stop(evt);
}
								
function item_over(evt) {
	var child = Event.element(evt);
	if(child.id != 'rating_nodes') {
		var name = child.id;
		act_rate = name.replace('crown', '');
		for(var i = 1; i <= 5; i++) {
			$('crown'+i).src = (i <= act_rate) ? cImgOn : cImgOff;
		}
	}
	Event.stop(evt);
}

function item_out(evt) {
	var child = Event.element(evt);
	if(child.id != 'rating_nodes') {
		for(var i = 1; i <= 5; i++) {
			$('crown'+i).src = (i <= click_rate) ? cImgOn : cImgOff;
		}
	}
	Event.stop(evt);
}
