
var idea = 0;
var idea_fixed = 0;
var originality = 0;
var originality_fixed = 0;
var tech = 0;
var tech_fixed = 0;
var show_form = 0;
var rated_form = 0;

function switchRateForm(object)
{
	if(show_form == 0)
	{
		$(".add_rating").show();
		$(".add_rating input").removeAttr('disabled');
		$(object).html('Мабуть, краще без оцінок');
		show_form = 1;
	}
	else
	{
		$(".add_rating").hide();
		$(".add_rating input").attr('disabled', true);
		$(object).html('Додати оцінку');
		show_form = 0;
	}
}

function clearRates()
{
	idea = 0;
	idea_fixed = 0;
	originality = 0;
	originality_fixed = 0;
	tech = 0;
	tech_fixed = 0;
	rated_form = 0;
	
	for(i = 1; i <= 7; i++ )
	{
		$("#idea_step_" + i).removeClass('idea_rate_on');
		$("#idea_step_" + i).addClass('idea_rate_off');
		
		$("#originality_step_" + i).removeClass('originality_rate_on');
		$("#originality_step_" + i).addClass('originality_rate_off');
		
		$("#tech_step_" + i).removeClass('tech_rate_on');
		$("#tech_step_" + i).addClass('tech_rate_off');
	}
	
	$("#idea_step").val('');
	$("#originality_step").val('');
	$("#tech_step").val('');
	
	if(show_form == 0)
		$("#CommentComment").val('');
}

function initRatings()
{
	idea = 0;
	idea_fixed = 0;
	originality = 0;
	originality_fixed = 0;
	tech = 0;
	tech_fixed = 0;
	rated_form = 0;
	
	$(".idea_rate_off").mouseover(function(){
		
		idea = parseInt($(this).attr('id').replace('idea_step_', ''));
		
		$("#idea_step_" + idea + " span").show();
		
		if(idea_fixed == 0)
		{
			for(i = 1; i <= idea; i++ )
			{
				$("#idea_step_" + i).removeClass('idea_rate_off');
				$("#idea_step_" + i).addClass('idea_rate_on');
			}
			
			for(i = idea + 1; i <= 7; i++ )
			{
				$("#idea_step_" + i).removeClass('idea_rate_on');
				$("#idea_step_" + i).addClass('idea_rate_off');
			}
		}
		
	});
	
	$(".originality_rate_off").mouseover(function(){
		
		originality = parseInt($(this).attr('id').replace('originality_step_', ''));
		
		$("#originality_step_" + originality + " span").show();
		
		if(originality_fixed == 0)
		{
			for(i = 1; i <= originality; i++ )
			{
				$("#originality_step_" + i).removeClass('originality_rate_off');
				$("#originality_step_" + i).addClass('originality_rate_on');
			}
			
			for(i = originality + 1; i <= 7; i++ )
			{
				$("#originality_step_" + i).removeClass('originality_rate_on');
				$("#originality_step_" + i).addClass('originality_rate_off');
			}
		}
		
	});
	
	$(".tech_rate_off").mouseover(function(){
				
		tech = parseInt($(this).attr('id').replace('tech_step_', ''));
		
		$("#tech_step_" + tech + " span").show();
		
		if(tech_fixed == 0)
		{
			for(i = 1; i <= tech; i++ )
			{
				$("#tech_step_" + i).removeClass('tech_rate_off');
				$("#tech_step_" + i).addClass('tech_rate_on');
			}
			
			for(i = tech + 1; i <= 7; i++ )
			{
				$("#tech_step_" + i).removeClass('tech_rate_on');
				$("#tech_step_" + i).addClass('tech_rate_off');
			}
		}
				
	});
	
	$(".idea_rate_off").mouseout(function(){
		
		idea = parseInt($(this).attr('id').replace('idea_step_', ''));
		
		$("#idea_step_" + idea + " span").hide();
		
		if(idea_fixed != 1)		
		{
			for(i = 1; i <= 7; i++ )
			{
				$("#idea_step_" + i).removeClass('idea_rate_on');
				$("#idea_step_" + i).addClass('idea_rate_off');
			}
		}
		
	});
	
	$(".originality_rate_off").mouseout(function(){
		
		originality = parseInt($(this).attr('id').replace('originality_step_', ''));
		
		$("#originality_step_" + originality + " span").hide();
		
		if(originality_fixed != 1)
		{
			for(i = 1; i <= 7; i++ )
			{
				$("#originality_step_" + i).removeClass('originality_rate_on');
				$("#originality_step_" + i).addClass('originality_rate_off');
			}
		}
		
	});
	
	$(".tech_rate_off").mouseout(function(){
		
		tech = parseInt($(this).attr('id').replace('tech_step_', ''));
		
		$("#tech_step_" + tech + " span").hide();
		
		if(tech_fixed != 1)
		{
			for(i = 1; i <= 7; i++ )
			{
				$("#tech_step_" + i).removeClass('tech_rate_on');
				$("#tech_step_" + i).addClass('tech_rate_off');
			}
		}
		
	});
	
	$(".idea_rate_off").click(function(){
		
		$("#idea_step").val(idea);
		
		if(idea_fixed == 0)
			idea_fixed = 1;
		
		for(i = 1; i <= idea; i++ )
		{
			$("#idea_step_" + i).removeClass('idea_rate_off');
			$("#idea_step_" + i).addClass('idea_rate_on');
		}
		
		for(i = idea + 1; i <= 7; i++ )
		{
			$("#idea_step_" + i).removeClass('idea_rate_on');
			$("#idea_step_" + i).addClass('idea_rate_off');
		}
		
		if(tech > 0 && originality > 0 && idea > 0)
			rated_form = 1;
		
	});
	
	$(".originality_rate_off").click(function(){
		
		$("#originality_step").val(originality);
		
		if(originality_fixed == 0)
			originality_fixed = 1;
		
		for(i = 1; i <= originality; i++ )
		{
			$("#originality_step_" + i).removeClass('originality_rate_off');
			$("#originality_step_" + i).addClass('originality_rate_on');
		}
		
		for(i = originality + 1; i <= 7; i++ )
		{
			$("#originality_step_" + i).removeClass('originality_rate_on');
			$("#originality_step_" + i).addClass('originality_rate_off');
		}
		
		if(tech > 0 && originality > 0 && idea > 0)
			rated_form = 1;
		
	});
	
	$(".tech_rate_off").click(function(){
		
		$("#tech_step").val(tech);
		
		if(tech_fixed == 0)
			tech_fixed = 1;
		
		for(i = 1; i <= tech; i++ )
		{
			$("#tech_step_" + i).removeClass('tech_rate_off');
			$("#tech_step_" + i).addClass('tech_rate_on');
		}
		
		for(i = tech + 1; i <= 7; i++ )
		{
			$("#tech_step_" + i).removeClass('tech_rate_on');
			$("#tech_step_" + i).addClass('tech_rate_off');
		}
		
		if(tech > 0 && originality > 0 && idea > 0)
			rated_form = 1;
		
	});
	
}

function ratePhoto(rate, photo_id)
{
	$("#photo-details-ratings").append('<div id="quick_mark_flash">Завантаженя...</div>');
	
	$("#rating-good").remove();
	$("#rating-bad").remove();
	
	$(".add_rating").remove();
	$("#switch_mark").remove();
	
	$.post('/ratings/ajax_rate_photo/' + rate + '/' + photo_id, function(data){
		
		$("#quick_mark_flash").remove();
		$("#photo-details-ratings").append('<div id="quick_mark_flash">Ваш голос враховано</div>');
		$('#tabs-2').load('/ratings/ajax_ratings/' + photo_id, function(){});
		
	});
}
