var ratingStars = function(formName,ratingId,newRatingId,listItemClassPrefix)
{
	// html references and popup window properties
	this.formElement = (formName && $(formName)) ? $(formName) : $("user_comment_form");
	this.ratingId = (ratingId && $(ratingId)) ? $(ratingId) : $("rating");
	this.newRatingId = (newRatingId) ? newRatingId : "jsRating";
	// Need to consider other changeables. Classes? variable names? That kind of stuff.
	this.listItemClassPrefix = (listItemClassPrefix) ? listItemClassPrefix : "stars";
}
ratingStars.prototype =
{
	initialise:function()
	{
		var objRef = this;
		if(this.ratingId != null) // check we have a link to hang the popup on.
		{
			objRef.buildNewStars();
			this.formElement.onsubmit=function()
			{
				// sanity check here!
			}
		}
	},
	buildNewStars:function()
	{
		var objRef = this;
		var newList = new Element("ul", {"class": this.listItemClassPrefix, "id": this.newRatingId}); // New unordered list.
		for (i=1; i<=5; i++)
		{
			var newSpan = new Element("span");
			newSpan.setText(i + " star" + (i == 1 ? "" : "s"));
			var newAnchor = new Element("a", {"href" : "?rating=" + i, "events": {"click":function(evt){
				new Event(evt).stop();
				objRef.formElement.rating.value = this.href.split("=")[1];
				newList.className = "stars" + this.href.split("=")[1];
//				return false; // Cancel the hyperlink.
			}}});
			// erk, I hope this works okay
			newAnchor.adopt(newSpan);
			var newListItem = new Element("li", {"class": this.listItemClassPrefix + i});
			newListItem.adopt(newAnchor);
			newList.adopt(newListItem);
		}
//		var newSpan = new Element("span", {"class": "stars0", "id": this.starsHolder});
		this.ratingId.replaceWith(newList);
//		newSpan.injectBefore(newList);
		var newHidden = new Element("input", {"type": "hidden", "name" : "rating"});
		this.formElement.adopt(newHidden);
	}
}
