
$(function() {
	$.fn.extend({
		center: function(x, y) {
			// var options =  $.extend({transition:300, minX:0, minY:0}, options);
			return this.each(function() {
				if (x == undefined) {
					x = true;
				}
				if (y == undefined) {
					y = true;
				}
				var $this = $(this);
				var $window = $(window);
				$this.css({
					position: "absolute"
				});
				if (x) {
					var left = ($window.width() - $this.outerWidth()) / 2 + $window.scrollLeft();
					$this.css('left', left);
				}
				if (!y == false) {
					var top = ($window.height() - $this.outerHeight()) / 2 + $window.scrollTop();
					if (parseInt(top, 10) < 0)
						top = "0px";
					$this.css('top', top);
				}
				// $(this).animate({
				//   top: (top > options.minY ? top : options.minY)+'px',
				//   left: (left > options.minX ? left : options.minX)+'px'
				// }, options.transition);
				return $(this);
			});
		}
	});
});

var myMask;

function ShowOverlay(closeOnClick, overLayId) {
	if (!overLayId)
		overLayId = "#pageOverlay";
	else
		overLayId = "#" + overLayId;
	myMask = document.createElement('div');
	$(myMask).attr("class", $(overLayId).attr("class"));
	$(myMask).attr("style", $(overLayId).attr("style"));
	$(myMask).html($(overLayId).html());
	$("body").prepend(myMask);
	if (closeOnClick)
		$(myMask).expose({ maskId: 'jqToolsExpose', color: '#000', opacity: 0.7, loadSpeed: 'fast', closeOnClick: true, closeOnEsc: false, onClose: function() { CloseOverlay(); }, api: true }).load();
	else
		$(myMask).expose({ maskId: 'jqToolsExpose', color: '#000', opacity: 0.7, loadSpeed: 'fast', closeOnClick: false, closeOnEsc: false, onClose: function() { CloseOverlay(); }, api: true }).load();
	$(myMask).css("display", "block");
	$(myMask).center();
	$(window).bind('resize', function() { $(myMask).center(); });
	$(window).bind('scroll', function() { $(myMask).center(); });
	if ($.browser.msie && parseInt($.browser.version, 10) < 7)
		$("select").css("visibility", "hidden");
}

function CloseOverlay() {
	$(myMask).css("display", "none");
	$(myMask).expose({ closeSpeed: 0, api: true }).close();
	$(window).unbind('resize');
	$(window).unbind('scroll');
	if ($.browser.msie && parseInt($.browser.version, 10) < 7)
		$("select").css("visibility", "visible");

	$("div#jqToolsExpose").remove();
	$(myMask).remove();
}


function StartVideo() {
	myMask = document.createElement('div');
	$(myMask).attr("class", $("#pageOverlay").attr("class"));
	$(myMask).attr("style", $("#pageOverlay").attr("style"));
	$(myMask).html($("#pageOverlay").html());
	$("body").prepend(myMask);
	$(myMask).expose({ maskId: 'jqToolsExpose', color: '#000', opacity: 0.7, loadSpeed: 'fast', closeOnEsc: false, onClose: function() { CloseVideo(); }, api: true }).load(RMP_createObject());
	$(myMask).css("display", "block");
	$(myMask).center();
	$(window).bind('resize', function() { $(myMask).center(); });
	$(window).bind('scroll', function() { $(myMask).center(); });
	if ($.browser.msie && parseInt($.browser.version, 10) < 7)
		$("select").css("visibility", "hidden");
}

function CloseVideo() {
	try { RMP_stop(); }
	catch (e) { }
	setTimeout('$("#actualFlashContent").html("&#160;")', 750);
	//$("#actualFlashContent").html("&#160;");
	CloseOverlay();
	// Need for videos on stage to restart stage animations
	setTimeout('RestartStageAnimation()', 2000);
}

function RestartStageAnimation() {
	try { NextTeaser(); }
	catch (e) { }
}

