$(function() {
    
    var player = $f('flowplayer', {bgcolor: '#FFFFFF', src: '../flash/flowplayer-3.1.3.swf'},  {
    	clip: {
            autoBuffering: true,
            autoPlay: true,
            scaling: 'fit'
        },
        plugins:  {
            controls: {
                all: true,
                autoHide: 'always',
                hideDelay: 1000
            }
        }
    });
    
    $f().load();
    
    var newsOverlay = function () {
    	var item = $(this).closest('.news');
    	var image = item.children('.news_image').html();
    	var title = item.children('.news_content').children('h2').html();
    	var body = item.children('.news_content').children('.news_body').html();
    	var links = item.children('.news_content').children('.news_links').children('p').html();
    	
    	var content = '';
    	content += '<div class="news">';
    	content += image;
    	content += '<h2>' + title + '</h2>';
    	content += body;
    	content += '<p class="modal_news_links">' + links + '</p>'
    	content += '</div>';
    	
    	$.modal(content, {overlayId: 'modal_overlay',
    		              containerId: 'modal_container',
    		              onOpen: function(dialog){
			  				  $f().pause();
    						  $f().hide();
    						  dialog.overlay.fadeIn('slow', function () {
    								dialog.container.slideDown('slow', function () {
    									dialog.data.fadeIn('slow');
    								});
    							});
						  },
    		              onClose: function(dialog){
    						  dialog.data.fadeOut('slow', function () {
	  								dialog.container.slideUp('slow', function () {
	  									dialog.overlay.fadeOut('slow', function () {
	  										$f().show();
	  										$.modal.close();
	  									});
	  								});
  								});
						  }
    	});
    }
    
    var choreographerOverlay = function () {
    	var item = $(this);
    	var image = item.children('.choreographer_image').html();
    	var name = item.children('.choreographer_content').children('.choreographer_name').html();
    	var bio = item.children('.choreographer_content').children('.choreographer_bio').html();
    	
    	var content = '';
    	content += '<div class="news">';
    	content += image;
    	content += '<h2>' + name + '</h2>';
    	content += bio;
    	content += '<p class="modal_credits_link">' + $('#credit_list').parent('p').html() + '</p>'
    	content += '</div>';
    	
    	$.modal(content, {overlayId: 'modal_overlay',
    		              containerId: 'modal_container',
    		              onOpen: function(dialog){
			  				  $f().pause();
    						  $f().hide();
    						  dialog.overlay.fadeIn('slow', function () {
    								dialog.container.slideDown('slow', function () {
    									dialog.data.fadeIn('slow');
    								});
    							});
						  },
    		              onClose: function(dialog){
    						  dialog.data.fadeOut('slow', function () {
	  								dialog.container.slideUp('slow', function () {
	  									dialog.overlay.fadeOut('slow', function () {
	  										$f().show();
	  										$.modal.close();
	  									});
	  								});
  								});
						  }
    	});
    }
    
    $('.news_link_full_story').click(newsOverlay);
    $('.news_image').click(newsOverlay).mouseover(function(){
    	$(this).css({
    		'opacity' : '0.8',
    		'filter' : 'alpha(opacity = 80)'});
    }).mouseout(function(){
    	$(this).css({
    		'opacity' : '1',
    		'filter' : 'alpha(opacity = 100)'});
   	});
    $('.choreographer').click(choreographerOverlay).mouseover(function(){
    	$(this).css({
    		'opacity' : '0.8',
    		'filter' : 'alpha(opacity = 80)',
    		'color' : '#935D5D'});
    }).mouseout(function(){
    	$(this).css({
    		'opacity' : '1',
    		'filter' : 'alpha(opacity = 100)',
    		'color' : '#000000'});
   	});
});
