﻿var VideoModal = (function() {
    function fnVideoModalConstructor() {
        /****************************************************/
        /*                                                  */
        /*                                                  */
        /*                 Private Variables                */
        /*                                                  */
        /*                                                  */
        /****************************************************/

        var sHiddenClassName = "Hidden";

        var oInstance, oContainer, oDialog, oCloseButton, oOverlay, oCallToActionLink;
        var aVideos = new Array();
        var iCurrentVideo;

        /****************************************************/
        /*                                                  */
        /*                                                  */
        /*                  Event Handlers                  */
        /*                                                  */
        /*                                                  */
        /****************************************************/

        function oCloseButton_onClick(event) {
            var oVideo = $("swf" + iCurrentVideo);



            try {
                oVideo.seekTo(0);
                oVideo.pauseVideo();

            }
            catch (eException) {
                //oVideo.viddlerSeek(0);
                //oVideo.viddlerPause();
            }
            finally {
                oInstance.hideModal();
                aVideos[iCurrentVideo].addClassName(sHiddenClassName);

                Event.stop(event);
            }

            var delCallToAction = document.getElementById('calltoActionLink');
            if (delCallToAction != null) {
                delCallToAction.parentNode.removeChild(delCallToAction);
            }

        }

        /****************************************************/
        /*                                                  */
        /*                                                  */
        /*                Accessors/Mutators                */
        /*                                                  */
        /*                                                  */
        /****************************************************/


        /****************************************************/
        /*                                                  */
        /*                                                  */
        /*          Class Level Priveleged Methods          */
        /*                                                  */
        /*                                                  */
        /****************************************************/

        this.hideModal = function() {
            $$("html").first().setStyle({ overflow: "auto" });
            oContainer.addClassName(sHiddenClassName);
        }

        this.hideCurrentVideo = function() {
            if (iCurrentVideo) {
                aVideos[iCurrentVideo].addClassName(sHiddenClassName);
                iCurrentVideo = null;

            }

        }

        this.showModal = function() {
            $$("html").first().setStyle({ overflow: "hidden" });
            var iScrollTop = $$("body").first().cumulativeScrollOffset().top;
            oDialog.setStyle({ top: iScrollTop + (document.viewport.getHeight() - 545) / 2 + "px" });
            oContainer.removeClassName(sHiddenClassName);
        }

        this.showVideo = function(iNewCurrentVideo, calltoactionID) {
            try {
                this.hideCurrentVideo();
                iCurrentVideo = iNewCurrentVideo;
                aVideos[iCurrentVideo].removeClassName(sHiddenClassName);

                var modalCallToActionContent = "";
                var modalCallToActionLink = "";
                var modalCallToActionIcon = "";

                switch (calltoactionID) {
                    case "ctaAPM":
                        modalCallToActionContent = "Download Orion Application Performance Monitor Now <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?Program=857&c=70150000000Dtb9&INTCMP=ILC-Modal-APM-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaIPAM":
                        modalCallToActionContent = "Download Orion IP Address Manager <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?program=911&c=70150000000Eehi&INTCMP=ILC-Modal-IPAM-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaIPSLAM":
                        modalCallToActionContent = "Lock In Your 25% Discount Now <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?Program=945&c=70150000000F6Xa&INTCMP=ILC-Modal-IPSLA-NA-DL"
                        modalCallToActionIcon = ""
                        break;
                    case "cta_IP_SLA_Manager":
                        modalCallToActionContent = " <span style='font-size:14px;'>Try Orion IP SLA Manager Free <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?Program=945&c=70150000000FBRJ&INTCMP=ILC-Modal-IPSLA-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaNCM":
                        modalCallToActionContent = "Download Orion Network Configuration Manager <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?program=617&c=70150000000E1Ii&INTCMP=ILC-Modal-NCM-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "cta_NPM":
                        modalCallToActionContent = "Try Orion Network Performance Monitor <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?program=607&c=70150000000Dlbw&INTCMP=ILC-Modal-NPM-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaNTA":
                        modalCallToActionContent = "Try Orion NTA Free for 30 Days <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?program=815&c=70150000000CgeI&INTCMP=ILC-Modal-NTA-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaToolset":
                        modalCallToActionContent = "Download Engineer's Toolset <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?program=428&c=70150000000D8FL&INTCMP=ILC-Modal-Toolset-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaWMI":
                        modalCallToActionContent = "Download Free WMI Monitor Now <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?Program=937&c=70150000000Ezdb&INTCMP=ILC-Modal-WMI-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "ctaTFTP":
                        modalCallToActionContent = "Download Free TFTP Server Now <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?Program=52&c=70150000000CcH2&INTCMP=ILC-Modal-TFTP-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "cta_Performance":
                        modalCallToActionContent = "Download Orion Performance Pack <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "/register/index.aspx?Program=956&c=70150000000FHt9&INTCMP=ILC-Modal-PerfPack-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    case "cta_NCG":
                        modalCallToActionContent = "Download Network Config Generator <span style='font-size:14px;'>&#187;</span>"
                        modalCallToActionLink = "http://nmueller2-dev/register/index.aspx?Program=968&c=70150000000FRws&INTCMP=ILC-TF_Top_DL&INTCMP=ILC-Modal-NCG-NA-DL"
                        modalCallToActionIcon = "<img src='/images/cta-modal-btn.jpg' class='modalBTN' />"
                        break;
                    default:
                }
                
                oCallToActionLink = new Element("div", { "id": "calltoActionLink" });
                oCallToActionLink.innerHTML = modalCallToActionIcon + "<a href='" + modalCallToActionLink + "'>" + modalCallToActionContent + "</a>";
                oDialog.insert(oCallToActionLink, "bottom");

            }
            catch (eException) {
            }
        }

        this.addVideo = function(sURL) {
            if (sURL && sURL.length > 0) {
                var sHeight = "385";
                var sWidth = "480";
                var oVideo = new Element("div", { "class": sHiddenClassName });
                var sReplaceId = "mov" + aVideos.length.toString();

                oVideo.insert("<div id=\"" + sReplaceId + "\"></div>", "bottom");
                oDialog.insert(oVideo, "bottom");
                swfobject.embedSWF(sURL, sReplaceId, sWidth, sHeight, "8", null, null, { allowFullScreen: "true", allowScriptAccess: "always" }, { id: "swf" + aVideos.length.toString() });
                aVideos.push(oVideo);
            }
        }

        /****************************************************/
        /*                                                  */
        /*                                                  */
        /*            Class Level Private Methods           */
        /*                                                  */
        /*                                                  */
        /****************************************************/

        function attachEvents() {
            Event.observe(oCloseButton, "click", oCloseButton_onClick);
        }

        function initialize() {
            var oBody = $$("body").first();
            var oHead = $$("head").first();



            oContainer = new Element("div", { "class": "VideoModal Hidden" });
            oOverlay = new Element("div", { "class": "VideoModalOverlay" });
            oDialog = new Element("div", { "class": "VideoModalDialog" });
            oCloseButton = new Element("a", { "class": "Close" });
            oCloseButton.innerHTML = "close this window";

            oDialog.insert(oCloseButton, "bottom");

            oContainer.insert(oOverlay, "bottom");
            oContainer.insert(oDialog, "bottom");
            oBody.insert(oContainer, "bottom");

            attachEvents();

        }

        /****************************************************/
        /*                                                  */
        /*                                                  */
        /*                 Initialize Class                 */
        /*                                                  */
        /*                                                  */
        /****************************************************/
        oInstance = this;
        initialize.bind(oInstance)();
    }

    return fnVideoModalConstructor;
})();


//This function should be used only if oVideoModal object is created
function displayVideo(videoID,ctaID) {
    oVideoModal.showVideo(videoID,ctaID);
    oVideoModal.showModal();
}

//This function should be used only if oVideoModal object is created
function initializeView(videoNum,ctaID) {
        var chkVideoTrue = querySt("showvideo");
            if (chkVideoTrue == "true") {
                oVideoModal.showVideo(videoNum,ctaID);
                oVideoModal.showModal();
            }
        }

function querySt(ji) {
        var qstring;
        qstring = window.location.search.substring(1);
        gy = qstring.split("&");
        for (i=0;i<gy.length;i++) {
            ft = gy[i].split("=");
            if (ft[0] == ji) {
            return ft[1];
            }
        }
}