/*
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){
	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; // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById(i).className = "on";
				document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById(i).className = "off";
			}
		}
	} else {
		for(i=1; i<=rated; i++) {
			document.getElementById(i).className = "on";
		}
	}
}

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

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

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
	var loc = window.location.href; 
	var url = loc.split("?");
    window.location = url[0] + "?rating=" + sel.id;
}

function setOn(num) {

   document.getElementById(num.id).className = "on";
}
