jQuery(document).ready(function($) {
    $('.zebra p:odd').addClass('odd');
    $('table.chart tbody tr:odd').addClass('odd');
    
    $(document).ajaxComplete(function() {
        $('.zebra p:odd').addClass('odd');
        $('table.chart tbody tr:odd').addClass('odd');
        
        // remove previous binds from thickbox elements
        //$('a.thickbox').unbind('click');
        //tb_init('a.thickbox');
    });
    
    // set up datepickers
    $('.datepicker').datepicker();
    
    // set up progressbars
    $('.progressbar').each(function() {
        var pct = $(this).attr('title');
        var mytext = $('<span>' + $(this).html() + '</span>'); 
        $(this).html('').progressbar({ value: pct }).append(mytext);
    });
    
    // set up collapse/expand links
    $('a.collapse').live('click', function() {
        $('#' + $(this).attr('target')).slideUp();
        $(this).removeClass('collapse').addClass('expand');
        return false; 
    });
    $('a.expand').live('click', function() {
        $('#' + $(this).attr('target')).slideDown();
        $(this).removeClass('expand').addClass('collapse');
        return false; 
    });
    
    // auto user-flash closer
    $('#user-flash').animate({ dummy: 1 }, 5000).slideUp();
    
    // user-flash closer link
    $('#user-flash a.closer').click(function() {
       $('#user-flash').slideUp(); 
    });
    
    // tabs ajax update
    $('a.ajax').click(function() {
        updateDiv = $('#'+$(this).attr('target'));
        fetchUrl = $(this).attr('href');
        updateDiv.load(fetchUrl);
        return false; 
    });
    
    // ajax loader start/stop
    $('#ajax-loader').ajaxStart(function() {
       $(this).css('display', 'block')
              .css('float', 'left');
    });
    $('#ajax-loader').ajaxStop(function() {
       $(this).fadeOut();
    });
    
    // lightbox setup
    $('a.lightbox').colorbox({
       title: $(this).attr('title'),
       initialWidth: 300,
       initialHeight: 300,
       maxHeight: 500,
       maxWidth: 500
    });
});

