<!-- Hide the code from browsers that do not support javascript
var request;

function createRequest() 
{	
 		try 
 		{
   			request = new XMLHttpRequest();
 		} 
 		catch (trymicrosoft) 
 		{
   			try 
   			{
     			request = new ActiveXObject("Msxml2.XMLHTTP");
   			} 
   			catch (othermicrosoft) 
   			{
     			try 
     			{
       				request = new ActiveXObject("Microsoft.XMLHTTP");
     			} 
     			catch (failed) 
     			{
       				request = false;
     			}
   			}
 		}
 
 		if (!request)
 		{
   			alert("Error initializing XMLHttpRequest!");
   		}
}

function updatePage() 
{
 	//alert('Response: '+request.status);
}


function $(o) 
{ 
	return((typeof(o)=='object'?o:document).getElementById(o)); 
}

function $S(o) 
{ 
	return($(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); 
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	var o=agent('msie')?{'X':posx,'Y':posy}:{'X':posx,'Y':posy}; 
	return(v?o[v]:o); 
	
}

var star={

    /* Mouse Events */
    
	'cur':function(e,o) 
	{ 
		if(star.stop) 
		{ 
			star.stop=0;
			
			document.onmousemove=function(e)
			{ 
	    		var id_array = o.id.split("_");
				star.objectid = id_array[2], star.objecttype = id_array[1], star.userid = id_array[3], star.uniqueid = id_array[4];
				var elesuffix = '_'+star.objecttype+'_'+star.objectid+'_'+star.userid+'_'+star.uniqueid;

				var p=abPos($('star'+elesuffix)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y;
				
				
				/* 
				// Firebug 
				console.log('abPos - Edge coords of stars - pX='+p.X+' pY='+p.Y); // left/right edges of stars - wrong sb 572 but 384 & 3481 but 2851
				console.log('XY - Screen coords of mouse - xX='+x.X+' xY='+x.Y); // screen coords of mouse - correct
				console.log('Coords within stars - oX='+oX+' oY='+oY);   // position within stars
				*/
				
			    if(oX<1 || oX>80 || oY<0 || oY>19) 
				{ 
					// mouse out of bounds so revert to the previous rating				
					star.stop=1; 
					star.revert(); 
					//console.log('Mouse out of bounds of the rating stars (reverted rating)');   
				}
             	else 
				{
	      			// indicate the rating
	      			$S('starCur'+elesuffix).width=oX+'px';
                	$S('starUser'+elesuffix).color='#111';
                	
                	// round rating to nearest 5
                	var roundX = Math.round(parseInt(oX)/4) * 5;
            		$('starUser'+elesuffix).innerHTML=roundX+'/100';  
            		//console.log('Updated rating stars as per mouse coords');
            	}
        	}
		}
    }
    
    ,
    
	'update':function(e,o) 
	{ 
		var id_array = o.id.split("_");
		star.objectid = id_array[2], star.objecttype = id_array[1], star.userid = id_array[3], star.uniqueid = id_array[4];
		var elesuffix = '_'+star.objecttype+'_'+star.objectid+'_'+star.userid+'_'+star.uniqueid;
		var v=parseInt($('starUser'+elesuffix).innerHTML);
		
		if (isNaN(v))
		{
			$('starCur'+elesuffix).title=0; // if rating is none
		}
		else
		{
			$('starCur'+elesuffix).title=v;
			createRequest(); 
	    	var url = 'AJAXRate.php?oid='+star.objectid+'&o='+star.objecttype+'&r='+v;
			request.open('GET',url,false); 	
			request.onreadystatechange = updatePage;
			request.send(null);    
   		}
   		
	    //alert('Command: '+url);
	}
	
	,
	
    'revert':function() 
	{ 
		var elesuffix = '_'+star.objecttype+'_'+star.objectid+'_'+star.userid+'_'+star.uniqueid;
		
		v=$('starCur'+elesuffix).title;
		
		// Firebug 
		//console.log('v='+v); // 
		
		if (v == 'None') // if rating is 'None'
		{
			// revert back to 'None' 
    		$S('starCur'+elesuffix).width='0px';
        	$('starUser'+elesuffix).innerHTML='None';
		}
		else
		{
			// revert back to old rating
			v=parseInt($('starCur'+elesuffix).title);
			$S('starCur'+elesuffix).width=Math.round(v*80/100)+'px';
        	$('starUser'+elesuffix).innerHTML=(v>0?Math.round(v)+'/100':'None');
        }
        
        $('starUser'+elesuffix).style.color='#888';
        document.onmousemove='';
    },
    

	/* Data */
    'stop':1,
    'objecttype':'none',
   	'userid':'0',
    'objectid':0,
    'uniqueid':0

};

// -->