$(document).ready(function()
{
	$.reject({header: 'Ви використовуєте застарілий браузер', 
	paragraph1: 'Ви використовуєте застарілий браузер, він може бути несумісний з нашим веб-сайтом. Список популярних браузерів наведено нижче.',   
	paragraph2: 'Просто клікніть на іконку для того щоб перейти на сторінку завантаження браузера', 
	close: true,
	closeMessage: 'При використанні цього браузера сайт може погано відображатись',
	closeLink: 'Закрити це вікно',imagePath:'/img/browser/'})  
	$(".news_controls > .up").click(function(){$.get("/news/approve/newsid/"+$(this).parent("div").parent("div").attr("id"),"",function(){alert("Новину дозволено для перегляду.");this},'text')});
	$(".news_controls > .drop").click(function(){$.get("/news/drop/newsid/"+$(this).parent("div").parent("div").attr("id"), "", function( data ){$("#"+data ).hide();$("#"+data ).next("div").hide();this;}, "text")});
	$(".news_controls > .edit").click(function(){
	    if ($(this).attr("class") == "edit")
	    {
		title = $("._news").children("h3").text();
	        $("._news").children("h3").children("div").replaceWith('<input name="title_edit">');
	        $("._news").children("h3").children("input").attr("value", title).css("width","70%");
	        $("._news").children(".news_short").load("/news/edit", {edit_id:document.URL,operation:"get_short_news"},function(){$("#short_news_edit").sMarkUp('bbcode', 200);});
	        $("._news").children(".long_news_visible").load("/news/edit", {edit_id:document.URL,operation:"get_long_news"},function(){$("#long_news_edit").sMarkUp('bbcode', 250);});
	        $(this).attr("class","save");
	    }
	    else
	    {
		title = $("._news").children("h3").children("input").attr("value");
		news_short = $("#short_news_edit").val();
		long_news = $("#long_news_edit").val();
		$.post('/news/edit',{operation:"save",edit_id:document.URL,title:title,short_news:news_short,long_news:long_news},function(){window.location = document.URL;});
	    }
	});
	$(".comment_controls > .drop").click(function(){$.get("/news/drop/commentid/"+$(this).parent("div").parent("div").parent("div").attr("id"), "", function( data ){$("#"+data ).hide();this;}, "text")});
	$("#login_panel").keypress(function(e){if(e.which == 13){$("#login_ok").click();}});
	$("#registration").change(function(){});
	$("#menu > ul > li").hover(function(){$(this).stop().children("ul").fadeIn("fast");},function(){$(this).stop().children("ul").fadeOut("fast");});
	$("#login_ok").click(function(){$("#error").load('/auth/login', {"login":$("#flogin").val() , "pass":$("#fpass").val()}, function(){if ($("#error").text() == "") window.location="/";})});
	$("#registration input#user_name").blur(function(){$.post('/auth/registration', $(this).serializeArray(), function(data){if (data == "OK") $("#user_name").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -187px -265px');else $("#user_name").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -171px -265px');}, "text")});
	$("#registration input#login").blur(function(){$.post('/auth/registration', $(this).serializeArray(), function(data){if (data == "OK") $("#login").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -187px -265px');else $("#login").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -171px -265px');}, "text")});
	$("#registration input#email").blur(function(){$.post('/auth/registration', $(this).serializeArray(), function(data){if (data == "OK") $("#email").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -187px -265px');else $("#email").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -171px -265px');}, "text")});
	$("#registration input#pass2").blur(function(){if ($("#pass").val() == $("#pass2").val()) $("#pass2").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -187px -265px'); else $("#pass2").parent("td").next("td").children("div").css("background",'url("/img/img.png") no-repeat -171px -265px');});
	$("#news > div > h3").click(function(){
		if ($(this).parent().children("div.long_news").css("display") == "none")
		{
			if ($(this).parent().children("div.long_news").text() == "")
			{
				$(this).parent().children(".load").show("fast");
				$(this).parent().children("div.long_news").load(document.URL, {"news":$(this).parent('div').attr('id')}, function(){$(this).prev("div.load").hide({opacity:"0.5"});$(this).slideDown("normal");});
			}
			else
			{
				$(this).parent().children("div.long_news").slideDown("normal");
			}
		}
		else
		{
			$(this).parent().children("div.long_news").slideUp("fast");
		}
	});
	$(".comment_text").keyup(function(){var text_title = $(this).val();
		if (text_title.length >= 700)
			{$("#comment_lenght").css("color", "red");$("#add_comment_button").attr("disabled", "disabled");}
		else
			{$("#comment_lenght").css("color", "black");$("#add_comment_button").attr("disabled", "");}
		$("#comment_lenght").text((text_title.length)+"/700");});
});