$(document).ready(function () {
	function getCurrentRating($rtp) {
		return parseInt($("> INPUT[type='radio']:checked", $rtp).val(), 10);
	}
	function resetImages($rtp) {
		var currentRating = getCurrentRating($rtp);
		$("> INPUT[type='radio']", $rtp).each(function () {
			var $radio = $(this);
			var $image = $radio.data("image");
			var v = parseInt($radio.val());
			var imageSource = "";
			if (v <= currentRating)
				imageSource = $image.data("image-src-on");
			else
				imageSource = $image.data("image-src-off");
			$image.attr("src", imageSource);
		});
	}
	$(".rateThisPage").each(function () {
		var $rateThisPage = $(this);
		var imageOnSrc = $rateThisPage.data("image-on");
		var imageOffSrc = $rateThisPage.data("image-off");
		$("> INPUT[type='radio']", $rateThisPage).each(function () {
			var $radio = $(this);
			var $image = $("<img />")
			$image.data("image-src-on", imageOnSrc);
			$image.data("image-src-off", imageOffSrc);
			$image.click(function () {
				$radio.click();
				resetImages($rateThisPage);
			});
			$radio.data("image", $image);
			$radio.after($image);
			$radio.hide();
			$("LABEL[for='" + $radio.attr("id") + "']").hide();
		});
		resetImages($rateThisPage);
	});
});
$(document).ready(function()
{
	function convertTDtoTH()
	{
		var td = this;
		var $th = $("<th></th>").html($(td).html());
		$.each(this.attributes, function(index) {
			$th.attr(td.attributes[index].name, td.attributes[index].value);
		});
		$(td).after($th).remove();
	}
	$("TABLE").each(function()
	{
		var $table = $(this);
		var $rows = $(">TR, >TBODY>TR", $table);
		$rows.filter("TR:even").addClass("odd");
		$rows.filter("TR:odd").addClass("even");
		if($table.parents("DIV.checkbox").length > 0)
			return;
		if($table.hasClass("atoz"))
			return;
		if($table.hasClass("no-colour"))
			return;
		if($(">THEAD", $table).length > 0)
			return;
		var $firstRow = $rows[0]; //$(">TR", $(this));
		if($firstRow.length == 0)
			return;
		if($(">TH", $firstRow).length == 0)
		{
			$(">TD", $firstRow).each(convertTDtoTH);
		}
	});
});
