function toggleBlogComments(postId) {
	if ($('#blogComments' + postId).is(':hidden')) {
	    $.get(  '/frontend/blog.php',
	            { comments: postId, ajax: 1 },
	            function(xml) { $('#blogComments' + postId).html(xml).slideDown('slow'); }
	            );
	} else {
	    $('#blogComments' + postId).slideUp('slow');
	}
}

function onclick_rate(element) {
    parts = element.id.split('-');
    postId = parts[1];
    rating = parts[2];
    
    if (element.parentNode.rated) {
        return;
    }
    element.parentNode.rated = true;
    
    $('#blogRating' + postId + ' .rate .option').each(function(e) { e.onclick = null; });
    
    $('#blogRating' + postId).fadeOut('slow', function() {
        $.post( '/svc/blog_rate.php?id=' + postId,
                {   rating: rating },
                function(xml) {
                    $('#blogRating' + postId + ' .rate').toggle();
                    $('#blogRating' + postId + ' .overall').html(xml).toggle();
                    $('#blogRating' + postId).fadeIn(1000);
                }
              );
    }
    );
}

$(document).ready(function() {
    ratings = ',' + $.cookie('blograting') + ',';
    $('.blogRating').each(function () {
        postId = this.id.substring(10);
        if (ratings.indexOf(','+postId+',') != -1) {
            $('#' + this.id + ' .overall').toggle();
        } else {
            $('#' + this.id + ' .rate').toggle();
        }
    });
    
    if ($.cookie('nsfw')) {
        $('.nsfw img').show();
        $('.nsfw-warning').hide();
    }
    
    $('a.show-nsfw').click(function() {
        id = $(this).id().substr(10);
        $('#blog-post-' + id + ' img').show();
        $('#blog-post-' + id + ' .nsfw-warning').hide();
    });
    
    $('a.show-nsfw-all').click(function() {
        $('.nsfw img').show();
        $('.nsfw-warning').hide();
    });
    
    $('a.show-nsfw-always').click(function() {
        $.cookie('nsfw', 1);
        $('.nsfw img').show();
        $('.nsfw-warning').hide();
    });
});