/* comments.js library for comments */

function show_warning() {
    var errdiv = $(this).parents('div.warning').find('div.errordiv');
    if (errdiv.css('display') == 'none') {
        errdiv.slideDown(1000);
        $(this).html('hide');
    } else {
        errdiv.slideUp(750);
        $(this).html('show');
    }
    return false;
}

function preview_comment() {
    var form = $(this).parents('form');
    var data = form.serialize();
    var popup = $("div#preview_container");
    var allselector = "#overlay, div#preview_container";
    popup.html('<div class="frame"><div class="closebox"></div><div class="content"></div></div>');
    
    /* set up the click events to hide the preview box */
    $(allselector).fadeIn(350);
    $('#overlay, div.frame div.closebox').click(function() { $(allselector).fadeOut(300); });

    /* load the ajax preview page, hide the spinner and show the preview (or errors) */
    $('div.frame div.content').html("<div class=\"allcenter\"><img src=\"" + media_url + "/img/spinner.gif\" alt=\"spin!\" /></div>");
    /* XXX: don't hardcore this url */
    var url = '/comments/preview/';
    var data = $('div.comment_form form').serialize();
    $.post(url, data, function(data) {
        $('div.frame div.content').html(data);
        // console.log($('div.preview div.warning a'));
        $('div.preview div.warning a').click(show_warning);
    });
    return false;
}

