/**
 *  Easy mouseover rating
 *
 * @package	net.hawkes.userrating
 * @author	Oliver Kliebisch
 * @copyright	2008 Oliver Kliebisch
 * @license	Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported <http://creativecommons.org/licenses/by-nc-nd/3.0/>
 */

function UserRating(elementName, currentRating) {
	this.elementName = elementName;
	this.currentRating = currentRating;

	this.init = function() {
		var span = document.getElementById(this.elementName + 'Span');
		if (span) {		
			for (var i = 1; i <= 5; i++) {
				var star = document.createElement('img');
				star.src = RELATIVE_WBB_DIR+'icon/noRatingS.png';
				star.alt = '';
				star.rating = this;
				star.name = i;
				star.onmouseover = function() { this.style.cursor = 'pointer'; this.rating.showRating(parseInt(this.name)); };				
				span.appendChild(star);
			}
					
			span.rating = this;			
						
			span.className = '';
		}
		
		if (this.currentRating > 0) {
			this.showCurrentRating();
		}
	}
	
	this.showCurrentRating = function() {
		this.showRating(this.currentRating);
	}
	
	this.showRating = function(rating) {
		var input = document.getElementById(this.elementName);
		input.value=rating;
		var span = document.getElementById(this.elementName + 'Span');
		if (span) {
			for (var i = 1; i <= rating; i++) {
				if (span.childNodes[i - 1]) {
					span.childNodes[i - 1].src = RELATIVE_WBB_DIR+'icon/ratingS.png';
				}
			}
			
			
			for (var i = rating + 1; i <= 5; i++) {
				if (span.childNodes[i - 1]) {
					span.childNodes[i - 1].src = RELATIVE_WBB_DIR+'icon/noRatingS.png';
				}
			}
		}
	}
	

	
	this.init();
}