(function($) {
    $('#backtotop').click(function(){
		$('html, body').animate({scrollTop:0}, 500);
    });

    $.validator.addMethod("notEqual", function(value, element, param) {
        param = $(element).attr('rel');
        return value != param ? true : false;},
        "Please specify a different (non-default) value"
    );

    $('#edit-comment-body-und-0-value').focus(function(){
        if ($(this).attr('rel') == $(this).val()) {
           $(this).val('');
        }
    });

    $('#edit-comment-body-und-0-value').blur(function(){
        if ($(this).val() == '') {
           $(this).val($(this).attr('rel'));
        }
    });

    $('#comment-form').validate({
        focusInvalid: false,
        rules: {
            'name': {required: true},
            'field_comment_email[und][0][email]': {email: true},
            'comment_body[und][0][value]': {required: true, notEqual:0}
        },
        errorPlacement: function(error, element) {
             element.parents('.form-item').addClass('error');
        },
        invalidHandler: function(form, validator) {
            if (validator.numberOfInvalids()) {
                $('#comment-form .form-item.error').removeClass('error');
                $('#wrapper-messages').addClass('messages').removeClass('status').addClass('error').html(error_message).attr("tabindex",-1).focus();
            }
        },
        submitHandler: function(form) {
            $(form).ajaxSubmit();
        }
    });
})(jQuery);
