﻿function showFlashPopup(swfData, closeButtonText) {
    var dimensions = getPageSize();
    var overlayObj = document.getElementById("flashPopupBackground");
    if (overlayObj == null) {
        var div = document.createElement("div");
        div.id = "flashPopupBackground";
        document.body.appendChild(div);
        overlayObj = div;
    }
    overlayObj.style.height = dimensions.pageHeight + "px";
    overlayObj.style.width = dimensions.pageWidth + "px";
    overlayObj.style.display = "block";

    var flashPopupObj = document.getElementById("flashPopup");
    if (flashPopupObj == null) {
        var div = document.createElement("div");
        div.id = "flashPopup";
        document.body.appendChild(div);
        flashPopupObj = div;
    }
    var trueHeight = (parseInt(swfData.Height) + 19);
    flashPopupObj.style.height = trueHeight + "px"; // because of control panel of jw player
    flashPopupObj.style.width = swfData.Width + "px";
    flashPopupObj.style.display = "block";
    var posY = (dimensions.windowHeight - trueHeight) / 2;
    flashPopupObj.style.top = ((posY > 20) ? posY : 20) + "px";

    flashPopupObj.style.left = "50%";
    flashPopupObj.style.margin = "0px 0px 0px " + (-1 * swfData.Width / 2) + "px";

    window.scrollTo(0, 0);

	document.getElementById("flashPopup").innerHTML = "";
	
    var closeButton = document.createElement("a");
    closeButton.id = "closeButton";
    closeButton.onclick = function() { document.body.removeChild(document.getElementById('flashPopupBackground')); document.body.removeChild(document.getElementById('flashPopup')); }
    closeButton.href = "#";
    closeButton.innerHTML = closeButtonText;
    flashPopupObj.appendChild(closeButton);
	
    var data = document.createElement("div");
    data.id = "flashPopupData";
	flashPopupObj.appendChild(data);

    var so = new swfobject.embedSWF(swfData.FlashUrl, "flashPopupData", swfData.Width, trueHeight, swfData.Version, swfData.ExpressInstall, swfData.SwfVariable, swfData.SwfParameter, swfData.SwfAttribute);
}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    var result = {
        "pageWidth": pageWidth,
        "pageHeight": pageHeight,
        "windowWidth": windowWidth,
        "windowHeight": windowHeight
    }
    return result;
}

function hideLayer() {
    var overlayObj = document.getElementById("flashPopupBackground");
    if (overlayObj) {
        overlayObj.style.display = "none";
    }

    var flashPopupObj = document.getElementById("flashPopup");
    if (flashPopupObj) {
        flashPopupObj.style.display = "none";
    }
}
