$(document).ready(function() {
	var base_url = "http://gazotron.com/";
	
	var height = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
	var height_stuff = height - 364;
	var height_content = height - 384;
	if(height_content > $("div.contacts_box").height() && $("div.contacts_box").height())
	{
		height_content = $("div.contacts_box").height();
	}
	
	if($("div.content").height() > height_content)
	{
		height_stuff = $("div.content").height() + 20;
		height_content = $("div.content").height();
		if($.browser.msie)
		{
			height_stuff = $("div.content").height() + 30;
		}
	}
	$("div.stuff").height(height_stuff);
	$("div.content").height(height_content);
	
	$("div.divart_logo").click(function() {
		window.location.href = "http://div-art.com/";
	});
	
	$("input.button").hover(function() {
		$(this).css("background-position", "0px -25px");
		$(this).css("color", "#e2fac7");
	}, function() {
		$(this).css("background-position", "0px 0px");
		$(this).css("color", "#036800");
	});
	
	/*---------------авторизація-----------------*/
	$("#login").val("");
	$("#pass").val("");
	
	$("#login").click(function() {
		$("#login").css("border-color", "#000000");
		$("#login").css("color", "#000000");
		$("span.error").css("display", "none");
		$("#wait").css("display", "none");
	});
	
	$("#login").focus(function() {
		$("#login").click();
	});
	
	$("#login").keypress(function(key) {
		if(key.keyCode == 13)
		{
			$("#enter").click();
		}
		else
		{
			$("#login").click();
		}
	});
	
	$("#pass").click(function() {
		$("#pass").css("border-color", "#000000");
		$("#pass").css("color", "#000000");
		$("span.error").css("display", "none");
		$("#wait").css("display", "none");
	});
	
	$("#pass").focus(function() {
		$("#pass").click();
	});
	
	$("#pass").keypress(function(key) {
		if(key.keyCode == 13)
		{
			$("#enter").click();
		}
		else
		{
			$("#pass").click();
		}
	});
	
	$("#enter").click(function() {
		if($.trim($("#login").val()) == "")
		{
			$("#no_login").css("display", "inline");
			$("#login").css("border-color", "#bf0000");
		}
		else
		{
			if($.trim($("#pass").val()) == "")
			{
				$("#no_pass").css("display", "inline");
				$("#pass").css("border-color", "#bf0000");
			}
			else
			{
				$("span.error").css("display", "none");
				$("#wait").css("display", "inline");
				$.post(base_url + "pub/login/", {"login": $.trim($("#login").val()), "pass": $.trim($("#pass").val())}, login_result);
			}
		}
	});
	
	function login_result(data)
	{
		$("span.wait").css("display", "none");
		$("span.error").css("display", "none");
		
		if(data == "wrong_login")
		{
			$("#wrong_login").css("display", "inline");
			$("#login").css("border-color", "#bf0000");
			$("#login").css("color", "#bf0000");
		}
		
		if(data == "wrong_pass")
		{
			$("#wrong_pass").css("display", "inline");
			$("#pass").css("border-color", "#bf0000");
			$("#pass").css("color", "#bf0000");
		}
		
		if(data == "done")
		{
			window.location.reload();
		}
	}
	/*---------------авторизація-----------------*/
	
	
	$("div.menu > div").hover(function() {
		if($(this).attr("class") == "button" && $("#" + $(this).attr("id") + " > span").attr("class") != "active_page")
		{
			var id = $(this).attr("id").split("_");
			$("#" + $(this).attr("id") + " > a").css("color", "#e2fac7");
			$(this).attr("class", "active_button");
			
			if($("#sep_" + id[1]).attr("class") == "sep_yes_no")
			{
				$("#sep_" + id[1]).attr("class", "sep_yes_yes")
			}
			
			if($("#sep_" + id[1]).attr("class") == "sep_no_no")
			{
				$("#sep_" + id[1]).attr("class", "sep_no_yes")
			}
			
			if($("#sep_" + (parseInt(id[1]) + 1)).attr("class") == "sep_no_yes")
			{
				$("#sep_" + (parseInt(id[1]) + 1)).attr("class", "sep_yes_yes")
			}
			
			if($("#sep_" + (parseInt(id[1]) + 1)).attr("class") == "sep_no_no")
			{
				$("#sep_" + (parseInt(id[1]) + 1)).attr("class", "sep_yes_no")
			}
		}
	}, function() {
		if($(this).attr("class") == "active_button" && $("#" + $(this).attr("id") + " > span").attr("class") != "active_page")
		{
			var id = $(this).attr("id").split("_");
			$("#" + $(this).attr("id") + " > a").css("color", "#1e713f");
			$(this).attr("class", "button");
			
			if($("#sep_" + id[1]).attr("class") == "sep_yes_yes")
			{
				$("#sep_" + id[1]).attr("class", "sep_yes_no")
			}
			
			if($("#sep_" + id[1]).attr("class") == "sep_no_yes")
			{
				$("#sep_" + id[1]).attr("class", "sep_no_no")
			}
			
			if($("#sep_" + (parseInt(id[1]) + 1)).attr("class") == "sep_yes_yes")
			{
				$("#sep_" + (parseInt(id[1]) + 1)).attr("class", "sep_no_yes")
			}
			
			if($("#sep_" + (parseInt(id[1]) + 1)).attr("class") == "sep_yes_no")
			{
				$("#sep_" + (parseInt(id[1]) + 1)).attr("class", "sep_no_no")
			}
		}
	});
});