
// Yet another way of doing these nameless DOM manipulations!

(function() {
	var init = function() {
		// Rating containers
		$$("div.rating").each(function(rating_container) {
			// Run through all the stars in this container
			rating_container.select("a").each(function(star, link_index) {
				star.observe("mouseover", function() {
					// Run through all the star images
					rating_container.select("a img").each(function(star_image, mouseover_index) {
						// Set the image to on or off, depending on i and index
						star_image.old_src = star_image.getAttribute("src");
						star_image.setAttribute("src", (mouseover_index <= link_index) ? "images/star-on.gif" : "images/star-off.gif");
					});
				});
				star.observe("mouseout", function() {
					// Run through all the star images
					rating_container.select("a img").each(function(star_image) {
						// Set the image to whatever it was before the hover
						star_image.setAttribute("src", star_image.old_src);
						star_image.old_src = undefined;
					});
				});
			});
		});
	};
	
	if (typeof Prototype != "undefined") {
		document.observe("dom:loaded", init);
	}
})();

