// Navigation menus
function initializeNavigation() {
    // Main navigation
    function initializeMainNavigation() {
        // When the mouse enters a navigation anchor, make the respective navigation panel visible
        $("#main-navigation ul li a").mouseenter(

        function () {
            $(this).parent().find("div").css("visibility", "visible");
        });
        // When the mouse leaves a navigation anchor, hide the respective navigation panel
        $("#main-navigation ul li a").mouseleave(

        function () {
            $(this).parent().find("div").css("visibility", "hidden");
        });
        // When the mouse enters a visible navigation panel, maintain its visibility
        $("#main-navigation .main-navigation-panel").mouseenter(

        function () {
            $(this).css("visibility", "visible");
            // Maintain the :hover style of the panel's sibling anchor by appending .selected to it
            $(this).prev("a").addClass("selected");
        });
        // When the mouse leaves a visible navigation panel, hide that panel
        $("#main-navigation .main-navigation-panel").mouseleave(

        function () {
            $(this).css("visibility", "hidden");
            // Remove the :hover style of the panel's sibling anchor by removing .selected from it
            $(this).prev("a").removeClass("selected");
        });
    }
    // Section navigation
    function initializeSectionNavigation() {
        // Hide all lists
        $('#section-nav ul').hide();
        //Show the first list
        $('#section-nav ul:first').show();
        //Change cursor to pointer when hovering over a clickable section heading
        $('#section-nav h5').hover(

        function () {
            $(this).addClass('mouse-pointer');
        }, function () {
            $(this).removeClass('mouse-pointer');
        });
        //When a section heading is clicked
        $('#section-nav h5').click(

        function () {
            var checkElement = $(this).parentsUntil('.section').parent().next().find('ul');
            //Check to see if the list is already open
            if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                //Links within h5s should work if list is open
                //return false;
            }
            //If the list is not already open, hide the others, and display the list
            if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $(this).parentsUntil('.section').parent().parent().find('ul').slideUp('100');
                $(this).parentsUntil('.section').parent().next().find('ul').slideToggle('100');
                return false;
            }
        });
    }
    // Promo Module Rotator
    function initializePromoModuleRotator() {
        $('#promo-module-rotator li').eq(0).removeClass('display-block');
        var numberOfPromos = $('#promo-module-rotator li').size();
        var thisPromo = ((Math.floor(Math.random() * numberOfPromos) + 1) - 1);
        $('#promo-module-rotator li').eq(thisPromo).addClass('display-block');
    }
    // Quotation Rotator
    function initializeQuotationRotator() {
        var numberOfQuotes = $('#quotation-rotator li').size();
        var thisQuote = (Math.floor(Math.random() * numberOfQuotes) + 1);
        $('#quotation-rotator li').eq(0).removeClass('visible');
        $('#quotation-rotator li').css({'opacity':0});
        $('#quotation-rotator li').eq(thisQuote).addClass('visible').css({'opacity':1});
        function changeQuote() {
            $('#quotation-rotator li').eq(thisQuote).animate({'opacity':0}, 500, function(){
                $(this).removeClass('visible');
            });
            if (thisQuote<(numberOfQuotes-1)){
                thisQuote++;
            } else {
                thisQuote=0;
            }
            $('#quotation-rotator li').eq(thisQuote).addClass('visible');
            $('#quotation-rotator li').eq(thisQuote).animate({'opacity':1}, 500);
        }      
        setInterval(changeQuote, 12000);
    }
    // Initialize functions
    initializeMainNavigation();
    initializeSectionNavigation();
    if ($('#promo-module-rotator').length > 0) {
        initializePromoModuleRotator();
    }
    if ($('#quotation-rotator').length > 0) {
        initializeQuotationRotator();
    }
}


// Homepage
function initializeHomepage() {
    // Carousel
    function initializeCarousel() {
        function translatePanelNumber(x) {
            if (x === 8) {
                return "eight";
            } else if (x === 7) {
                return "seven";
            } else if (x === 6) {
                return "six";
            } else if (x === 5) {
                return "five";
            } else if (x === 4) {
                return "four";
            } else if (x === 3) {
                return "three";
            } else if (x === 2) {
                return "two";
            } else {
                return "one";
            }
        }

        function panelRotatorSwitch() {
            $('#homepage-carousel .homepage-carousel-panel:nth-child(' + (thisPanel) + ')').removeClass('visible');
            $('ul#homepage-carousel-navigation li:nth-child(' + (thisPanel) + ') a').removeClass('homepage-carousel-navigation-' + translatePanelNumber(thisPanel) + '-active');
            if (thisPanel === numberOfPanels) {
                thisPanel = 1;
            } else {
                thisPanel++;
            }
            $('#homepage-carousel .homepage-carousel-panel:nth-child(' + (thisPanel) + ')').addClass('visible');
            $('ul#homepage-carousel-navigation li:nth-child(' + (thisPanel) + ') a').addClass('homepage-carousel-navigation-' + translatePanelNumber(thisPanel) + '-active');
        }

        function carouselNavigationSwitch(x) {
            if (x !== thisPanel) {
                $('#homepage-carousel .homepage-carousel-panel:nth-child(' + (thisPanel) + ')').removeClass('visible');
                $('ul#homepage-carousel-navigation li:nth-child(' + (thisPanel) + ') a').removeClass('homepage-carousel-navigation-' + translatePanelNumber(thisPanel) + '-active');
                thisPanel = x;
                $('#homepage-carousel .homepage-carousel-panel:nth-child(' + (thisPanel) + ')').addClass('visible');
                $('ul#homepage-carousel-navigation li:nth-child(' + (thisPanel) + ') a').addClass('homepage-carousel-navigation-' + translatePanelNumber(thisPanel) + '-active');
            } else {
                return;
            }
        }
        // Count the number of panels
        var numberOfPanels = $('#homepage-carousel .homepage-carousel-panel').size();
        // Randomly assign a panel as the initial panel
        var thisPanel = (Math.floor(Math.random() * numberOfPanels) + 1);
        //var thisPanel = 1;
        // Load the initial panel and select it's navigation button
        $('#homepage-carousel .homepage-carousel-panel:nth-child(' + (thisPanel) + ')').addClass('visible');
        $('ul#homepage-carousel-navigation li:nth-child(' + (thisPanel) + ') a').addClass('homepage-carousel-navigation-' + translatePanelNumber(thisPanel) + '-active');
        // Turn on the panel rotator
        var panelRotatorOn = 1;

        function panelRotator() {
            if (panelRotatorOn === 1) {
                panelRotatorSwitch();
            }
        }
        setInterval(panelRotator, 6000);
        // Listen for carousel navigation buttons to be clicked
        var thisButton = 1;
        $('a#homepage-carousel-navigation-one').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 1;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-two').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 2;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-three').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 3;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-four').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 4;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-five').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 5;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-six').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 6;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-seven').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 7;
            carouselNavigationSwitch(thisButton);
        });
        $('a#homepage-carousel-navigation-eight').click(function (e) {
            e.preventDefault();
            panelRotatorOn = 0;
            thisButton = 8;
            carouselNavigationSwitch(thisButton);
        });
    }
    // Scrolling background
    function initializeBackground() {
        var homepageBackgroundScrollSpeedOne = 120;
        var homepageBackgroundScrollSpeedTwo = 80;
        var homepageBackgroundScrollSpeedThree = 40;
        var homepageBackgroundScrollPositionOne = 0;
        var homepageBackgroundScrollPositionTwo = 0;
        var homepageBackgroundScrollPositionThree = 0;

        function homepageBackgroundScrollOne() {
            homepageBackgroundScrollPositionOne -= 1;
            $('#homepage-content-wrapper-one').css("backgroundPosition", homepageBackgroundScrollPositionOne + "px 0");
        }

        function homepageBackgroundScrollTwo() {
            homepageBackgroundScrollPositionTwo -= 1;
            $('#homepage-content-wrapper-two').css("backgroundPosition", homepageBackgroundScrollPositionTwo + "px 0");
        }

        function homepageBackgroundScrollThree() {
            homepageBackgroundScrollPositionThree -= 1;
            $('#homepage-content-wrapper-three').css("backgroundPosition", homepageBackgroundScrollPositionThree + "px 0");
        }
        setInterval(homepageBackgroundScrollOne, homepageBackgroundScrollSpeedOne);
        setInterval(homepageBackgroundScrollTwo, homepageBackgroundScrollSpeedTwo);
        setInterval(homepageBackgroundScrollThree, homepageBackgroundScrollSpeedThree);
    }
    // Modules
    function initializeModules() {
        var moduleWidth = 180;
        var modulesNumber = $('#homepage-content-left-modules-wrapper ul li').size();
        var modulesOffset = 0;
        var modulesOffsetLimit = (moduleWidth * (modulesNumber - 3));
        if (modulesNumber > 4) {
            $('a#homepage-content-left-modules-navigation').addClass('visible');
        }

        function modulesRotate() {
            modulesOffset += moduleWidth;
            if (modulesOffset === modulesOffsetLimit) {
                modulesOffset = 0;
                $('#homepage-content-left-modules-wrapper ul').animate({
                    left: "0px"
                }, 500);
            } else {
                $('#homepage-content-left-modules-wrapper ul').animate({
                    left: "-" + modulesOffset + "px"
                }, 250);
            }
        }
        $('a#homepage-content-left-modules-navigation').click(function (e) {
            e.preventDefault();
            modulesRotate();
        });
    }
    // Ticker
    // May cause slowdown
    function initializeTicker() {
        var numberOfItems = $('#homepage-content-left-ticker-wrapper ul li').size();
        var thisItem = 0;
        if (numberOfItems > 1) {
            $('#homepage-content-left-ticker-wrapper ul li').css({'opacity':0});
            $('#homepage-content-left-ticker-wrapper ul li').eq(thisItem).addClass('visible').css({'opacity':1});
        }
        numberOfItems = --numberOfItems;
        function changeItem() {
            if (thisItem < numberOfItems) {
                $('#homepage-content-left-ticker-wrapper ul li').eq(thisItem).animate({'opacity':0}, 250, function(){
                    $(this).removeClass('visible');
                });
                thisItem++;
                $('#homepage-content-left-ticker-wrapper ul li').eq(thisItem).addClass('visible');
                $('#homepage-content-left-ticker-wrapper ul li').eq(thisItem).animate({'opacity':1}, 250);
            } else {
                $('#homepage-content-left-ticker-wrapper ul li').eq(thisItem).animate({'opacity':0}, 250, function(){
                    $(this).removeClass('visible');
                });
                thisItem = -1;
                changeItem();
            }
        }
        setInterval(changeItem, 7000);
    }
    // Feeds
    function initializeFeeds() {
        var itemsNumberFeedOne = $('#homepage-content-left-feed-one ul li').size();
        var itemsNumberFeedTwo = $('#homepage-content-left-feed-two ul li').size();
        var itemsGroupHeight = 228;
        var itemsOffsetFeedOne = 0;
        var itemsOffsetFeedTwo = 0;
        var itemsOffsetLimitOne = (itemsGroupHeight * itemsNumberFeedOne);
        var itemsOffsetLimitTwo = (itemsGroupHeight * itemsNumberFeedTwo);
        $('#homepage-content-left-feed-one a.homepage-content-left-feed-navigation-up').click(function (e) {
            e.preventDefault();
            feedUp();
        });
        $('#homepage-content-left-feed-one a.homepage-content-left-feed-navigation-down').click(function (e) {
            e.preventDefault();
            feedDown();
        });
        $('#homepage-content-left-feed-two a.homepage-content-left-feed-navigation-up').click(function (e) {
            e.preventDefault();
        });
        $('#homepage-content-left-feed-two a.homepage-content-left-feed-navigation-down').click(function (e) {
            e.preventDefault();
        });

        function feedUp() {
            itemsOffsetFeedOne += itemsGroupHeight;
            $('#homepage-content-left-feed-one ul').animate({
                top: "-" + itemsOffsetFeedOne + "px"
            }, 500);
        }

        function feedDown() {
            itemsOffsetFeedOne -= itemsGroupHeight;
            $('#homepage-content-left-feed-one ul').animate({
                top: "-" + itemsOffsetFeedOne + "px"
            }, 500);
        }
    } 
    // Promotions
    // Starts at 2 because navigation and items are siblings and both are anchors
    function initializePromotions() {
        function promoSwitch() {
            $('a.homepage-content-right-item:eq(' + (thisPromo) + ')').removeClass('visible');
            if (thisPromo === (numberOfPromos - 1)) {
                thisPromo = 0;
            } else {
                thisPromo++;
            }
            $('a.homepage-content-right-item:eq(' + (thisPromo) + ')').addClass('visible');
        }
        // Count the number of promos
        var numberOfPromos = $('a.homepage-content-right-item').size();
        //var thisPromo = Math.floor(Math.random() * (numberOfPromos));
        var thisPromo = 1;
        // Load the initial promo
        $('a.homepage-content-right-item:eq(' + (thisPromo) + ')').addClass('visible');
        // Listen for promo navigation button to be clicked
        $('a#homepage-content-right-navigation').click(function (e) {
            e.preventDefault();
            promoSwitch();
        });
    }
    // Initialize functions
    initializeCarousel();
    //initializeBackground();
    initializeModules();
    initializeTicker();
    //initializeFeeds();
    initializePromotions();
}


// Modal windows
function initializeModalWindows(){
  // Insert the page mask
  $('body').prepend('<div id=\"modal-window-page-mask\" class=\"close-modal-window\"></div>');
  // When a modal window activation link is clicked
  $('.activate-modal-window').click(function(e){
    e.preventDefault();
    // Retrieve the modal window's id from the name value of the activating element
    var modalWindowID = $(this).attr('name');
    // Pass the modal window's id to the showModalWindow function
    showModalWindow(modalWindowID);
  });
  // When a modal window's close button is clicked
  $('.close-modal-window').click(function(){
    closeModalWindows();
  });
  // When the browser window is resized
  $(window).resize(function(){
    centerModalWindows();
  });
  function showModalWindow(modalWindowID) {
    // Make the page mask visible and set its opacity to 0, and fade it in
    $('#modal-window-page-mask').css({'visibility':'visible',opacity:0}).fadeTo(100,0.8);
    // Center any modal windows
    centerModalWindows();
    // Show the modal window
    $('#'+modalWindowID).css({'visibility':'visible',opacity:0}).fadeTo(200,1);
  }
  function closeModalWindows(){
    // Hide the mask
    $('#modal-window-page-mask').fadeOut(200);
    // Hide any modal windows
    $('.modal-window').fadeOut(100);
  }
  function centerModalWindows(){
    // Center each modal window
    $('.modal-window').each(function(){
      // Determine width and height of the modal window
      var modalWindowWidth = $(this).outerWidth();
      var modalWindowHeight = $(this).outerHeight();
      // Calculate the left and top offsets
      var left=(0-(modalWindowWidth/2));
      var top=(0-(modalWindowHeight/2));
      // Apply left and top values to modal window CSS
      $(this).css({'margin-top':top,'margin-left':left});
    });
  }
}

// Slide viewer
function initializeSlideViewer() {
    var slideViewerPreviousSlide = 1;
    var slideViewerThisSlide = 1;
    var $slideViewerCaption = 'Default Caption';
    function slideViewerSwitch() {
        // Replace previous slide's captionwith empty span
        $('.slide-viewer li:nth-child(' + (slideViewerPreviousSlide) + ') .slide-viewer-caption').replaceWith('<span class="slide-viewer-caption"></span>');
        // Get caption from this slide's alt attribute
        $slideViewerCaption = $('.slide-viewer img:nth-child(' + (slideViewerThisSlide + 1) + ')').attr('alt');
        // Insert caption into this button's span
        $('.slide-viewer li:nth-child(' + (slideViewerThisSlide) + ') .slide-viewer-caption').replaceWith('<span class="slide-viewer-caption">: ' + $slideViewerCaption + '</span>');

        $('.slide-viewer img:nth-child(' + (slideViewerThisSlide + 1) + ')').addClass('slide-viewer-active');
        $('.slide-viewer li:nth-child(' + (slideViewerThisSlide) + ') a').addClass('slide-viewer-button-active');
        if (slideViewerThisSlide !== slideViewerPreviousSlide) {
            $('.slide-viewer img:nth-child(' + (slideViewerPreviousSlide + 1) + ')').removeClass('slide-viewer-active');
            $('.slide-viewer li:nth-child(' + (slideViewerPreviousSlide) + ') a').removeClass('slide-viewer-button-active');
        }
        // Prepare this slide to change by assigning it as the previous slide
        slideViewerPreviousSlide = slideViewerThisSlide;
    }
    function slideViewer() {
        // Determine how many slides are being used
        var $slideViewerNumberOfSlides = $('.slide-viewer img').size();
        // When a button is clicked, navigate to that slide
        $('.slide-viewer-controls li').click(function () {
            var slideViewerThisButton = $(this);
            slideViewerThisSlide = (slideViewerThisButton.prevAll('li').length + 1);
            slideViewerSwitch();
        });
        // Prevent link from performing default behavior
        $('.slide-viewer-controls li a').click(function (event) {
            event.preventDefault();
        });
        // When a slide is clicked, navigate to the next slide
        $('.slide-viewer img').click(function () {
            if (slideViewerThisSlide < $slideViewerNumberOfSlides) {
                slideViewerThisSlide++;
                slideViewerSwitch();
            } else {
                slideViewerThisSlide = 1;
                slideViewerSwitch();
            }
        });
    }
    // Initialize function
    slideViewer();
}


// Popup slideshow
function initializePopupSlideshow() {
  // Define variables
  var ie7=false;
  var numberOfSlides=0;
  var currentSlide=0;
  var slides="";
  var $slideSetItems=$('.popup-slideshow-slideset li');
  var $popupSlideshow=$('.popup-slideshow');
  // Compile slides from all the slidesets
  $slideSetItems.each(function(){
    // Get each slide's img src attribute
    var source=$(this).children('img').attr('src');
    // Get each slide's img alt attribute
    var caption=$(this).children('img').attr('alt');
    // Append the slide li to the slides variable
    slides = (slides+('<li><img src="'+source+'" alt="'+caption+'"/><span class="popup-slideshow-caption">'+caption+'</span></li>'));
    // Add slide to overall count
    numberOfSlides++
  });
  // Append slides to slideshow
  $('#popup-slideshow ul').append(slides);
  // When a trigger link is clicked
  $('a.popup-slideshow-trigger').click(function(event){
    event.preventDefault();
    // Determine next slide's position in overall list
    // Remove .popup-slideshow-initial-slide class
    $slideSetItems.removeClass('popup-slideshow-initial-slide');
    // Add .popup-slideshow-initial-slide class to the next initial slide's slideset list item
    $(this).next().find("li").eq(0).addClass('popup-slideshow-initial-slide');
    var nextInitialSlide=0;
    // Set the current slide index equal to the index of the initial slide's slideset list item
    $slideSetItems.each(function(){
      if ($(this).hasClass('popup-slideshow-initial-slide')===true){
        currentSlide=nextInitialSlide;
      } else {
        nextInitialSlide++;
      }
    });
    changeSlide(currentSlide);
  });
  // Slideshow nav
  // Arrow keys
//  $(document).keydown(function(e){
//    if (e.keyCode===37 && currentSlide!==0) { 
//      currentSlide--;
//      changeSlide(currentSlide);
//      return false;
//    } else if (e.keyCode===39 && currentSlide!==numberOfSlides-1) { 
//      currentSlide++;
//      changeSlide(currentSlide);
//      return false;
//    }
//  });
  // Nav buttons
  $('#popup-slideshow-nav-previous').click(function(event){
    event.preventDefault();
    currentSlide--;
    changeSlide(currentSlide);
  });
  $('#popup-slideshow-nav-next').click(function(event){
    event.preventDefault();
    currentSlide++;
    changeSlide(currentSlide);
  });
  // Slide change function
  function changeSlide(currentSlide){
    // Hide previous slide
    $('#popup-slideshow ul li').removeClass('current-slide');
    $('#popup-slideshow ul li').eq(currentSlide).addClass('current-slide');
    // If currentSlide is first slide, hide the previous nav button
    if(currentSlide===0){
      $('#popup-slideshow-nav-previous').css('visibility','hidden');
    } else{
      $('#popup-slideshow-nav-previous').css('visibility','visible');
    }
    // If currentSlide is last slide, hide the next nav button
    if(currentSlide===numberOfSlides-1){
      $('#popup-slideshow-nav-next').css('visibility','hidden');
    } else{
      $('#popup-slideshow-nav-next').css('visibility','visible');
    }
    // Set caption width to the image's width
    $('#popup-slideshow ul').css('width',$('#popup-slideshow ul li.current-slide img').width());
    // Set slideshow width to the image's width plus border
    $popupSlideshow.css('width',($('#popup-slideshow ul li.current-slide img').width()+84));
  }
}





// Basic slideshow
function initializeBasicSlideshow() {
    // Define variables
    var basicSlideshowNumberOfSlides = 1;
    var basicSlideshowThisSlide = 1;
    var basicSlideshowNextSlide = 1;

    function basicSlideshowSwitch(x) {
        $('.basic-slideshow ul li:nth-child(' + (x) + ')').addClass('basic-slideshow-active');
        $('.basic-slideshow ul li:nth-child(' + (basicSlideshowThisSlide) + ')').removeClass('basic-slideshow-active');
        basicSlideshowThisSlide = x;
        $(".basic-slideshow .basic-slideshow-controls p").html("Slide " + basicSlideshowThisSlide + " of " + basicSlideshowNumberOfSlides);
    }

    function basicSlideshow() {
        // Determine how many slides are being used
        basicSlideshowNumberOfSlides = $('.basic-slideshow ul li img').size();
        // Set previous slide to last slide
        basicSlideshowPreviousSlide = basicSlideshowNumberOfSlides;
        // Display location within controls
        $(".basic-slideshow .basic-slideshow-controls p").html("Slide " + basicSlideshowThisSlide + " of " + basicSlideshowNumberOfSlides);
        // Display first slide
        $('.basic-slideshow ul li:nth-child(1)').addClass('basic-slideshow-active');
        // When next button is clicked, navigate to next slide
        $('a.basic-slideshow-next').click(function (e) {
            e.preventDefault();
            if (basicSlideshowThisSlide === basicSlideshowNumberOfSlides) {
                basicSlideshowNextSlide = 1;
                basicSlideshowSwitch(basicSlideshowNextSlide);
            } else {
                basicSlideshowNextSlide++;
                basicSlideshowSwitch(basicSlideshowNextSlide);
            }
        });
        // When previous button is clicked, navigate to previous slide
        $('a.basic-slideshow-previous').click(function (e) {
            e.preventDefault();
            if (basicSlideshowThisSlide === 1) {
                basicSlideshowNextSlide = basicSlideshowNumberOfSlides;
                basicSlideshowSwitch(basicSlideshowNextSlide);
            } else {
                basicSlideshowNextSlide--;
                basicSlideshowSwitch(basicSlideshowNextSlide);
            }
        });
    }
    // Initialize function
    basicSlideshow();
}


// Network automation quiz
function initializeAutomationQuiz() {
    function stringToNumber(x) {
        return (parseFloat(x));
    }

    function automationQuizSetValue(x) {
        if (x.checked === true) {
            return (x.value);
        } else {
            return (0);
        }
    }

    function automationQuizScore() {
        var automationQuizTotalScore = stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizOne)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTwo)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizThree)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizFour)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizFive)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizSix)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizSeven)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizEight)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizNine)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizEleven)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTwelve)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizThirteen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizFourteen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizFifteen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizSixteen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizSeventeen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizEighteen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizNineteen)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTwenty)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTwentyOne)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTwentyTwo)) + stringToNumber(automationQuizSetValue(document.automationQuiz.automationQuizTwentyThree));
        var automationScoreMeter;
        var headline;
        var message;
        if (automationQuizTotalScore >= 200) {
            automationScoreMeter = "4";
            headline = "Outstanding";
            message = "Your company and IT organization are in stellar shape, having scored " + automationQuizTotalScore + " points! Your network should be in <strong>outstanding</strong> condition with regard to automation. Keep up the great work!";
        } else if (automationQuizTotalScore >= 150 && automationQuizTotalScore < 200) {
            automationScoreMeter = "3";
            headline = "Above Average";
            message = "Your IT organization is doing very well compared to most others. You scored <strong>above average</strong> with " + automationQuizTotalScore + " points&mdash;but less than the target 200 points. To bridge the gap and become a stellar organization, look for areas that could be further automated. The areas that you did not check off in this assessment are great places to start.";
        } else if (automationQuizTotalScore >= 100 && automationQuizTotalScore < 150) {
            automationScoreMeter = "2";
            headline = "Below Average";
            message = "Your IT organization's automation strategy has scored <strong>below average</strong>. Your score of " + automationQuizTotalScore + " points was less than the 150 point average. You should look for ways to increase automation and scale to support your business services. The areas that you did not check off in this assessment are great places to start.";
        } else {
            automationScoreMeter = "1";
            headline = "Danger Zone";
            message = "You network is at risk of failure and may have availability, compliance, and security issues. You have scored in the <strong>danger zone</strong> with " + automationQuizTotalScore + " points&mdash;much lower than average&mdash;and should take immediate action to correct issues, as well as look into automation to improve efficiencies and scalability. The areas that you did not check off in this assessment are great places to start your automation strategy.";
        }
        $("#network-automation-quiz-panel-score").html("<h3>Your Score</h3><h4>" + headline + "</h4><img src=\"/content/dam/infoblox/images/resources/network-automation-center/automation-score-meter-" + automationScoreMeter + ".jpg\" alt=\"Your Score\"><p>" + message + "</p>");
    }

    function automationQuiz() {
        $("a.network-automation-quiz-next").click(function (e) {
            e.preventDefault();
            $(this).parent().removeClass("network-automation-quiz-panel-active");
            $(this).parent().next().addClass("network-automation-quiz-panel-active");
        });
        $("a.network-automation-quiz-score").click(function (e) {
            e.preventDefault();
            automationQuizScore();
            $(this).parent().removeClass("network-automation-quiz-panel-active");
            $(this).parent().next().addClass("network-automation-quiz-panel-active");
        });
    }
    // Initialize function
    automationQuiz();
}


// IPv6 challenge
function initializeIpvsixChallenge() {
    function ipvsixChallenge() {
        // Function variables
        var characterList = "0123456789abcdef";
        var characterGroup = "";
        var ipAddress = "";
        var ipAddressSubmission = "";
        // Validate the user submission and display appropriate results page


        function validateIPAddress() {
            ipAddressSubmission = document.getElementById("ip-address-submission").value;
            if (ipAddressSubmission === ipAddress) {
                // Show winner message
                $('#ipvsix-challenge-page-three').removeClass("ipvsix-challenge-page-visible");
                $('#ipvsix-challenge-page-five').addClass("ipvsix-challenge-page-visible");
            } else {
                // Show loser message
                $('#ipvsix-challenge-page-three').removeClass("ipvsix-challenge-page-visible");
                $('#ipvsix-challenge-page-four').addClass("ipvsix-challenge-page-visible");
            }
        }
        // Hide the IP address and show the submission area


        function hideIPAddress() {
            $('#ipvsix-challenge-page-two').removeClass("ipvsix-challenge-page-visible");
            $('#ipvsix-challenge-page-three').addClass("ipvsix-challenge-page-visible");
        }

        function displayIPAddress() {
            // Remove any existing data in the user submission input
            document.getElementById("ip-address-submission").value = "";
            // Empty variables
            characterGroup = "";
            ipAddress = "";
            // Run 8 times
            for (b = 0; b < 8; b++) {
                // Empty characterGroup each time
                characterGroup = "";
                // Concatenate 4 characters
                for (a = 0; a < 4; a++) {
                    characterGroup += characterList.charAt(Math.floor(Math.random() * characterList.length));
                }
                // Add a colon at the end of each group and concatenate onto existing string
                ipAddress += (characterGroup + ":");
            }
            // Remove the last colon
            ipAddress = ipAddress.slice(0, -1);
            // Insert the address in page two's readout
            $("#ipvsix-challenge-page-two .ipvsix-challenge-readout").html(ipAddress);
            // Change the page after 20 seconds
            setTimeout(hideIPAddress, 20000);
            // Hide pages one and four and show page two
            $('#ipvsix-challenge-page-one').removeClass("ipvsix-challenge-page-visible");
            $('#ipvsix-challenge-page-four').removeClass("ipvsix-challenge-page-visible");
            $('#ipvsix-challenge-page-two').addClass("ipvsix-challenge-page-visible");
        }
        $('a#ipvsix-challenge-show-address').click(function (e) {
            e.preventDefault();
            displayIPAddress();
        });
        $('a#ipvsix-challenge-submit').click(function (e) {
            e.preventDefault();
            validateIPAddress();
        });
        $('a#ipvsix-challenge-reset').click(function (e) {
            e.preventDefault();
            displayIPAddress();
        });
    }
    // Initialize function
    ipvsixChallenge();
}


// Initialization
$(document).ready(function(){
  initializeNavigation();
  if ($('#homepage-content').length>0){
    initializeHomepage();
  }
  initializeModalWindows();
  initializeSlideViewer();
  initializePopupSlideshow();
  initializeBasicSlideshow();
  if ($('#network-automation-quiz').length>0){
    initializeAutomationQuiz();
  }
  if ($('#ipvsix-challenge').length>0){
    initializeIpvsixChallenge();
  }
  // Search input
  $('.search_input').click(function(){
    $(this).focus();
    $(this).select();
  });
});
