/* Copyright (c) Motoki, 2010 */
/*   motokisensei@gmail.com   */
/*  Developed for FarGate.RU  */

Supernatural.bindRatingContainer = function(container)
{
	
	$('span', container).each(function(i) {
		$(this).mouseover(function() {
			$(this).addClass('hover');
		});
		$(this).mouseout(function() {
			$(this).removeClass('hover');
		});
		$(this).click(function(event) {
			event.stopPropagation();				
			$(container).load(container.href, {rating : i + 1}, function(responseText, textStatus) {
				if (textStatus != 'success')
				{
					alert('Во время выполнения запроса произошла ошибка, голос не был учтён.');
					return;
				}
				container.style.backgroundColor = '#ffffcc';
				$(container).animate({ backgroundColor: '#dcccad' }, 'slow', 'linear', function() {
					container.style.backgroundColor = 'transparent';
					Supernatural.bindRatingContainer(container);
				});
			});
			return false;
		});
	});

}

$(document).ready(function() {

	$('.rating a').each(function() {
	
		$(this).click(function() {
			return false;
		});
		Supernatural.bindRatingContainer(this);
	
	});

});


