window.addEvent('domready', function(){checkforbookmark();})
window.addEvent('resize',function() {
	if($('modal')) { 
		centerModal();
	}
});
function checkforbookmark(){
	var url = location.href;
	var tokens = url.split('#');
	
	if (tokens[1] && tokens[1] == 'lmicvideo') {videoPopup('videocontent', 'video') }

	if (tokens[1] && tokens[1] == 'lmicaudio') {videoPopup('audiocontent', 'audio') }
}
function centerModal() {
	var iebody = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	
	$('modal').setStyles({
			'top': ( window.getHeight() - $('modal').getHeight() )  / 2 - 20 + iebody.scrollTop,
			'left': ( window.getWidth() - $('modal').getWidth() )  / 2 
	});
}

function videoPopup(contentid, classname) {

	var screen = new Element('div', {
		'id': 'screen',
		'styles': {
			opacity: 0,
			'height': window.getScrollHeight(),
			'width': window.getWidth()
		},
		'events': {
			'click': function() { 
				videoPopupClose(); 
			}
		}
	}).inject(document.body);				
	
	var screenFx = new Fx.Tween(screen, {
		duration:600,
		transition:'quad:in',	
		onComplete: function() {

			var modal = new Element('div', {
				'id': 'modal', 'class':classname
			}).inject('screen','after');
			
			
			
			modal.set('html','<img class=\"closebutton\" src=\"/images/video/modal/close.gif\" onclick=\"videoPopupClose();\" /><div class="modalcontent">' + $(contentid).get('html')+'</div>');		
		$$('#modal .flashcontent').each(function (flash){flash.id="flashcontent";})
		$$('#modal .video_container').each(function (flash){flash.id="video_container";})
		$$('#modal .video_description').each(function (flash){flash.id="video_description";})

		 findvideolinks();
		 //IE 6 
		if (Browser.Engine.trident && Browser.Engine.version == 4) { $$('select').each(function(sel){sel.setStyle('visibility', 'hidden')});}
			
			centerModal();
		}
	}).start('opacity',.8);

 
}


function videoPopupClose() {
	$('modal').destroy();
	
	var screenFx = new Fx.Tween('screen',  {
		duration:500, 
		transition: 'quad:in',
		onComplete: function() {
			$('screen').destroy();
			$$('select').each(function(sel){sel.setStyle('visibility', 'visible')});
		}
	}).start('opacity',0);															
}