
function rat() {
	
	// _state is the current hovered star icon
	this.change = function(_state) {
	
		var i = 1;
		
		var color = new Array(5);
		color[0] = "grey";
		color[1] = "red";
		color[2] = "orange";
		color[3] = "yellow";
		color[4] = "lightgreen";
		color[5] = "green";	
				
		
		// Display colored stars (amount is the current _state)
		if(_state != 0) {
			
			while(i <= _state) {
				getById("id_" + i).src = iconPath + "/favorites_" + color[i] + "_16.png";
				i++;
			}
		}
		
		// Here we finish missing stars with grey stars
		while(i <= 5) {
			getById("id_" + i).src = iconPath + "/favorites_" + color[0] + "_16.png";
			i++;
		}
	}
	
	// Rate (Does a new ajax request)
	this.rate = function(_module, _field, _objId, _state) {
		
		setChecked();
		
		var request = new AjaxRequest(pathPrefix + "/Ajax/ratRate", false, true);
		request.callFunction = this.reload;
		
		request.setPostvars("module=" + _module + "&field=" + _field + "&objId=" + _objId + "&state=" + _state + sid2);
		request.doRequest();

		return false;
	}
	
	// Disable voting functionality
	function setChecked() {
		var i = 1;
		while(i <= 5) {
			getById("a_rat_" + i).href = "#";
			getById("a_rat_" + i).onclick = function(){};
			i++;
		}
	}
	
	// This reloads rating-form after rate
	this.reload = function(_request) {
		getById('rat_container').innerHTML = _request.responseText;
	}		
}

rat = new rat();



