function voteUpPost( id )
{
	if( document.getElementById('vote-plus-button-'+id).className == 'vote-plus-disabled' )
		return;
	document.getElementById('vote-plus-button-'+id).className = 'vote-plus-disabled';
	document.getElementById('vote-minus-button-'+id).className = 'vote-minus-disabled';
	$("#vote-plus-button-"+id).unbind('click', voteUpPost);
	$("#vote-minus-button-"+id).unbind('click', voteDownPost);
	$.post(
		'/voteblogpost/',
		{
			direction: 1,
			postId: id
		},
		function(data)
		{
			if( parseInt( data.rating ) > 0 )
			{
				data.rating = '+' + data.rating;
			}
			$('#rating-container-'+id).text( data.rating );
		}, "json"
		);
}

function voteDownPost( id )
{
	if( document.getElementById('vote-plus-button-'+id).className == 'vote-plus-disabled' )
		return;
	document.getElementById('vote-plus-button-'+id).className = 'vote-plus-disabled';
	document.getElementById('vote-minus-button-'+id).className = 'vote-minus-disabled';
	$.post(
		'/voteblogpost/',
		{
			direction: -1,
			postId: id
		},
		function(data)
		{
			if( parseInt( data.rating ) > 0 )
			{
				data.rating = '+' + data.rating;
			}
			$('#rating-container-'+id).text( data.rating );
		}, "json"
		);
}

function showLatestComments()
{
    var output = '<div style="width: 260px; background: #2a2d32; float: left; margin-left: 20px; -margin-left: 10px;" id="latest-comments" ><div style="padding: 14px 0 10px 12px;"><span style="font-size: 16px; color: #ffffff;" >Последние комментарии</span></div><div id="latest-comments-content" style="background: url(/img/inc/latest-comments/ajax-loader.gif) no-repeat 97px 100px; height: 800px; width: 240px;"  ><div style="clear: both;" ></div></div></div>';
    $("#sidebar").prepend( output ); 
    $.post(
        "/ajaxhandler/",
        {
            method: "getLatest10CommentsFromBlog"
        },
        function(data)
        {
            if ( data != "" )
            {
                $('#latest-comments-content').css( 'height', 'auto' );
                $('#latest-comments-content').css( 'background-image', 'none' );
                $('#latest-comments-content').html( data + '<div style="clear: both;" ></div>' );
            } else {
               
            }
        }
    );
}

if ( jQuery.browser.msie && jQuery.browser.version == '6.0' )
{
    var px1 = '580';
} else {
    var px1 = '580';
}
$(document).ready(function(){

    if ( $('html').width() > 1240 && $('#latest-comments').html() == null )
    {
        $('#sidebar').css('width', px1 + 'px');
        $('#container').css('margin-right','-' + px1 +  'px');
        $('#content').css('margin-right',px1 + 'px');
        showLatestComments();
    }
    
});

$(window).resize( function()
{
        if ( $('html').width() > 1240 && $('#latest-comments').html() == null )
        {
            $('#sidebar').css('width', '580px');
            $('#container').css('margin-right','-580px');
            $('#content').css('margin-right','580px');
            showLatestComments();
        } else {
            if ( $('html').width() > 1240 && $('#latest-comments').html() != null )
            {
                $('#sidebar').css('width', '580px');
                $('#container').css('margin-right','-580px');
                $('#content').css('margin-right','580px');
                $('#latest-comments').show();
            } else {
                if ( $('html').width() < 1240 && $('#latest-comments').html() != null )
                {
                    $('#sidebar').css('width', '300px');
                    $('#container').css('margin-right','-300px');
                    $('#content').css('margin-right','300px');
                    $('#latest-comments').hide();
                }
            }
        }
}); 
