window.addEvent('resize',function() {
	if($('modal')) { 
		centerModal();
	}
});

function centerModal() {
	var iebody = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	
	$('modal').setStyles({
			'top': ( window.getHeight() - 397 )  / 2 - 20 + iebody.scrollTop,
			'left': ( window.getWidth() - 523 )  / 2 
	});
}

function videoPopup(ChannelID, StoryID, linkTitle, linkHref) {

	var screen = new Element('div', {
		'id': 'screen',
		'styles': {
			opacity: 0,
			'height': window.getScrollHeight(),
			'width': window.getWidth()
		},
		'events': {
			'click': function() { 
				videoPopupClose(); 
			}
		}
	}).injectInside(document.body);				
	
	var screenFx = new Fx.Style(screen, 'opacity', {
		duration:600, 
		onComplete: function() {

			var modal = new Element('div', {
				'id': 'modal'
			}).injectAfter('screen');
			
			centerModal();
			
			modal.setHTML('<img src=\"/images/video/modal/close.gif\" onclick=\"videoPopupClose();\" /><div id=\"flashcontent\"></div><a href=\"' + linkHref + '\">' + linkTitle + '</a>');		
		
			// feedroom code
			var so = new FlashObject ("http://leggmason.pb.feedroom.com/pb-comp/leggmason/custom1/player.swf", "player", "442", "308", "8", "#FFFFFF");
			so.addVariable ("SkinName", "custom1");
			so.addVariable ("SiteID", "leggmason");
			so.addVariable ("SiteName", "leggmason");		
			so.addVariable ("ChannelID", ChannelID);
			so.addVariable ("StoryID", StoryID);
			so.addVariable ("Volume", ".5");
			so.addParam ("quality", "high");
			so.addParam ("allowFullScreen", "true");
			so.addParam ("allowScriptAccess", "always");
			so.addParam ("menu", "false");
			so.write ("flashcontent");	
		}
	}).start(.8);
								
}

function videoPopupClose() {
	$('modal').empty().remove();
	
	var screenFx = new Fx.Style('screen', 'opacity', {
		duration:500, 
		onComplete: function() {
			$('screen').remove();
		}
	}).start(0);															
}