
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.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($('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

        if(oX<0 || oX>85 || oY<0 || oY>17) { star.stop=1; star.revert(); }
        
        else {
            $S('starCur'+n).width=Math.ceil(Math.ceil(oX/17)*17)+'px';
            $S('starUser'+n).color='#111';
            $('starUser'+n).innerHTML=Math.ceil(oX/17)+'/5';
        }
    };
} };

star.update=function(e,o, user, id, type) { var n=star.num, v=$('starUser'+n).innerHTML; v=v.substr(0, 1);

    n=o.id.substr(4); $('starCur'+n).title=v;
	
	req=new XMLHttpRequest(); 
	req.open('GET',"ajax/rating.stars.php?score="+v+"&user="+user+"&id="+id+"&type="+type,false); 
	req.send(null);
	if (req.readyState==4) {
		if(req.responseText == 'not_ok') {
			alert('За да дадете оценка, трябва да се логнете в своят акаунт!');
		}
		else if(req.responseText == 'already voted') {
			alert('Вече сте дали своята оценка!');
		}
		else {
			window.location = window.location.href;
		}
	}
	
	

};

star.revert=function() { var n=star.num, v=$('starCur'+n).title;

    $S('starCur'+n).width=v*17+'px';
    $('starUser'+n).innerHTML=(v>=0?v+'/5':'');
    $('starUser'+n).style.color='#888';
    
    document.onmousemove='';

};

star.num=0;
