﻿var myBody ;
var myOverlay;
var myLightBox;

var myOverlayLogin;
var myLoginBox;

var myLink;
var myCloseButton;
var myVideo;
var xScroll;
var yScroll;
var myPageScroll;
var myWidth; 
var myHeight;
var myPageSize;
var cHeight = "400";
var cWidth = "500";
var myLogin;

function ShowLightBox(pVideo)
{
    InitLightBox()
    myOverlay = document.getElementById("myOverlay");
    myLightBox = document.getElementById("myLightBox");

    myOverlay.style.display = 'block';
    myLightBox.style.top = myPageScroll[1] + ((myPageSize[3] - cHeight) / 2) + "px";
    myLightBox.style.left = ((myPageSize[0] - cWidth) / 2) + "px";
    myLightBox.style.display = 'block';

    LoadVideo(pVideo);
}

function ShowLightBoxImage(pImage, pHeight, pWidth) 
{

    if (pHeight != null) 
    { 
        cHeight = pHeight;
    }
    
    if (pWidth != null) 
    { 
        cWidth = pWidth;
    }


    InitLightBox()
    myOverlay = document.getElementById("myOverlay");
    myLightBox = document.getElementById("myLightBox");

    myOverlay.style.display = 'block';
    myLightBox.style.top = myPageScroll[1] + ((myPageSize[3] - cHeight) / 2) + "px";
    myLightBox.style.left = ((myPageSize[0] - cWidth) / 2) + "px";
    myLightBox.style.display = 'block';

    LoadImage(pImage);
}

function InitLightBox()
{
    myPageSize = PageSize();
    myPageScroll = PageScroll();

    myBody = document.getElementsByTagName("body").item(0);
    
    // -------
    // Overlay
    // -------
    myOverlay = document.createElement('div');
    myOverlay.setAttribute('id', 'myOverlay');
    myOverlay.onclick = function() { CloseLightBox(); return false; }
    myOverlay.style.display = 'none';
    myOverlay.style.position = 'absolute';
    myOverlay.style.top = '0';
    myOverlay.style.left = '0';
    myOverlay.style.zIndex = '90';
    myOverlay.style.width = '100%';
    myOverlay.style.height = myPageSize[1] + 'px';
    myBody.insertBefore(myOverlay, myBody.firstChild);

    // --------
    // LightBox
    // --------
    myLightBox = document.createElement("div");
    myLightBox.setAttribute('id', 'myLightBox');
    myLightBox.style.display = 'none';
    myLightBox.style.position = 'absolute';
    myLightBox.style.zIndex = '100';
    myLightBox.style.width = cWidth + 'px';
    myLightBox.style.height = cHeight + 'px';
    myBody.insertBefore(myLightBox, myOverlay.nextSibling);

    // ----
    // Link
    // ----
    myLink = document.createElement("a");
    myLink.setAttribute('href', '#');
    myLink.setAttribute('title', 'Click to close');
    myLink.onclick = function() { CloseLightBox(); return false; }
    myLightBox.appendChild(myLink);

    // -----------
    // Close Image
    // -----------
    myCloseButton = document.createElement("img");
    myCloseButton.src = '../../Tools/Images/Close.gif';
    myCloseButton.setAttribute('id', 'closeButton');
    myCloseButton.style.position = 'absolute';
    myCloseButton.style.zIndex = '200';
    myLink.appendChild(myCloseButton);
}

function LoadVideo(pVideo)
{
    // -----
    // Video
    // -----
    myVideo = document.createElement("embed");
    myVideo.setAttribute("type", "application/x-shockwave-flash");
    myVideo.setAttribute("id", "myVideo");
    myVideo.setAttribute("name", "myVideo");
    myVideo.setAttribute("src", "../../Tools/Video/player-viral.swf");
    myVideo.setAttribute("allowscriptaccess", "always");
    myVideo.setAttribute("allowfullscreen", "true");
    myVideo.setAttribute("flashvars", "file=../../Tools/Video/" + pVideo + "&image=../../Tools/prev.png&autostart=true");
    myVideo.style.width = cWidth + "px";
    myVideo.style.height = cHeight + "px";
    myLightBox.appendChild(myVideo)
}

function LoadImage(pImage) 
{
    // -----
    // Image
    // -----
    myImage = document.createElement("img");
    myImage.setAttribute("id", "myImage");
    myImage.setAttribute("name", "myImage");
    myImage.setAttribute("src", pImage);
    myImage.style.width = cWidth + "px";
    myImage.style.height = cHeight + "px";
    myLightBox.appendChild(myImage)
}

function CloseLightBox() 
{
    myOverlay.style.display = 'none';
    myLightBox.style.display = 'none';
    myLightBox.removeChild(myVideo);
}

function PageScroll()
{
    yScroll;

    if (self.pageYOffset) 
    {
        yScroll = self.pageYOffset;
    } 
    else 
    if (document.documentElement && document.documentElement.scrollTop) 
    {	 
        yScroll = document.documentElement.scrollTop;
    } 
    else 
    if (document.body) 
    {
        yScroll = document.body.scrollTop;
    }

    myPageScroll = new Array('', yScroll)
    
    return myPageScroll;
}

function PageSize()
{
    if (window.innerHeight && window.scrollMaxY) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } 
    else 
    if (document.body.scrollHeight > document.body.offsetHeight) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } 
    else 
    {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    if (self.innerHeight) 
    {
        myWidth = self.innerWidth;
        myHeight = self.innerHeight;
    } 
    else 
    if (document.documentElement && document.documentElement.clientHeight) 
    { 
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } 
    else 
    if (document.body) 
    { 
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if (yScroll < myHeight) 
    {
        pHeight = myHeight;
    } 
    else 
    {
        pHeight = yScroll;
    }

    if (xScroll < myWidth) 
    {
        pWidth = myWidth;
    } 
    else 
    {
        pWidth = xScroll;
    }

    myPageSize = new Array(pWidth, pHeight, myWidth, myHeight)
    return myPageSize;
}

//------------------------------------------------------------------------------------------------

function ShowLoginBox() 
{
    InitLoginBox()
    myOverlayLogin = document.getElementById("myOverlayLogin");
    myLoginBox = document.getElementById("myLoginBox");

    myOverlayLogin.style.display = 'block';
    myLoginBox.style.top = myPageScroll[1] + ((myPageSize[3] - cHeight) / 2);
    myLoginBox.style.left = ((myPageSize[0] - cWidth) / 2);
    myLoginBox.style.display = 'block';

    LoadLogin();
}


function InitLoginBox() 
{
    myPageSize = PageSize();
    myPageScroll = PageScroll();

    myBody = document.getElementsByTagName("body").item(0);

    // -------
    // Overlay
    // -------
    myOverlaylogin = document.createElement('div');
    myOverlaylogin.setAttribute('id', 'myOverlayLogin');
    myOverlaylogin.style.display = 'none';
    myOverlaylogin.style.position = 'absolute';
    myOverlaylogin.style.top = '0';
    myOverlaylogin.style.left = '0';
    myOverlaylogin.style.zIndex = '90';
    myOverlaylogin.style.width = '100%';
    myOverlaylogin.style.height = myPageSize[1] + 'px';
    myBody.insertBefore(myOverlaylogin, myBody.firstChild);

    // --------
    // LightBox
    // --------
    myLoginBox = document.createElement("div");
    myLoginBox.setAttribute('id', 'myLoginBox');
    myLoginBox.style.display = 'none';
    myLoginBox.style.position = 'absolute';
    myLoginBox.style.zIndex = '100';
    myLoginBox.style.width = cWidth + 'px';
    myLoginBox.style.height = cHeight + 'px';
    myBody.insertBefore(myLoginBox, myOverlaylogin.nextSibling);

}

function LoadLogin() 
{
    // -----
    // Login
    // -----
    myLogin = document.createElement("iframe");
    myLogin.setAttribute("src", "http://login.babmedikal.com");
    myLogin.setAttribute("overflow", "hidden");
    myLogin.style.width = '490';
    myLogin.style.height = '390';
    myLoginBox.appendChild(myLogin)
}
