/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

//function $(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
//function $S(o) { return((typeof(o)=='object'?o:$(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offset().left; z.Y+=o.offset().top; o=o.offset().parent; }; 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($('#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(); }
        
        else {
            $('#starCur'+n).css('width', oX+'px');
            $('#starUser'+n).css('color', '#111');
            $('#starUser'+n).html(Math.round(oX/84*100));
        }
    };
} };

star.update=function(e,o, item_id, message) {
	
	var n=star.num, v=parseInt($('#starUser'+n).html());

    n=o.id.substr(4); $('#starCur'+n).attr('title', v);

    // req=new XMLHttpRequest(); req.open('GET','?vote='+(v/100),false); req.send(null);    
	jQuery.post('./', {"p_mode" : "rating", "p_phase" : "vote", "p_item" : item_id, "p_rate" : v});
	
	if(message)
	{
		alert(message);	
	}

};

star.revert=function() {
	
	var n=star.num, v=parseInt($('#starCur'+n).attr('title'));

	$('#starCur'+n).css('width', Math.round(v*84/100)+'px');
	$('#starUser'+n).css('color', '#888');
	$('#starUser'+n).html(v>0?Math.round(v):'');
    
    document.onmousemove='';

};

star.num=0;