﻿function hideIFrameVideoPagesNKS() {
    method = "hideLightbox";
    // get objects
    var objOverlay = document.getElementById('nksoverlay');
    var objLightbox = document.getElementById('nkslightbox1');
    var objFrame = document.getElementById('nksvideolightboxFrame');

    // hide lightbox and overlay
    objOverlay.style.display = 'none';
    objLightbox.style.display = 'none';
    objFrame.src = "about:blank";

    // resize the frame back
    //parent.document.getElementById("main").cols="*,245";
    showSWFObjects();
}

function showSWFObjects() {
    var objs = document.getElementsByTagName("div");
    for (i = 0; i < objs.length; i++) {
        if (objs[i].id.indexOf("_SWF") > -1) {

            if (objs[i].innerHTML.toLowerCase().indexOf("<object") > -1)
                objs[i].style.display = "block";
        }
    }
}

function hideSWFObjects() {
    var objs = document.getElementsByTagName("div");
    for (i = 0; i < objs.length; i++) {
        if (objs[i].id.indexOf("_SWF") > -1) {

            if (objs[i].innerHTML.toLowerCase().indexOf("<object") > -1)
                objs[i].style.display = "none";
        }
    }

}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll() {

    var yScroll;
    method = "getPageScroll";

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }

    arrayPageScroll = new Array('', yScroll)
    return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize() {

    var xScroll, yScroll;
    method = "getPageSize";

    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;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}


function pause(numberMillis) {
    method = "pause";
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;

    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}


function openInLightBox(pageSrc, pageHeight, pageWidth) {

    method = "openInLightBox";


    if (document.getElementById("nks") == null) {
        var newdiv = document.createElement('div');
        newdiv.setAttribute('id', 'nks');
        document.body.appendChild(newdiv);

        var lBox = "";
        lBox = lBox + "<div id='nksoverlay' oncontextmenu='return false;' style='display: none; position: absolute;margin: 0 auto 0 auto; top: 0; left: 0'></div>";
        lBox = lBox + "<img id='nksloadingImage' style='display: none; position: absolute; margin: 0 auto 0 auto;' src='../images/loading.gif' />";
        lBox = lBox + "<div id='nkslightbox1' style='position: absolute'>";
        lBox = lBox + "<div id='nkslightBoxWrapper' style='position: relative; padding-top: 31px; height: 100%;width: 100%'>";
        lBox = lBox + "<iframe id='nkslightboxFrame' frameborder='0' scrolling='no' border-color='#000000' style='display: none'></iframe>";
        lBox = lBox + "<iframe id='nksvideolightboxFrame' frameborder='0' border-color='#000000' scrolling='auto' style='display: none;'></iframe>";
        lBox = lBox + "<a onclick='hideIFrameVideoPagesNKS()' id='btnnksClose' class='reactLightClose'></a>";
        lBox = lBox + "</div></div>";

        document.getElementById("nks").innerHTML = lBox;
    }

    //get the objects for loading the cropping interface
    var objOverlay = document.getElementById('nksoverlay');
    objOverlay.style.display = 'none';
    objOverlay.style.position = 'absolute';
    objOverlay.style.top = '0';
    objOverlay.style.left = '0';
    objOverlay.style.width = '100%';
    objOverlay.style.height = '90%'; //screen.height + 'px'; //(arrayPageScroll[1] + 'px');
    objOverlay.style.zIndex = '501';
    //objOverlay.style.opacity= 0.5;

    //new Effect.Appear(objOverlay, { duration:0.2, from: 0, to: 0.8 });


    var objLightbox = document.getElementById('nkslightbox1');
    objLightbox.style.width = pageWidth + 'px';

    if (document.getElementById("btnnksClose") == null) {
        var objBUtton = document.createElement("A");
        objBUtton.setAttribute("id", "btnnksClose");
        objBUtton.setAttribute("class", "reactLightClose");
        objBUtton.setAttribute("onclick", "hideIFrameVideoPagesNKS()");
        objBUtton.style.zIndex = '504';
        objLightbox.appendChild(objBUtton);

    }


    var objFrameCrop = document.getElementById('nkslightboxFrame');
    objFrameCrop.style.display = "none";
    var objFrame = document.getElementById('nksvideolightboxFrame');

    // read the page size, window size and the scrolled position
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

    objOverlay.style.display = 'block';

    // A small pause between the image loading and displaying is required with IE,
    // this prevents the previous image displaying for a short burst causing flicker.
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        pause(250);
    }

    //setting the height and width of the iframe in which to display the cropping page : crop.aspx

    objFrame.height = (pageHeight + 35) + 'px';
    objFrame.width = (pageWidth + 0) + 'px';
    var h = (pageHeight + 35);
    var w = (pageWidth + 0);

    var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - h) / 2);
    var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);

    objLightbox.style.left = lightboxLeft + 'px';
    objLightbox.style.top = lightboxTop + 'px';

    //window.scrollTo(0,0);

    objFrame.style.display = 'block';
    objFrame.src = pageSrc;
    //	objFrame.scrolling = "auto";


    // After crop interface is loaded, update the overlay height as the crop interface might have
    // increased the overall page height.
    //arrayPageScroll = getPageScroll();
    objOverlay.style.height = (screen.height + arrayPageSize[1]) + 'px';

    //display the crop interface
    objLightbox.style.display = 'block';
    objLightbox.style.zIndex = 502;

    objFrame.style.zIndex = 503;



    //	var fObj = document.getElementById('flashObj');
    //	if(fObj != null)
    //	    fObj.style.visibility='hidden';
    //	
    hideSWFObjects();

}
