/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

function $jx(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $S(o) { return((typeof(o)=='object'?o:$jx(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$jx(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={};

var updated = 0;

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($jx('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

        if(oX<1 || oX>84 || oY<0 || oY>19) 
			{ 
			    star.stop=1; star.revert(); 
			   if (updated == 0)
			   {
				$jx('usrrat').innerHTML = 'User rating';
               }
			}
        else 
			{
					$jx('usrrat').innerHTML = 'Your rating';
               $S('starCur'+n).width=oX+'px';
               $S('starUser'+n).color='#111';
               $jx('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';
            }
    };
} };

star.update=function(e,o,id) { var n=star.num, v=parseInt($jx('starUser'+n).innerHTML);

    n=o.id.substr(4); $jx('starCur'+n).title=v;

    req=new XMLHttpRequest(); req.open('GET','/bookrating.php?id='+id+'&vote='+v,false); req.send(null);    
	$jx('usr2').style.display = 'block';
	updated = 1;

};

star.revert=function() { var n=star.num, v=parseInt($jx('starCur'+n).title);

    $S('starCur'+n).width=Math.round(v*84/100)+'px';
    $jx('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
    $jx('starUser'+n).style.color='#888';
    
    document.onmousemove='';
};

star.num=0;

function showrating(id, def){
//if (def != 0)
//{
//	sdef = def.toString() + '%';
//}
document.write('<div id="star"><ul id="star0" class="star" onmousedown="star.update(event,this,'+id+')" onmousemove="star.mouse(event,this)" title="Rate This Movie!"><li id="starCur0" class="curr" title="'+def+'" style="width: '+Math.round((def/100)*82)+'px;"></li></ul><br><div style="color: rgb(136, 136, 136);" id="starUser0" class="user">'+def+'%</div><xbr style="clear: both;"></div>');
}
