$(document).ready(function(){
    
    //fix zf hidden element from displaying
    $('input[type=hidden]').filter(function() {
        var noLabel = $(this).closest('dd').prev('dt').html() === '&nbsp;';
        var onlyChild = $(this).is(':only-child');
        if (noLabel && onlyChild) {
            return true;
        }
        return false;
    }).each(function() {
        $(this).closest('dd').hide()
               .prev('dt').hide();
    });

    //add stripes to tables
    $('table tr:even').addClass('alt');
    
    //hide flash messages after being displayed
    $('.flash-message').css('cursor', 'pointer');
    $('.flash-message').click(function() {
        $(this).slideUp('slow');
    });
    
    //add a confirmation dialog to links with a class of confirm
    $('a.confirm').click(function() {
        var title = $(this).attr('title');
        return confirm('Are you sure you want to ' + title + '?');
    });

    /*############ bulletins table, show more link ##################*/
    
    var numShown = 4; // Initial rows shown & index
    var numMore = 5; // Increment
    var numRows = $('#bulletin-archive').find('tr').length; // Total # rows
    
    // on page load: Hide extra rows and a "show 5 more" link
    $('#bulletin-archive')
        .find('tr:gt(' + numShown + ')').hide().end()
        .append('<tfoot><tr><td colspan="2" style="text-align: center;"><a class="show-more" href="#">Show ' + numMore + ' More</a></td></tr></tfoot>');
    
    //show more table rows
    $('a.show-more').click(function() {
        $(this).closest('table').find('tr:hidden:lt('+numMore+')').show();
        var remainingRows = $(this).closest('table').find('tr:hidden').size();
        if (remainingRows == 0) {
            $(this).closest('tr').remove();
        }
        return false;
    });
    
    //$('#more').click(function(){
    //    numShown = numShown + numMore;
    //    // no more show more if done
    //    if ( numShown >= numRows ) $('#more').remove();
    //    // change rows remaining if less than increment
    //    if ( numRows - numShown < numMore ) $('#more span').html(numRows - numShown);
    //    $('#bulletin-archive').find('tr:lt('+numShown+')').show();
    //})


});
