var iHeight=630, iWidth=820;
var pageHeight, pageWidth, windowHeight, windowWidth, scrollTop, scrollLeft;
var overlay, wrapper, content, flash_markup;

var markup ='<div class="model-popup-overlay"></div>'+ 
			'<div class="model-popup-wrapper">'+
				'<div class="model-popup-close">'+
					'<a href="javascript:;"></a>'+
				'</div>'+
				'<div id="model-popup-content" class="model-popup-content">'+
				'</div>'+
			'</div>'
;

function model_popup(videoPath) {
	flash_markup = '<embed id=\'sliderMovie\' flashvars=\'vidPath='+videoPath+'\' src="videoPlayer.swf" allowscriptaccess="sameDomain" width="800" height="600" quality="high" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';

	pageHeight = jQuery('#flashcontent').height();
	pageWidth = jQuery('body').width();

	windowHeight = jQuery(window).height();
	windowWidth = jQuery(window).width();
	
	scrollTop = jQuery(window).scrollTop();
	scrollLeft = jQuery(window).scrollLeft();

	initial();
}

function initial() {
	
	jQuery('body').append(markup);

	window.onresize = function() {
		overlay.css({"width":jQuery('#flashcontent').width(), "height":jQuery('#flashcontent').height()});
		wrapper.css({'top':( ( jQuery(window).height() - iHeight ) / 2 ) + scrollTop,'marginLeft':-(iWidth / 2)});
	}
	
	overlay = jQuery('.model-popup-overlay');
	wrapper = jQuery('.model-popup-wrapper');
	content = jQuery('.model-popup-content');

	overlay.css({"width":pageWidth, "height":pageHeight}).click(function() {
		closePopup();
	})
	
	jQuery('.model-popup-close > a').click(function(){closePopup()});

	wrapper.css({'height':iHeight,'width':iWidth,'visibility':'visible','top':( ( windowHeight - iHeight ) / 2 ) + scrollTop,'marginLeft':-(iWidth / 2)});

	content.html(flash_markup);
}

function closePopup() {
	overlay.remove();
	wrapper.remove();
	window.onresize = null;
}
