
function ratingStars() { 

	var stars = $$('div.star-rating li a');
	var req = new Request({method: 'get', 
						  	autoCancel: true,
						  	url: '/gateway/ajaxGateway.php',
							onSuccess: function(response){
								setRated(response);
							}
						  });
	stars.addEvent('mouseover' , function() { 
		
		t = parseInt( this.getParent('li').id.substr(2,1) );
		for(i=1;i<t;i++){
			$('s_'+i).getChildren('a').set('class', 'hover');
		}
		} );
				
	stars.addEvent('mouseout' , function() { 
		$$('div.star-rating li a').set('class', '');

		} );				
					
								  
	stars.addEvent('click' , function() { 
				
				li = argToGet(this.href);
				req.send('_module=ratings&mode=rating'+li);
				return false;
				} );
	
}
function setRated(resp){
	//resp is a json object

	var res = JSON.decode(resp);
	switch(res.status){
	
	case 'okay':
		alert('Nous avons bien enregistré votre note, merci!');
				
		for(var i=1;i<6 ; i++){
			if(i<=Math.floor(res.newAve) ){
				$('s_'+i).set('class', 'rated');
			}else{
				$('s_'+i).set('class', 'unrated');
			}
		}
		
		//$('aveVotes').innerHTML = res.newAve;	
		//$('numVotes').innerHTML = res.newCount;
		
		break;
	case 'duplicate':
		alert('Vous avez déjà noté cet article');
		break;
	case 'error':
		alert('Oops... nous avons rencontré un problème. Votre note n\'a pas été prise en compte! Veuillez réessayer s\'il vous plait.');
		break;
	}
	
}

