﻿window['dvl'] = window['dvl'] || {};
window['dvl']['navigation'] = window['dvl']['navigation'] || {};

// navigation module
(function (navigation, $, undefined) {
    // add the class 'selected' to the specific link according
    // to whether the page title contains the name of the text
    navigation.setCurrentPage = function(navTarget, pageTitle){
        // get the list items for each nav link
        var topLevelNav = $(navTarget).children('ul').children('li').children('a');
        // split the page title into an array
        var searchTerms = pageTitle.split(" / ");

        // iterate through each nav link
        topLevelNav.each(function(){
            // and then through each search term from the page title
            for(var i = 0; i != searchTerms.length; i++){
                // if the search term is in the link text
                if(searchTerms[i].toUpperCase() 
                    === $(this).text().toUpperCase()){

                    // add selected class and return from callback
                    $(this).parent().addClass('selected');
                    return false;
                }
            }
        });
    };

    navigation.createSubMenus = function(navTarget, subMenuClass){
        
    };
} (window['dvl']['navigation'], jQuery));
