/**
 * Copyright (c) 2008-2009 Wydawnictwo Bauer Sp. z o.o., Sp.k. All Rights Reserved
 * Author: Krzysztof Kozłowski, http://www.kozik.net.pl
 *
 * $Id: func_jquery_rate.js 3512 2009-04-23 08:27:00Z kkozlowski $
 *
 * @file
 * @see JQuery
 * @see Rater
 */

/**
 * Setup DIV for rating elements. Requires JQuery.
 *
 * @param		rate_min		int
 * @param		rate_max		int
 * @param		gw_file			string
 * @param		gw_file_sel		string
 */
function setup_jquery_rate(rate_min, rate_max, gw_file, gw_file_sel)
{
	$(document).ready(function() {
		// AJAX na ocenie
		$("#ocena a").click(function(e) {
			// stop normal link click
			e.preventDefault() ;
			$("#ocena").hide() ;
			position = $(this).attr("label") ;
			// send request
			$.post("/ajax.php", {
					"action": rater_action,
					"oid": rater_oid,
					"oname": rater_oname,
					"rc": rater_rc[position],
					"value": position
				}, function(xml) {
					// format and output result
					$("#ocena").show("slow") ;
					$("#ocena").html(xml) ;
				}
			);
		});
		// Podswietlanie gwiazdek
		$("#ocena img").each(function() {
			$(this).hover(
				function() {
					position = $(this).attr("label");
					for(var j=rate_min; j<=position; j++) {
						$("#ocen_i_" + j).attr("src", gw_file_sel) ;
					};
				},
				function() {
					position = $(this).attr("label");
					for(var j=rate_min; j<=position; j++) {
						$("#ocen_i_" + j).attr("src", gw_file) ;
					};
				}
			);
		}) ;
	}) ;
}
