$(function(){
	soundManager.url = '/swf/';


    $('a[rel="gallery"]').fancybox();
    
    // zebra rows
    $('.resume table').find('tr:odd').addClass('zebra');
   
    // add count to headers
    $('.resume table').each(function(){
        var header = $(this).prev('h3');
        var row_count = $(this).find('tr').length;
        header.html(header.html() + ' (' + row_count + ')');
    });
   
    // hide tables
    $('.resume table:not(:first)').hide();
    // create accordion
    $('.resume h3').each(function(){
        $(this).click(function(){
            var header = this;
            $(header).siblings('table:visible').slideUp('slow', function(){
                $(header).next('table:hidden').slideDown('slow');
            });
        });
    });
    
    // headshots
    $('.headshots a.headshot').click(function(){
        $('.headshots img').attr('src', $(this).attr('href'));
        return false;
    });
    
    
    
    // bio cutoff
    $('.full_bio p.cutoff').hide();
    $('.full_bio p.cutoff').nextAll('p').hide();
    $('.full_bio').append('<p><a href="#" class="continue">Continue reading more.</a></p>')
        .find('a.continue')
        .click(function(){
            $('.full_bio p.cutoff').slideDown();
            $('.full_bio p.cutoff').nextAll('p').slideDown();
            $(this).remove();
            return false;
        });
    
    $('.audio a.stop').live('click', function(){
        $('.audio a').removeClass('playing');

		soundManager.destroySound('clip');

        $(this).remove();
        return false;
    });
    
    $('.audio a').click(function(){
		$('.audio .stop').remove();
		$('.audio a').removeClass('playing');
		$(this).addClass('playing');
		

		soundManager.destroySound('clip');
		
		soundManager.createSound({
			id: 'clip',
			url: $(this).attr('href'),
			autoPlay: true,
			onfinish: function() {
			    $('.audio a').removeClass('playing');
			    $('.audio .stop').remove();
			}
		});
		
		$('.audio').prepend('<a class="stop" href="#">Stop</a>');
		
		return false;
	});
    
});
