/** javascript implementation for rate page form **/

$(document).ready(function() {

	var base = $("#pageRating");
	var labelSpan = $("<div class='label'></div>");
	
	$("form", base).addClass("jsEnabled");
	$("form", base).append(labelSpan);
	labelSpan.html($(".expl", base).html());
	
	// hide each value and add new behaviours to it
	$(".value", base).each(function() {
		$("*", this).hide();
		$(this).addClass("star");
		
		$(this).hover(starActive);
		$(this).click(submitForm);
	});
	
	
	/** 
	 *	This function submits the form to the server.
	 */
	function submitForm() {
		$("form", base).submit();
	}
	
	/** 
	 *	This function changes a number of CSS elements and 
	 *  labels that need to happen when a different star has
	 *  become active.
	 */
	function starActive() {
		// remove the class
		$(".value", base).removeClass("active");

		// change the rating to the current star
		$(this).addClass("active");
		$(this).prevAll(".value").addClass("active");
		$("input", this).attr("checked", "checked");
		$(labelSpan).html($("span", this).html());
	}

});

