/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(num,post){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;
		}
	}

	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		s = s.substring(0,1);
		a = 0;
		for(i=1; i<=sMax; i++){
			if(i<=s){
				document.getElementById("_"+i+post).className = "on";
				document.getElementById("rateStatus"+post).innerHTML = num.title;
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i+post).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me,post){
	if(!rated){
		if(!preSet){
			for(i=1; i<=sMax; i++){
				document.getElementById("_"+i+post).className = "";
				document.getElementById("rateStatus"+post).innerHTML = me.parentNode.title;
			}
		}else{
			rating(preSet);
			document.getElementById("rateStatus"+post).innerHTML = document.getElementById("ratingSaved"+post).innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me,post,blog){
	if(!rated){
		document.getElementById("rateStatus"+post).innerHTML = document.getElementById("ratingSaved"+post).innerHTML + " :: "+me.title;
		preSet = me;
		rated=1;
		sendRate(me,post,blog);
		rating(me,post);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel,post,blog){
	var id = sel.id;
	var voto = id.substring(1,2);
	window.location.href = 'http://www.radioglobonatal.com.br/blog/jogodavida/votar.php5?voto='+voto+'&post='+post+((blog>0)?'&blog='+blog:'');
}


