// JavaScript Document

var i=0; var j=0; var a=0;
var voteresultid;
var votecountid;

var afterVote = '1';
var afterVote_rating = 0;
var afterVote_count = 0;

function video_vote(id, parentid)
{
	//alert(id + " " + parentid);
	var qs = "";
	var videoid = "";
	videoid = parentid.substring(3);
	qs = "?video_id=" + videoid + "&vote=" + id;
	voteresultid = "voteresult_"+parentid;
	votecountid = "votecount_"+parentid;
	//alert(qs + " " + voteresultid + " " + votecountid);
	document.getElementById(votecountid).style.display = "none";
	document.getElementById(voteresultid).style.display = "";
	//alert(qs);
	OpenAjaxPostCmd('/video_vote/',voteresultid,qs,'<span>..</span>',voteresultid,'2','2');	
	var parent1 = document.getElementById(parentid);
	if(afterVote == '0')
	{
		var attr = parent1.childNodes[6].getAttributeNode("value");
		attr.value = id;
	}
	putOriginalStars(parentid);
	
	//$(voteresultid).fadeOut("slow");
	setTimeout("document.getElementById(voteresultid).style.display='none';document.getElementById(votecountid).style.display='';document.getElementById(votecountid).innerHTML = '<span>' + afterVote_count + ' Votes</span>';", 3000);
	
}


function changestar(id, parentid)
{
	var parent = document.getElementById(parentid);
	if(parent.hasChildNodes)
	{	
		for(i=1; i<=5; i++)
		{
			if(i<=id)
				parent.childNodes[i].src = "/media/images/icons/starOn.png";
			else
				parent.childNodes[i].src = "/media/images/icons/starOff.png";
		}
	}
}

var original;

function putOriginalStars(parentid)
{
	var parent = document.getElementById(parentid);
	if(parent.hasChildNodes)
	{	
		original = parent.childNodes[6].getAttribute("value");
		//alert(original);
		for(i=1; i<=5; i++)
		{
			if(i<=original)
				parent.childNodes[i].src = "/media/images/icons/starOn.png";
			else
				parent.childNodes[i].src = "/media/images/icons/starOff.png";
		}
	}
}