﻿wygModalPopup = {
	modalSetup : function() {
		//wygModalPopup.initModalPopup('mpeSendToFriend');
		wygModalPopup.initModalPopup('mpeNewsletter');
		wygModalPopup.initModalPopup('mpeLogin');
		wygModalPopup.initModalPopup('mpeRegister');
		wygModalPopup.initModalPopup('mpeAccount');
	},
	initModalPopup : function(name) {
		var modalPopup = $find(name);
		if (modalPopup) {
			modalPopup.add_showing(wygModalPopup.hideFlashPlayer);
			modalPopup.add_hiding(wygModalPopup.showFlashPlayer);
		}
	},
	hideFlashPlayer : function() {
		wygModalPopup.__setVisibility(false)
	},
	showFlashPlayer : function() {
		wygModalPopup.__setVisibility(true)
	},
	close : function(mpId) {
		var modalPopup = $find(mpId);
		if (modalPopup) {
			modalPopup.hide();
		}
	},
	/*closeDelayed : function(mpId) {
		//window.setTimeout(2000, function() { wygModalPopup.close(mpId) });
		//window.setTimeout(2000, Function.createCallback(wygModalPopup.close, mpId));
	},*/
	__setVisibility : function(playerIsVisible) {
		var theVideo = $get('theVideo');
		var theThumbnail = $get('theThumbnail');
		if (theVideo && theThumbnail) {
			theThumbnail.style.display = ((playerIsVisible) ? 'none' : 'block');
			theThumbnail.style.visibility = ((playerIsVisible) ? 'hidden' : 'visible');
			if (!playerIsVisible) {
				var bounds = Sys.UI.DomElement.getBounds(theVideo);
				if (bounds.width != 0) {
					theThumbnail.style.width = bounds.width + 'px';
					theThumbnail.style.height = bounds.height + 'px';
					for (var i = 0; i < theThumbnail.childNodes.length; ++i) {
						var child = theThumbnail.childNodes[i];
						if ((child.nodeType == 1) && (child.nodeName.toLowerCase() == 'img')) {
							child.style.height = (bounds.height - 35) + 'px';
						}
					}
				}
			}
			theVideo.style.display = ((playerIsVisible) ? 'block' : 'none');
			theVideo.style.visibility = ((playerIsVisible) ? 'visible' : 'hidden');
		}
	}
}
if (typeof(Sys) !== 'undefined') {
	Sys.Application.add_load(wygModalPopup.modalSetup);
	Sys.Application.notifyScriptLoaded();
}