// rating object REQUIRES JQUERY
var Rate = function() {
	this.url = 'global/ajax/ajax_rate.cfm';
	this.isActive = true;
}

// set rating with ajax
Rate.prototype.rS = function(obj, num, r_id, e_id) {
	$.ajax({
		type:'POST',
		url:this.url,
		data:'num='+num+'&r_id='+r_id+'&e_id='+e_id,
		dataType:'json',
		beforeSend: function() {
			$(obj.parentNode).fadeOut('slow');
		},
		success: function(msg) {
			if(msg.SUCCESS)
				$(obj.parentNode).html(msg.MSG).fadeIn('slow');
			else { 
				alert(msg.MSG);
				$(obj.parentNode).fadeIn('slow');
			}
		}
	});
}

Rate.prototype.rT = function(num) {
	get('rating').value = num;
	this.isActive = false;
}

// Mouse over effects
Rate.prototype.rI = function(obj) {
	if (!this.isActive) return;
	
	var star = obj.parentNode.childNodes;

	for (i = 0; i < star.length; i++) {
		if (star[i].nodeType == 1 && star[i].nodeName != 'A') {
			
			if (star[i] == obj)  {
				star[i].className = 'over';
				
				var vote = star[i].childNodes;

				for (j = 0; j < vote.length; j++) {
					if (vote[j].nodeType == 1)
						vote[j].style.visibility = 'hidden';
				}
				break;
			}
			else {
				star[i].className = 'over';
				
				var vote = star[i].childNodes;

				for (j = 0; j < vote.length; j++) {
					if (vote[j].nodeType == 1)
						vote[j].style.visibility = 'hidden';
				}
			}
		}
	}
}

// mouse out effects
Rate.prototype.rO = function(obj) {
	if (!this.isActive) return;
	
	var star = obj.parentNode.childNodes;
	
	for (i = star.length-1; i > 0; i--) {
		if (star[i].nodeType == 1 && star[i].nodeName != 'A') {
			
			if (star[i] == obj)  {
				star[i].className = 'star';
				
				var vote = star[i].childNodes;

				for (j = 0; j < vote.length; j++) {
					if (vote[j].nodeType == 1)
						vote[j].style.visibility = 'visible';
				}
				break;
			}
		}
	}
}

// mouse out of container effects
Rate.prototype.rR = function(obj) {
	if (!this.isActive) return;
	
	var star = obj.childNodes;

	for (i = star.length-1; i >= 0; i--) {
		if (star[i].nodeType == 1 && star[i].nodeName != 'A') {
			star[i].className = 'star';
			
			var vote = star[i].childNodes;

			for (j = 0; j < vote.length; j++) {
				if (vote[j].nodeType == 1)
					vote[j].style.visibility = 'visible';
			}
		}
	}
}

Rate.prototype.rReset = function(obj) {
	this.isActive = true;
	this.rR(obj.parentNode);
	return false;
}

// create new object
var r = new Rate();