/**
 * Rate.js
 *	-functions for rating a recipe
 **/
 
 /**
  *_rate();	Rate the current recipe
  * @params	recipe_id	int	id of the recipe
  * @params	rate		int	rating given
  **/
  function Rate_rate(recipe_id,recipe_number,rate){
	$('#rating-'+recipe_id).load(location.href,{
		func:'Rate_displayRating',
		Txt:$('#rating-'+recipe_id+' label').text(),
		RecipeId:recipe_id,
		RecipeNumber:recipe_number,
		HeaderPath:$('#HEADERPATH').val(),
		star_rating:rate},function(){Rate_link();});
		return false;
  }
  
  $(document).ready(function(){
		Rate_link();
	});
	
	/**
	 *_link(); formats links if JS is enabled
	 **/
	function Rate_link(){
		$('.rate-link').attr('href','javascript:;');
	}
	

	/**
	 *_toggleRating();	Dynamic display of users chosen rating for recipe
	 * @params	recipe_id	int id of recipe rating
	 * @params	rate		int	current rating hovering over
	 **/
	function Rate_toggleRating(recipe_id,rate){
		if($('#rating-'+recipe_id+' .rate-link').length>0){
			var x=0;var img;
			$('#rating-'+recipe_id+' .rate-link img').each(function(){
				img = $(this).attr('src');
				if(x<rate){
					if(img.indexOf('-empty')>0) img = img.replace('-empty','-your');
					else if(img.indexOf('-your')<=0) img = img.replace('-rating','-your-rating');
				}else if(img.indexOf('-empty')<0){
					if(img.indexOf('-your')>0) img = img.replace('-your','-empty');
					else img = img.replace('-rating','-empty-rating');
				}
				$(this).attr('src',img);
				x++;
			});
		}
	}