	var rating_unitwidth  = 18;
	var units = 5;
	var renderParams = new Object;
	
	function renderStars(item,renderData)
	{
		var rater ='';
		
		if(typeof(item.rating) == 'undefined') return rater;
		
		if(typeof(renderData) != 'undefined')
		{
			renderParams = renderData;
		}
		else
		{
			renderParams = new Object;
		}
		
		var blockwidth = rating_unitwidth*units;
		var rating_width = item.rating.stars*rating_unitwidth;
		var voted = ( (typeof(item.rating.vote) == 'number' || typeof(item.rating.vote) == 'string' ) && item.rating.vote > 0);
		item.sourcekey = item.sourcekey?item.sourcekey:item.origin;
		
/*

<ul class="star-rating">
	<li class="current-rating" style="width:60%;">Currently 3/5 Stars.</li>
	<li><a href="#" title="1 star out of 5" class="one-star">1</a></li>
	<li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li>
	<li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li>
	<li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li>
	<li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li>
</ul>

*/
		
		rater +='<div class="ratingblock">';			
		rater +='<div id="unit_long'+item.id+'">';
		//rater +='  <ul id="unit_ul'+item.id+'" class="unit-rating" style="width:'+blockwidth+'px; float:left;">';
		rater += '<ul class="star-rating">';
		//rater +='     <li id="unit_starBar'+item.id+'" class="current-rating" style="width:'+rating_width+'px;">Currently '+item.rating.stars+'</li>';
		rater += '<li class="current-rating" style="width:'+rating_width+'px;">Currently '+item.rating.stars+'</li>'
		
		for (var ncount = 1; ncount <= units; ncount++) 
		{
			// loop from 1 to the number of units
			if(!voted) 
			{
				// if the user hasn't yet voted, draw the voting stars
				//rater += '<li><a href="javascript:void(0);" onclick="voteForItem(\''+ncount+'\',\''+item.id+'\',\''+item.sourcekey+'\',\''+item.link+'\',\''+item.rating.stars+'\',\''+item.rating.count+'\')" title="'+ncount+' out of '+units+'" class="r'+ncount+'-unit rater" rel="nofollow">'+ncount+'</a></li>';
				rater += '<li><a href="javascript:void(0);" onclick="voteForItem(\''+ncount+'\',\''+item.id+'\',\''+item.sourcekey+'\',\''+item.link+'\',\''+item.rating.stars+'\',\''+item.rating.count+'\')" title="'+ncount+' out of '+units+'" class="star-'+ncount+'">'+ncount+'</a></li>';
			}
		}
		ncount=0; // resets the count
		
		rater+='  </ul>';
		
		var vdesc='';
		var rcount = item.rating.count;			
		
		if(rcount > 0)
		{
			if(voted)
			{
				vdesc += ' you';
				rcount--;
				vdesc += (rcount > 0) ? ' and' : '';
			}
			
			if(rcount > 0)
			{
				vdesc += ' '+rcount+( (voted) ? ' more' : '' ); 
				vdesc += ( (rcount == 1) ? ' person' : ' people' );
			}
			
			
			rater += '<span style="float: left; margin: 2px 0px 0px 5px;"> rated <strong> '+parseFloat(item.rating.stars).toFixed(2)+'</strong> by '+vdesc+'</span>';
		}
		
		rater += '	<br clear="all" />';
		rater += '</div>';
		rater += '</div>';
	

		return rater;
	}
	
	function voteForItem(vote,newsid,source,url,currentRating,currentCount)
	{
		
		var url = siteHome+"ajaxAPI.php?api_call=Outbrain::saveRatedUrl&api_format=JSON&url="+url+"&newsid="+newsid+"&source="+source+"&vote="+vote;
		var myAjax = new Ajax.Request(url, { method:'post', onSuccess:redrawRating.bind(this) });

		return false;
	}
	
	function redrawRating(Request)
	{
		try { var res = eval('('+Request.responseText+')') }
		catch(e) { return hpe.error(e) }
		
		try { var res = eval('('+res['0']+')') }
		catch(e) { return hpe.error(e) }
		/*
		alert(res['newsid']);
		alert(res['rating']);
		alert(res['count']);
		*/
		//disable vote
		var element = document.getElementById('ratingConteiner'+res['newsid']);
		//var rating = (oldRating*oldCount+parseInt(vote))/(parseInt(oldCount)+1);
		//var count =  parseInt(oldCount)+1;
		
		var item = new Object();
		item.rating = new Object();
		item.id = res['newsid'];

		item.rating.stars = parseFloat(res['rating']).toFixed(2);

		item.rating.count = parseInt(res['count']);
		item.rating.vote = parseInt(res['vote']);

		item.link = '';
		item.sourcekey = '';

		if(typeof(renderParams) != 'undefined' && typeof(renderParams['p']) != 'undefined' && typeof(renderParams['i']) != 'undefined')
		{
			var p = renderParams['p'];
			var i = renderParams['i'];
			appCP.pageItems[p].items[i].rating = item.rating;
		}
		
		element.innerHTML = renderStars(item);
	}
