/* 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.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.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>240 || oY<0 || oY>48) { star.stop=1; star.revert(); }
		
		else {

			__$S('starCur'+n).width=oX+'px';
			__$S('starUser'+n).color='#111';
			__$('starUser'+n).innerHTML=Math.round(oX/240*100)+'%';
		}
	};
} };

star.update=function(e,o) {
    var n=star.num, v=parseInt(__$('starUser'+n).innerHTML);
	n=o.id.substr(4); __$('starCur'+n).title=v;
    var id = __$("post-id").innerHTML;
	req=new XMLHttpRequest();
    req.open('GET','/action/vote.php?vote='+v+'&id='+id,true);
    req.onreadystatechange = function () {
        if (req.readyState != 4)
            return;
        if (req.responseText != '1') {
            alert(req.responseText);
            return;
        }

        __$("starUser"+star.num).innerHTML = "Tack f&ouml;r din r&ouml;st!";
    };
    req.send(null);    
};

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

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

};

star.num=0;

