$(document).ready(function(){
	var ajaxpath = 'ajax.php';

	if (typeof(EditorReady) == "function")
		EditorReady();

	$('dl.tabs dt').click( function() {
		$(this)
			.siblings().removeClass('selected').end()
			.next('dd').andSelf().addClass('selected');
	});
	$('dl.bottom_tabs dt').click( function() {
		$(this)
			.siblings().removeClass('selected').end()
			.next('dd').andSelf().addClass('selected');
	});

	$("div#lastnewsblock").corner("20px");

	$('table.solution_post img.discussp').click( function ()
	{
		var th = $(this);
		th.parent().find('ratio').load(ajaxpath + '?action=discussvoteup&id=' + th.attr('oid'));
	});

	$('table.solution_post img.discussm').click( function ()
	{
		var th = $(this);
		th.parent().find('ratio').load(ajaxpath + '?action=discussvotedown&id=' + th.attr('oid'));
	});

	$('table.solution_post img.solp').click( function ()
	{
		var th = $(this);
		th.parent().find('ratio').load(ajaxpath + '?action=solvoteup&id=' + th.attr('oid'));
	});

	$('table.solution_post img.solm').click( function ()
	{
		var th = $(this);
		th.parent().find('ratio').load(ajaxpath + '?action=solvotedown&id=' + th.attr('oid'));
	});

	$("a.i_am_profession").click( function ()
	{
		$("#profession").val($(this).html());
		$(this).parent().parent().removeClass('selected').end();
		return false;
	});

	$("a.i_am_region").click( function ()
	{
		$("form#cityform").attr("action", $(this).attr("href") );
		$("form#cityform").fadeIn();
		window.location.href = '#cityform';
		return false;
	});

	$('.datepicker').datepicker({
            changeMonth: true,
            changeYear: true,
            //dateFormat: 'dd.mm.yy',
            dateFormat: 'yy-mm-dd',
            onSelect: function(dateText) {
                $("#datebutton").attr("href", "/cdr/?start="+$("#startdate").attr("value")+"&end="+$("#enddate").attr("value"))
            }
        }).datepicker($.datepicker.regional['ru']);


	$("table.newstree span.catbtn").click( function ()
	{
		var cc = $(this).parent().parent().parent().find("tr.catcontent");
		if (cc.css("display") == "none")
			cc.fadeIn("fast");
		else
			cc.fadeOut("fast");
	});

	$("a.ajax").click( function ()
	{
		$(this).load($(this).attr("href"));
		return false;
	});
	
	$("a.parent_ajax").click( function ()
	{
		$(this).parent().load($(this).attr("href"));
		return false;
	});


	$(".problem_dok").click( function()
	{
		document.go($(this).attr('src'));
	});


	$("select#country_select").change( function()
	{
		var sel = $(this).find("option:selected").text();

		if (sel == "Белорусия")
		{
			$('#region_td').load('/templates/belorus_regions.html');;
		}
		else if ( sel == "Украина")
		{
			$('#region_td').load('/templates/ukr_regions.html');
		}
		else if (sel == "Российская Федерация")
		{
			$('#region_td').load('/templates/rf_regions.html');
		}
		else if (sel == "Казахстан")
		{
			$('#region_td').load('/templates/kazah_regions.html');
		}

		$("i_am_profession").parent().mouseOut(function () {alert("11");});

		$("select#region").css("width", "100%");
		//$("select#region").append("<option value='' selected='selected'>Любой</option>");

		//
		//
		//
	});


	/* Голосование за новость - подсветка картинок */
	$("#news_tick1").mouseover( function()
	{
		$(this).attr("src", "/img/tick_16.png");
	});
	$("#news_tick1").mouseout( function()
	{
		$(this).attr("src", "/img/graytick_16.png");
	});

	$("#news_tick2").mouseover( function()
	{
		$(this).attr("src", "/img/tick_16.png");
		$("#news_tick1").attr("src", "/img/tick_16.png");
	});
	$("#news_tick2").mouseout( function()
	{
		$(this).attr("src", "/img/graytick_16.png");
		$("#news_tick1").attr("src", "/img/graytick_16.png");
	});

	$("#news_tick3").mouseover( function()
	{
		$(this).attr("src", "/img/tick_16.png");
		$("#news_tick1").attr("src", "/img/tick_16.png");
		$("#news_tick2").attr("src", "/img/tick_16.png");
	});
	$("#news_tick3").mouseout( function()
	{
		$(this).attr("src", "/img/graytick_16.png");
		$("#news_tick1").attr("src", "/img/graytick_16.png");
		$("#news_tick2").attr("src", "/img/graytick_16.png");
	});

	$("#news_tick4").mouseover( function()
	{
		$(this).attr("src", "/img/tick_16.png");
		$("#news_tick1").attr("src", "/img/tick_16.png");
		$("#news_tick2").attr("src", "/img/tick_16.png");
		$("#news_tick3").attr("src", "/img/tick_16.png");
	});
	$("#news_tick4").mouseout( function()
	{
		$(this).attr("src", "/img/graytick_16.png");
		$("#news_tick1").attr("src", "/img/graytick_16.png");
		$("#news_tick2").attr("src", "/img/graytick_16.png");
		$("#news_tick3").attr("src", "/img/graytick_16.png");
	});

	$("#news_tick5").mouseover( function()
	{
		$(this).attr("src", "/img/tick_16.png");
		$("#news_tick1").attr("src", "/img/tick_16.png");
		$("#news_tick2").attr("src", "/img/tick_16.png");
		$("#news_tick3").attr("src", "/img/tick_16.png");
		$("#news_tick4").attr("src", "/img/tick_16.png");
	});
	$("#news_tick5").mouseout( function()
	{
		$(this).attr("src", "/img/graytick_16.png");
		$("#news_tick1").attr("src", "/img/graytick_16.png");
		$("#news_tick2").attr("src", "/img/graytick_16.png");
		$("#news_tick3").attr("src", "/img/graytick_16.png");
		$("#news_tick4").attr("src", "/img/graytick_16.png");
	});


//, .solution_post .discussm {
});

