﻿var mintMenuSpeed = 10;
var mintMenuTimer = 10;

function MenuExpand(pstrID) {
    var strMenuHeader = document.getElementById('m' + pstrID);
    var strMenuItems = document.getElementById('i' + pstrID);
    clearInterval(strMenuItems.timer);
    clearTimeout(strMenuHeader.timer);

    if (strMenuItems.maxh && strMenuItems.maxh <= strMenuItems.offsetHeight) {
        return;
    }
    else if (!strMenuItems.maxh) {
        strMenuItems.style.display = 'block';
        strMenuItems.style.height = 'auto';
        strMenuItems.maxh = strMenuItems.offsetHeight;
        strMenuItems.style.height = '0px';
    }
    strMenuItems.timer = setInterval(function () { IncrementOpen(strMenuItems) }, mintMenuTimer);
}

function MenuContract(pstrID) {
    var strMenuHeader = document.getElementById('m' + pstrID);
    var strMenuItems = document.getElementById('i' + pstrID);
    clearInterval(strMenuItems.timer);
    strMenuHeader.timer = setTimeout(function () { MenuItemContract(strMenuItems) }, 50);
}

function MenuItemContract(pstrMenuItems) {
    pstrMenuItems.timer = setInterval(function () { IncrementClose(pstrMenuItems) }, mintMenuTimer);
}

function DelayContract(pstrID) {
    var strMenuHeader = document.getElementById('m' + pstrID);
    var strMenuItems = document.getElementById('i' + pstrID);
    clearTimeout(strMenuHeader.timer);
    clearInterval(strMenuItems.timer);

    if (strMenuItems.offsetHeight < strMenuItems.maxh) {
        strMenuItems.timer = setInterval(function () { IncrementOpen(strMenuItems) }, mintMenuTimer);
    }
}

function IncrementOpen(pstrMenuItems) {

    var intCurrentHeight = pstrMenuItems.offsetHeight;
    var intRemainingDistance = (Math.round((pstrMenuItems.maxh - intCurrentHeight) / mintMenuSpeed));

    if (intRemainingDistance <= 1) {
        intRemainingDistance = 1;
    }

    pstrMenuItems.style.height = intCurrentHeight + intRemainingDistance + 'px';
    pstrMenuItems.style.opacity = intCurrentHeight / pstrMenuItems.maxh;
    pstrMenuItems.style.filter = 'alpha(opacity=' + (intCurrentHeight * 100 / pstrMenuItems.maxh) + ')';

    if (intCurrentHeight > (pstrMenuItems.maxh - 2)) {
        clearInterval(pstrMenuItems.timer);
    }
}

function IncrementClose(pstrMenuItems) {

    var intCurrentHeight = pstrMenuItems.offsetHeight;
    var intRemainingDistance = (Math.round(intCurrentHeight / mintMenuSpeed));

    pstrMenuItems.style.height = intCurrentHeight + (intRemainingDistance * -1) + 'px';
    pstrMenuItems.style.opacity = intCurrentHeight / pstrMenuItems.maxh;
    pstrMenuItems.style.filter = 'alpha(opacity=' + (intCurrentHeight * 100 / pstrMenuItems.maxh) + ')';

    if (intCurrentHeight < 2) {
        clearInterval(pstrMenuItems.timer);
    }
}

function GetXMLDoc(pstrFileName) {

    myIdentifier = Math.round(Math.random() * 10000);


    var vntHTTP = null;

    if (window.XMLHttpRequest) {

        vntHTTP = new XMLHttpRequest();
    }
    else {

        vntHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    }
    vntHTTP.open("GET", pstrFileName + "?uniq=" + myIdentifier, false);
    vntHTTP.send();
    return vntHTTP.responseXML;
}

function GenerateNavBar(pstrMenuXML) {

    var xmlDoc = GetXMLDoc(pstrMenuXML);

    var x = xmlDoc.getElementsByTagName("MENU");

    for (i = 0; i < x.length; i++) {

        document.write("<dl class=\"menu\">");
        document.write("<dt id=\"m");
        document.write(i);
        document.write("\" onmouseover=\"MenuExpand('");
        document.write(i);
        document.write("')\"    onmouseout=\"MenuContract('");
        document.write(i);
        document.write("')\">");
        document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
        document.write("</dt>");
        document.write("<dd id=\"i");
        document.write(i);
        document.write("\" onmouseover=\"DelayContract('");
        document.write(i);
        document.write("')\" onmouseout=\"MenuContract('");
        document.write(i);
        document.write("')\">");
        document.write("<ul>");

        var y = x[i].getElementsByTagName("ITEM");

        for (j = 0; j < y.length; j++) {

            if (!y[j].getElementsByTagName("ITEM_LINK")[0].childNodes[0] && !y[j].getElementsByTagName("ITEM_BASE")[0].childNodes[0]) {
                document.write("<li><div class=\"top-menu-item\">");
            } else {
                document.write("<li><div class=\"top-menu-item\" onclick=\"ResetXMLCloseMenu('" + y[j].getElementsByTagName("ITEM_LINK")[0].childNodes[0].nodeValue + "', '" + y[j].getElementsByTagName("ITEM_BASE")[0].childNodes[0].nodeValue + "', '" + i + "')\">");
            }
            document.write(y[j].getElementsByTagName("ITEM_NAME")[0].childNodes[0].nodeValue);

            document.write("</div></li>")
        }
        document.write("</ul>");
        document.write("</dd>");
        document.write("</dl>");
    }
    document.write("<div style=\"clear:both\" />");
}

function GeneratePage(pstrPageXML) {

    var str;

    str = "Wes are using " + pstrPageXML + "<BR><BR>";

    var xmlDoc = GetXMLDoc("./PageXML/" + pstrPageXML);

    var x = xmlDoc.getElementsByTagName("page_element");
    str = str + x.length
    for (i = 0; i < x.length; i++) {

        str = str + x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue;
    }
    return str;
}

function ResetXMLCloseMenu(pstrPageXML, pstrBase, pstrID) {
    MenuContract(pstrID);
    ResetXML(pstrPageXML, pstrBase, pstrID);
}



function GenerateQuickLinks(pstrQuickLinksXML) {

    var xmlDoc = GetXMLDoc(pstrQuickLinksXML);

    var y = xmlDoc.getElementsByTagName("ROW_ITEM");

    for (j = 0; j < y.length; j++) {

        var x = y[j].childNodes;

        for (i = 0; i < x.length; i++) {

            if (x[i].nodeType == 1) {

                document.write("<ul class=\"QuickLinkTable\">");

                switch (x[i].nodeName) {

                    case "ITEM_ONE":

                        if (!x[i].getElementsByTagName("ITEM_LINK")[0].childNodes[0] && !x[i].getElementsByTagName("ITEM_BASE")[0].childNodes[0]) {
                            document.write("<li class=\"QuickLinkTable\"><div class=\"QuickLinkTable_One\" ");
                        } else {
                            document.write("<li class=\"QuickLinkTable\"><div class=\"QuickLinkTable_One\"  id=\"I1_" + j + "\" onclick=\"ResetXML('" + x[i].getElementsByTagName("ITEM_LINK")[0].childNodes[0].nodeValue + "','" + x[i].getElementsByTagName("ITEM_BASE")[0].childNodes[0].nodeValue + "','I1_" + j + "')\" ");
                        }

                        if (x[i].getElementsByTagName("ITEM_PIC")[0].childNodes[0]) {
                            document.write("style=\"background-image:url(" + x[i].getElementsByTagName("ITEM_PIC")[0].childNodes[0].nodeValue + ");\" ");
                        }
                        document.write(">");
                        if (x[i].getElementsByTagName("ITEM_NAME")[0].childNodes[0]) {
                            document.write(x[i].getElementsByTagName("ITEM_NAME")[0].childNodes[0].nodeValue);
                        }
                        document.write("</div></li></ul>");

                        break;

                    case "ITEM_TWO":
                        if (!x[i].getElementsByTagName("ITEM_LINK_ONE")[0].childNodes[0] && !x[i].getElementsByTagName("ITEM_BASE_ONE")[0].childNodes[0]) {
                            document.write("<li class=\"QuickLinkTable\"><div class=\"QuickLinkTable_Two\" ");
                        } else {
                            document.write("<li class=\"QuickLinkTable\"><div class=\"QuickLinkTable_Two\" id=\"I2A_" + j + "\" onclick=\"ResetXML('" + x[i].getElementsByTagName("ITEM_LINK_ONE")[0].childNodes[0].nodeValue + "','" + x[i].getElementsByTagName("ITEM_BASE_ONE")[0].childNodes[0].nodeValue + "','I2A_" + j + "')\" ");
                        }
                        if (x[i].getElementsByTagName("ITEM_PIC_ONE")[0].childNodes[0]) {
                            document.write("style=\"background-image:url(" + x[i].getElementsByTagName("ITEM_PIC_ONE")[0].childNodes[0].nodeValue + ");\" ");
                        }
                        document.write(">");
                        if (x[i].getElementsByTagName("ITEM_NAME_ONE")[0].childNodes[0]) {
                            document.write(x[i].getElementsByTagName("ITEM_NAME_ONE")[0].childNodes[0].nodeValue);
                        }
                        document.write("</div></li>");

                        if (!x[i].getElementsByTagName("ITEM_LINK_TWO")[0].childNodes[0] && !x[i].getElementsByTagName("ITEM_BASE_TWO")[0].childNodes[0]) {
                            document.write("<li class=\"QuickLinkTable\"><div class=\"QuickLinkTable_Two\"");
                        } else {
                            document.write("<li class=\"QuickLinkTable\"><div class=\"QuickLinkTable_Two\" id=\"I2B_" + j + "\" onclick=\"ResetXML('" + x[i].getElementsByTagName("ITEM_LINK_TWO")[0].childNodes[0].nodeValue + "','" + x[i].getElementsByTagName("ITEM_BASE_TWO")[0].childNodes[0].nodeValue + "','I2B_" + j + "')\" ");
                        }
                        if (x[i].getElementsByTagName("ITEM_PIC_TWO")[0].childNodes[0]) {
                            document.write("style=\"background-image:url(" + x[i].getElementsByTagName("ITEM_PIC_TWO")[0].childNodes[0].nodeValue + ");\"");
                        }
                        document.write(">");
                        if (x[i].getElementsByTagName("ITEM_NAME_TWO")[0].childNodes[0]) {
                            document.write(x[i].getElementsByTagName("ITEM_NAME_TWO")[0].childNodes[0].nodeValue);
                        }
                        document.write("</div></li></ul>");

                    default:

                }
            }
        }
    }
}

// JavaScript Document
function VidDisplay() {

}
//MSG
function VidDisplay(pstrVideoLink) {


    document.getElementById("VideoPlayer").src = pstrVideoLink + "&autoplay=1";

    document.getElementById("VideoPlayer").style.visibility = "visible";
    document.getElementById("popup_background").style.visibility = "visible";
    document.getElementById("popup_content").style.visibility = "visible";
    document.getElementById("player").style.visibility = "visible";

}

function VidHide() {
    document.getElementById("VideoPlayer").style.visibility = "hidden";
    document.getElementById("popup_background").style.visibility = "hidden";
    document.getElementById("popup_content").style.visibility = "hidden";
    document.getElementById("player").style.visibility = "hidden";
    document.getElementById("VideoPlayer").src = "";
}


function VidDisplay1() {
    document.getElementById("popup_background").style.display = "none";
}


function VidHide1() {
    document.getElementById("popup_background").style.display = "block";
}

