/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */
/* Commented and Modified by Mark Baker */
/***************************************************************************************************************/
/* looks up an element with the id v in object o if o is an object, otherwise it looks it up in the document root. */
function $(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
/***************************************************************************************************************/
/***************************************************************************************************************/
/* Get the style of S whether it is an object or in the document */
function $S(o) { return((typeof(o)=='object'?o:$(o)).style); } 
/***************************************************************************************************************/
/***************************************************************************************************************/
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
/***************************************************************************************************************/
/***************************************************************************************************************/
/* Returns an array of the X and Y pos of the mouse */
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); }
/***************************************************************************************************************/
/***************************************************************************************************************/
/* Returns the X/Y coordinates of the mouse relative to the browser window  */
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); /* if v was passed, o[v] else return o */
}
/***************************************************************************************************************/
var star={};
// star.num=0;
star.mouse=function(e,o) { /* As the mouse moves, it passes the event and the object to this function */ 
	if(star.stop || isNaN(star.stop)) { /* star.stop is either true or invalid */
		star.stop=0; /* Initialize star.stop */
		document.onmousemove=function(e) { 
			var n=star.num; /* Working with the JS object star */
			var p=abPos($('star'+n)); /* p will be an object with X/Y coordinates of the mouse relative to the star div 18:25 is what is returned*/
			var x=XY(e); /* Create object x and give it X and Y coordinates of the mouse */
			var oX=x.X-p.X; /* Subtract mouse X (from the page) from mouse X (relative to the current star set) */
			var oY=x.Y-p.Y; /* Whatever it does with X, it does with Y */
			star.num=o.id.substr(4); /* You can have multiple star ratings on a page - named star0 star1 etc. Which one is this? */
			if(oX<1 || oX>100 || oY<0 || oY>25) { /* if coordinates are out of bounds */
				star.stop=1; 
				star.revert(); 
			}
			else { /* mouse is over the star div */
				$S('starCur'+n).width=oX+'px';  /* resize starCur+n with the cursor */ 
				$S('starUser'+n).color='#111';  /* Change the font color of the status indicator */
				$('starUser'+n).innerHTML=oX+'%'; /* Variable containing the current mouse position */
				if(parseInt($S('starCur'+n).width) < 20){
					$('starDescription').innerHTML = 'Poor';
				} else if(parseInt($S('starCur'+n).width) > 20 && parseInt($S('starCur'+n).width) < 40){
					$('starDescription').innerHTML = 'Below Average';
				} else if(parseInt($S('starCur'+n).width) > 41 && parseInt($S('starCur'+n).width) < 60){
					$('starDescription').innerHTML = 'Average';
				} else if(parseInt($S('starCur'+n).width) > 61 && parseInt($S('starCur'+n).width) < 80){
					$('starDescription').innerHTML = 'Above Average';
				} else if(parseInt($S('starCur'+n).width) > 81){
					$('starDescription').innerHTML = 'Excellent';
				}
			}
		};
	} 
};
star.update=function(e,o) { 
	var n=star.num, v=parseInt($('starUser'+n).innerHTML);
	n=o.id.substr(4); 
	if(v<10){ v = 10} else 
        if(v<20){ v = 20} else
        if(v<30){ v = 30} else
        if(v<40){ v = 40} else
        if(v<50){ v = 50} else
        if(v<60){ v = 60} else
        if(v<70){ v = 70} else
        if(v<80){ v = 80} else
        if(v<90){ v = 90} else
        if(v<100){ v = 100}
	//v=(v>95?100:v); /* Round anything over 95 to 100 */
	$('starCur'+n).title=v;
	//document.getElementById('usrRating').value = v;
	$('usrRating').value = v;
};
star.revert=function() { 
	var n=star.num, v=parseInt($('usrRating').value);
	$S('starCur'+n).width=v+'px';
	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
	$('starUser'+n).style.color='#888';
	document.onmousemove='';
};
	
