var rollover=new Array();

function swap_images(the_type, the_id, the_color) { //Type is Up or Down. ID is the Tag's Id. Color is what color is being swapped.
	if (rollover[the_id] == null) {
		rollover[the_id] = 0; //The first rollover is given a number of 0.
	}

	if (rollover[the_id] >= 0) {
		the_image = the_type + the_id; //This ID references the Thumb that is in motion.
		the_loading = the_type + the_color; //This is the name of the image that is going to be swapped.
		
		rollover[the_id] = 1;

		document.getElementById(the_image).src = "images/" + the_loading + ".jpeg";
	}
}


function swap_out_images(the_type, the_id) { //Swaps the image to grey when roll out.
	if (rollover[the_id] >= 0) { //This will only run if the user has not clicked on the button at least once.
		the_image = the_type + the_id;
		the_loading = the_type + "grey";

		document.getElementById(the_image).src = "images/" + the_loading + ".jpeg";
	} 
}


function cast_vote(the_type, the_id, the_color) { //This happens when the user hits on Thumbs Up or Thumbs Down.
	if (rollover[the_id] >= 0) { //This will only run the first time the user hits a button..
		rollover[the_id] = -1; //Because this number is now -1.
		
		the_image = the_type + the_id;
		
		the_loading = the_type + the_color; //This is the name of the image that is going to be swapped.
		
		newwindow = window.open('thanx.php?id='+the_id+'&type='+the_type+'','mywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1300,height=150,left=1,top=1'); //Creates the new window
		newwindow.blur(); //Sends the new window to the back.
		
		document.getElementById(the_image).src = "images/" + the_loading + ".jpeg"; //Keeps the selected image highlighted.
		
		document.getElementById("up"+the_id).className = ""; //Turns off the Hover effects.
		document.getElementById("down"+the_id).className = "";
		
		total_thumbs = document.getElementById("total_"+the_type+"["+the_id+"]").innerHTML; //Gets the old number from the database.
		total_thumbs++;
		
		document.getElementById("total_"+the_type+"["+the_id+"]").innerHTML = total_thumbs; //Shows the new number. Demonstration purposes only.
		
		if ((total_thumbs >= 3) && (the_type == "up")) {
			document.getElementById("the_msg["+the_id+"]").innerHTML = " <span style='color: green; font-weight: bold;'>This tag has been accepted.</span>"; //3 votes or more means this tag is accepted. Demonstration purposes only.
		}
	}
}