function sm_raiting__startup()
{	
	$('.handler__rating').click(	
		function()
		{	
			if($('.already_vote').attr('action')=='1'){
				$.ajax({
					url: $(this).attr('rate_action'),             // указываем URL и
					dataType : "json",                     // тип загружаемых данных
					success: raiting_response
				});
			}
			else {
				$('.already_vote').show();
				setTimeout("$('.already_vote').hide();", 5000);
			}

			return true;
		} 
	); 
	
	$('.handler__rating img').hover(
		function()
		{				
			var num = $(this).attr('number');
			hover(num);
		},
		function()
		{			
			var num = $('.rating_complete').attr('rating');
			hover(num);
		}		
	);
	
    return true;
}

function hover (num){
	$('.handler__rating img').each(
		function() {
			hov($(this), num);
		}
	);	
}

function hov (item, num){
	if (item.attr('number') <= num){
		item.removeClass('rating-unactive');
		item.addClass('rating-active');
	}
	else{
		item.removeClass('rating-active');
		item.addClass('rating-unactive');
	}
}

function rating_unactive (){
	$('.handler__rating').each (
		function()
		{				
			$(this).attr('rate_action', 'localhost:;');
		}
	);
}

function raiting_response( responseBody, responseStatus )
{
    if( responseStatus == 'success' && responseBody )
    {
		var counter=1;
		$('.handler__rating img').each (
			function()
			{				
				if(counter <= responseBody.rating){
					$(this).removeClass('rating-unactive');
					$(this).addClass('rating-active');
				}
				else{
					$(this).removeClass('rating-active');
					$(this).addClass('rating-unactive');
				}
				counter++;
			}
		);
		$('.rating_complete').show();
		$('.rating_complete').attr('rating', responseBody.rating);
		rating_unactive();
		setTimeout("$('.rating_complete').hide();", 5000);
		$('.already_vote').attr('action', '0');
    }

    return true;
}
