var ie = (navigator.userAgent.indexOf('MSIE')>=0) ? true : false;
var ie6 = (navigator.userAgent.indexOf('MSIE 6')>=0) ? true : false;

/*** Embed Video Player ***/

$.fn.videoPlayerEmbed = function() {
	var settings = {
    	path: '../_swf/VideoPlayer.swf',
		width: 640,
    	height: 360,
    	version: '9.0.0',
    	id: 'flash-video-target',
    	expressInstall: false
    };

    var flashvars = {
    	flvPath: "../_swf/Morlot-Seattle-Symphony-640x360.flv",
		loopBool: "false",
		autoPlayBool: "true",
		imgPath: "../_img/microsite/Morlot-Seattle-Symphony-Video-Poster-Frame.jpg",
		hideControlsBool: "true",
		controlPadding: "10",
		controlSetup: "PlayPause,ProgressBar,TimeDisplay,FlyoutVolumeControl,FullScreen"
    };

    var params = {
		menu: "false",
		scale: "noscale",
		salign: "tl",
		wmode: "opaque",
		allowScriptAccess: "always",
		allowFullscreen: "true"
	};
	
	swfobject.embedSWF(settings.path, settings.id, settings.width, settings.height, settings.version, settings.expressInstall, flashvars, params);
};

/*** Modal Window ***/

$.fn.modalPanel = function(options){
	options = jQuery.extend({
		modalContent: $('div#modal-content'),
		className: 'modal-window',
		callback: function(){}
	},options);

	var overlay = $(document.createElement('div')).attr('id','overlay').fadeTo(0, '.85'),
		modalWindow = $(document.createElement('div')).attr('id','modal-window').addClass(options.className),
		flashTarget = $(document.createElement('div')).attr('id','flash-video-target'),
		modalContentTarget = options.modalContent.html();

	function handleEscape(e){
		if(e.keyCode == 27){
			modalHide();
		}
	}

	function modalHide(){
		$(document).unbind('keydown', handleEscape);
		var remove = function(){ $(this).remove(); };

		overlay.fadeOut(400, remove);
		modalWindow.fadeOut(400, remove).empty();

		if(typeof document.body.style.maxHeight === 'undefined'){
			$('body','html').css({ 'height' : 'auto', 'overflow' : 'auto', 'width' : 'auto' });
		}
	}

	function positionModal(){
		modalWindow.css({
			left: ($(document.body).width() - modalWindow.width()) / 2 + 'px',
			top: ($(window).height() - modalWindow.height()) / 2 + 'px'
		});
	}
	
	return this.each(function(){
		$(this).click(function(e) {
			e.preventDefault();

			$(document).keydown(handleEscape);

			$('body').append(overlay.click(function(){modalHide();})).append(modalWindow);

			overlay.fadeIn(400);

			modalWindow.html(modalContentTarget).append(flashTarget).fadeIn(200);
			$(this).videoPlayerEmbed();
			//var modalWindowContent = modalWindow.html($(this).siblings('div.modal-content').html());

			modalWindow.append($('<a class="btn" id="btn-modal-close"><span class="offscreen">Close</span></a>').click(function(){
				modalHide();
			}));

			positionModal();

			options.callback.call(this);
		});

		$(window).bind('resize', function(){
			positionModal();
		});
	});
};






