// StarRating pizza template js 

function stars(v,o){ 
	return((typeof(o)=='object'?o:document).getElementById(v)); 
}
function starsS(o){ 
	return((typeof(o)=='object'?o:stars(o)).style); 
}
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.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,rater_width,rater_height) { 
	if(star.stop || isNaN(star.stop)){ 
		star.stop=0;
		document.onmousemove=function(e){ 
			var n=star.num;
			var p=abPos(stars('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>rater_width || oY<0 || oY>rater_height){
				star.stop=1; star.revert(rater_width);
			}else{
				starsS('starCur'+n).width=oX+'px';
				starsS('starUser'+n).color='#111';
				var newvalue=Math.round(oX/rater_width*100)+'%';
				if(newvalue == ''){
					newvalue = '0%';	
				}
				stars('starUser'+n).innerHTML=newvalue;
			}
		};
	} 
};

star.update=function(e,o,fieldname) { 
	var n=star.num, v=parseInt(stars('starUser'+n).innerHTML);
	n=o.id.substr(4); 
	stars('starCur'+n).title=v;
	
	stars(fieldname).value=v;
};

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

	starsS('starCur'+n).width=Math.round(v*rater_width/100)+'px';
	var newvalue=(v>0?Math.round(v)+'%':'');
	if(newvalue == ''){
		newvalue = '0%';	
	}
	stars('starUser'+n).innerHTML=newvalue;
	stars('starUser'+n).style.color='#888';
	
	document.onmousemove='';
};

star.num=0;