function agent(v) {
	return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0));
}

function abPos(o) {
	var o=(typeof(o)=='object'?o:stars(o)), z={X:0,Y:0};
	while(o!=null) {
		z.X+=o.offsetLeft;
		z.Y+=o.offsetTop;
		o=o.offsetParent;
	};
	return(z);
}

function XY(e,v) {
	var o=agent('msie')?{'X':event.clientX+document.documentElement.scrollLeft,'Y':event.clientY+document.documentElement.scrollTop}:{'X':e.pageX,'Y':e.pageY};
	return(v?o[v]:o);
}

star={};

star.mouse=function(e,o) {
	if(star.stop || isNaN(star.stop)) {
		star.stop=0;
		document.onmousemove=function(e) {
			var n=star.num;
			var p=abPos(document.getElementById('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y;
			//alert(p+'::'+x+'::'+oX+'::'+oY);
			star.num=o.id.substr(4);
			if(oX<0 || oX>169 || oY<0 || oY>19) {
				star.stop=1;
				star.revert(e);
			}
			else {
				document.getElementById('starCur'+n).style.width=oX+'px';
				document.getElementById('starUser'+n).style.color='#111';
				document.getElementById('starUser'+n).innerHTML=Math.round(oX*100/169)/10;
			}
		};
	}
};

star.update=function(e,o,ep) {
	var n=star.num, v=(document.getElementById('starUser'+n).innerHTML)*10;
	n=o.id.substr(4);
	document.getElementById('starCur'+n).title = v;
	if (v==0) { var v2 = -1; } else { var v2 = v; }
	vote(e,ep,v2,n);
};

star.revert=function(e) {
	var n=star.num, v=parseInt(document.getElementById('starCur'+n).title);
	document.getElementById('starCur'+n).style.width=Math.round(v*169/100)+'px';
	document.getElementById('starUser'+n).innerHTML=v/10;
	document.getElementById('starUser'+n).style.color='#888';
	window.document.onmousemove = null;
	var olCheckMouseCapture = true;
	if ((olNs4 || olNs6 || olIe4)) {
		olMouseCapture();
	} else {
		overlib = no_overlib;
		nd = no_overlib;
		ver3fix = true;
	}
};

star.num=0;

function vote(e,ep,v2,n){
	if (document.getElementById){
		var dataLine =  ep + ':!b2l@:' + v2 + ':!b2l@:' + n;
		x_ajax_vote(dataLine, vote_display);
	}
}

function vote_display(dataline){
	var dlarray = dataline.split('::@!@::');
	document.getElementById('total'+dlarray[2]).innerHTML=(dlarray[0]/10);
	document.getElementById('num_rates'+dlarray[2]).innerHTML=dlarray[1];
}

function showRate(tvdbepID){
	var dataLine = tvdbepID + ':!r@:' + 'a';
	x_ajax_affiche_rate(dataLine, display_showRate);

}

function display_showRate(data){
	try{
		var showRate = document.getElementById('showRate');
		document.body.removeChild(showRate);
	}
	catch(e){}
	
	document.getElementById('main').style.opacity = .30;
	document.getElementById('main').style.filter = "alpha(opacity=30)";
	
	if (document.body.clientWidth)
		var w = document.body.clientWidth;
	else
		var w = document.body.offsetWidth;
	
	if (navigator.appName == "Opera"){
		h = window.innerHeight;
	}
	else{
		h = window.screen.availHeight;
	}

	l = ((w/2)-250);
	t = ((h/2)-70);
	
	var showRate = document.createElement('div');

	showRate.id = 'showRate';
	showRate.style.position = "absolute";
	showRate.style.left = document.documentElement.scrollLeft+l+'px';
	showRate.style.top = document.documentElement.scrollTop+t+'px';
	showRate.style.zIndex = 1000;
	showRate.innerHTML = data;
	
	var protect = document.createElement('div');
	protect.id = 'protect';
	protect.style.position = "fixed";
	protect.style.left = '0px';
	protect.style.top = '0px';
	protect.style.width = document.getElementById('main').style.width;
	protect.style.height = document.getElementById('main').style.height;
	protect.style.zIndex = 900;
	protect.backgroundColor = '#000000';
	protect.onclick = hideRate;

	document.body.appendChild(showRate);
	document.getElementById('main').appendChild(protect);
}

function hideRate(){
	var showRate = document.getElementById('showRate');
	document.body.removeChild(showRate);
	var protect = document.getElementById('protect');
	document.getElementById('main').removeChild(protect);
	document.getElementById('main').style.opacity=1;
	document.getElementById('main').style.filter = "alpha(opacity=100)";
	window.document.onmousemove = null;
	var olCheckMouseCapture = true;
	if ((olNs4 || olNs6 || olIe4)) {
		olMouseCapture();
	} else {
		overlib = no_overlib;
		nd = no_overlib;
		ver3fix = true;
	}
}
