$(document).ready(function() {
    jQuery('form').validate();

    // contextual link
    jQuery('.contextual-link-wrapper').bind('mouseover', function() {
        jQuery('.contextual-link', this).show();
    }).bind('mouseout', function() {
        jQuery('.contextual-link', this).hide();
    });
    jQuery('.contextual-link').bind('mouseover', function() {
        var el = jQuery(this).parent('.contextual-link-wrapper');
        jQuery(el).addClass('contextual-link-wrapper-active');
    }).bind('mouseout', function() {
        var el = jQuery(this).parent('.contextual-link-wrapper');
        jQuery(el).removeClass('contextual-link-wrapper-active');
    });

    // autocomplete
    $('input.autocomplete').each(function() {
        var url = $(this).val();
        var options = {
            minChars: 3
        };
        if ($(this).attr('minchars') != undefined) {
            options.minChars = $(this).attr('minchars');
            $(this).removeAttr('minchars');
        }
        if ($(this).attr('max') != undefined) {
            options.max = $(this).attr('max');
            $(this).removeAttr('max');
        }
        $(this).val('').autocomplete(url, options);
    });
});

