$(function()
{

dp.SyntaxHighlighter.HighlightAll('code', 0, 0);

$('#new_articles_a, #popular_articles_a, #rated_articles_a').click(function(){
	$('#new_articles_a').removeClass('art_a_selected');
	$('#popular_articles_a').removeClass('art_a_selected');
	$('#rated_articles_a').removeClass('art_a_selected');
	$(this).addClass('art_a_selected');
	$('#new_articles').hide();
	$('#popular_articles').hide();
	$('#rated_articles').hide();
	return false;
});

$('#new_articles_a').click(function(){
	$('#new_articles').show();
	return false;
});

$('#popular_articles_a').click(function(){
	$('#popular_articles').show();
	return false;
});

$('#rated_articles_a').click(function(){
	$('#rated_articles').show();
	return false;
});

$('form *').focus(function(){
	if ($(this).is('select')) return;
	$(this).addClass('active_input');
});

$('form *').blur(function(){
	$(this).removeClass('active_input');
});

$('#rightcol li a').hover(function() {
	$(this).parent().addClass("zzz1");
}, function() {
	$(this).parent().removeClass("zzz1");
});

$('.vote').click(function() {
	var $id   = $(this).attr('id');
	var $updn = $(this).attr('updn');
	$('#2hide').fadeOut(500, function() {
		//alert($updn+' - '+$id);
		$('#2show').fadeIn(500);
		//------------------------------------------------------------
		$.post("/vote/cast", {'id': $id, 'direction': $updn},
		function(data) {
			$('#2show').fadeOut(500, function() {
				$('#mes').html(data);
				/*
				if (data == 'already voted') {
					$('#mes').html('<font color="#AA0000">Вы уже голосовали за эту статью</font>');
				} else if (data == 'cant vote') {
					$('#mes').html('<font color="#AA0000">Чтобы голосовать, вы должны зарегистрироваться</font>');
				}
				*/
				$('#message_vote').fadeIn(500);
			});
   	 		//$('#2show').html(data);
		//------------------------------------------------------------
		});
	});
	return false;
}); // end of vote click function

// anti smap feature ------------------------------------------
/*
$('form#commentform').submit(function() {
	$('input#h4s:first').val('antispamsystem@diespammers.com');
});
*/

// login dialog -----------------------------------------------
$('#loginbtn').click(function() {
	$.blockUI({message: $('#loginform1'), css: {width: '240px'}});
	return false;
});

$('#comment_preview_btn').click(function(){
	var $comment_body = $('#comment_body').val();
	if ($comment_body.length < 3) {
		alert('Текст комментария должен состоять как минимум из 3-х символов');
	} else {
		$('#comment_preview').html('<div align="center"><img src="/img/loading.gif" /></div>');
		$('#comment_preview').show();
		$.post('/comment/preview/', {'comment' : $comment_body}, function(data){
			if (data == 'error') {
				$('#comment_preview').hide();
				alert('Ошибка!');
			}
			else {
				$('#comment_preview').html(data);
			}
		});
	}
});

$('#simles_btn, #simles_div').hover(function(){
	$('#simles_div').show();
}, function(){
	$('#simles_div').hide();
});

$('textarea').mouseover(function(){
	$('#simles_div').hide();
});

$('#simles_div').click(function(){
	$(this).hide();
});

$('#commentform').submit(function() {
	//if (confirm('А вы точно не спамер?'))
	$('#antismapinput').val('die spammers!');
	//else return false;
});

});
