//launch voting process
function vote() {
	//votebox is 3 levels up
	votebox = this.parentNode.parentNode.parentNode;
	var destURL = "includes/rateit-ajax.php";
	//tack query onto destURL
	destURL += "?" + this.href.split("?")[1];
	
	//update stars area after data returned
	xhr.onreadystatechange = function() {
		//if done returning data
		if(xhr.readyState == 4 && xhr.status == 200) {
			//update star area
			votebox.innerHTML = xhr.responseText;
			//reinitialize new links
			initRateit();
			//insert thank you text
		}
	}
	xhr.open('GET', destURL);
	xhr.send(null);
	
	return false;
}


//setup the whole shebang
function initRateit() {
	//bail if no DOM or Ajax capabilities
	if(!document.getElementById)
		return;
		
	//global var xhr is used for all submissions	
	try {
	   xhr = new ActiveXObject("Microsoft.XMLHTTP");    // trying Internet Explorer 
	}
	catch(e) {  // failed 
		try {
	  		xhr = new XMLHttpRequest()
		}
		catch(e) {
			return;
		}
	}
	
	
	//loop through voteboxes and add handlers to all a tags therein
	document.getElementsByClassName("vote").each(function(votebox) {
	    $A(votebox.getElementsByTagName("a")).each(function(link) {
	        link.onclick = vote;
	    });
	});
}

window.onload = initRateit;