function toggleModal(movie, movieWidth, movieHeight, title){
	var newWidth;
	var newHeight;

	if(!(jQuery('#modal_bg').length)){
		buildModal();
	}
	
	if(jQuery('#modal_bg_wrap').css('display') == 'none'){
		if(document.documentElement.scrollTop){
			jQuery('#modal').css('top', ((100 + document.documentElement.scrollTop) + 'px'));
		}else{
			jQuery('#modal').css('top', ((100 + document.body.scrollTop) + 'px'));
		}		
		jQuery('#modal').prepend('<div id="modal_mov"></div>');
		jQuery('#modal').prepend('<div id="modal_title">'+title+'</div>');
		jQuery('#modal_title').hide();
		swfobject.embedSWF(movie, "modal_mov", movieWidth, movieHeight, "9.0.0");
		jQuery('#modal_bg_wrap').fadeIn(function callback(){
			jQuery('#modal_bottom').css('display','none');
			
			newWidth = jQuery('#modal').width();
			newHeight = jQuery('#modal').height();
			jQuery('#modal_wrap').css('width','0');
			jQuery('#modal').css('display','none');
			jQuery('#modal_mov').css('display','none');
			jQuery('#modal').css('width','0');
			jQuery('#modal').css('height', newHeight+'px');
			jQuery('#modal').css('left','0');
			jQuery('#modal').slideDown(function callback(){
				jQuery('#modal').animate({width: newWidth+'px',left: '-'+Math.round((newWidth/2))+'px'}, '', '', function(){
					jQuery('#modal_mov').fadeIn(function callback(){
						jQuery('#modal').css('height','');
						jQuery('#modal_title').slideDown(function(){
							jQuery('#modal_bottom').slideDown();
						});											
					});								
				});
			});
			jQuery('#modal_wrap').css('left','50%');
		});					
	}else{
		jQuery('#modal_bg_wrap').css('display','none');
		jQuery('#modal_wrap').css('left','-50%');
		jQuery('#modal_mov').remove();
		jQuery('#modal_title').remove();
	}
	
	return false;
}
function buildModal(){
	var modal_wrap = document.createElement('div');
	modal_wrap.setAttribute('id','modal_wrap');
	jQuery('body').prepend(modal_wrap);
	
	var modal = document.createElement('div');
	modal.setAttribute('id','modal');	
	jQuery('#modal_wrap').html(modal);				
	
	var modal_bottom = document.createElement('div');
	modal_bottom.setAttribute('id','modal_bottom');
	jQuery('#modal').append(modal_bottom);
	jQuery('#modal_bottom').html('<img src="/newsroom/wp-includes/modalbox/images/close.gif" id="modal_close_btn" />');	
	jQuery('#modal_close_btn').click(function(){
		toggleModal();
	});
	
	var modal_bg_wrap = document.createElement('div');
	modal_bg_wrap.setAttribute('id','modal_bg_wrap');
	jQuery('body').append(modal_bg_wrap);
	jQuery('#modal_bg_wrap').click(function(){
		toggleModal();
	});
	
	var modal_bg = document.createElement('div');
	modal_bg.setAttribute('id','modal_bg');
	jQuery('#modal_bg_wrap').html(modal_bg);
	
	return false;
}
