$(document).ready(function() {
    $('.comment-trigger', this).click(function() {
        $('#commentbox'+ this.id).toggle('medium');
        var cId = this.id;

        // populate/clear username input
        swapValue = new Array();
        $(".comment-user").each(function(i){
            swapValue[i] = $(this).val(); //alert(swapValue[i])
            $(this).focus(function(){
                if ($(this).val() == swapValue[i]) {
                    $(this).val("");
                }
                $(this).addClass("focus");
            }).blur(function(){
                if ($.trim($(this).val()) == "") {
                    $(this).val(swapValue[i]);
                    $(this).removeClass("focus");
                }
            });
        });
    });

    $('.comment-submit', this).click(function() {
        params2 = this.id.split("_");
        cId = params2[1];
        params = $('.comments-container_'+cId).attr('id').split("_");
        user = $('#ui_'+ cId).val();
        comment = $('#tb_'+ cId).val();

        // check catcha values
        if ($('#comment-captcha-value_'+cId).val() != $('#captcha_'+cId).val()) {
            alert('Please type the number in the box')
            return false;
        }

        if ($('#tb_'+ cId).val() != '') {
            $('#comment-update_'+ cId).load("/site/modules/comments/controller.comments.module.php?itemType="+params[0]+"&itemId="+params[1]+"&comment="+escape(comment)+"&userId="+user, function() {
                $('#commentbox_'+ cId).fadeOut('medium', function() {
                    $('#comment-update_'+ cId).fadeIn('medium');
                });
            });
        }
    });
    return false;
});

function getElementParams(str) {
    params = str.split("_");
    return params;
}
