$(document).ready(function()
{
    // disable the go button to begin with
    $('#employee_submit').attr('disabled', 'disabled');
    
    // if no slug defined then don't submit the form
    $('#employee_submit').click(function()
    {
        return !($('#employee_search_slug').val() == '');
    });
    
    // profile overlay
    // if the function argument is given to overlay, it is assumed to be the onBeforeLoad event listener 
    $("a[rel]").overlay(function()
    { 
        // grab wrapper element inside content 
        var wrap = this.getContent().find("div.wrap"); 
        wrap.load(this.getTrigger().attr("href"));         
    });
    
    // and setup scrolling on the iframe when clicking an index link
    $('a.index-link').click(function()
    {
        $('div#contacts-list').scrollTo($(this).attr('rel'));
    });

    $('#toggle-filter-button').addClass('filter-off').removeClass('filter-on');
    $('#people-filter').hide();
    
    // toggle filter action
    $('a#toggle-filter').click(function()
    {
	    $('h3#toggle-filter-button').toggleClass('filter-on');   
	    $('h3#toggle-filter-button').toggleClass('filter-off'); 
        $('#people-filter').slideToggle(50);
        return false;
    });
    
    // show the filter if a filter value has been set 
    if($('#law_area_filter_law_area').val())
    {
        $('h3#toggle-filter-button').toggleClass('filter-on');   
        $('h3#toggle-filter-button').toggleClass('filter-off'); 
        $('#people-filter').show();
    }
});

// format an autocomplete result    
function formatItem(row)
{
    return row[0] + "&nbsp;<small>" + row[1] + "</small>";
}

function selectItem(li)
{
    // assign slug to form and allow submit to be pressed
    $('#employee_search_slug').val(li.extra[1]);
    $('#employee_submit').attr('disabled', '');
}