﻿$(function () {
    //setupNavBar();

    setupNavigation();
    setupThemeNavigation();
    SetupSearchArea();


    $('.leftNavigation > li').bind('mouseenter', function() {

        //$(this).children('.innerStrandNode').removeClass('selected');
        var obj = $(this);
        if (!obj.hasClass('down')) {
            $('.leftNavigation > li.down').removeClass('down').children('ul').slideUp(0);
            obj.addClass('down').children('ul').slideDown(0);
        }
    });

});

function getPath() {
    var loc = window.location;
    var aspxExtention = ".aspx";
    var strippedLocation = loc.href.substring(0, loc.href.length - ((loc.search + loc.hash).length));
    if (strippedLocation.substring(strippedLocation.length - aspxExtention.length, strippedLocation.length) == aspxExtention) {
        aspxExtention = "";
    }
    return strippedLocation + aspxExtention;
}

function setupNavigation() {
    $('.leftNavigation li').each(function () {
        if ($(this).attr('class') != 'down') {
            if (getPath() != $(this).children('ul').children('a').attr('href')) {
                $(this).children('ul').hide();
            } else {
                $(this).parent('ul').removeAttr("style");
                $(this).parent('ul').addClass('down');
            }
        }
    });
}

function setupThemeNavigation() {
    $('.innerStrandNode li').each(function () {
        if ($(this).attr('class') != 'down') {
            var currentPath = getPath();
            if (getPath() != $(this).children('span').children('a').attr('href')) {
                $(this).children('ul').hide();
                $(this).removeClass('selected');
                if (currentPath == $(this).parent('ul').parent('li').children('span').children('a').attr('href')) {
                    $(this).parent('ul').parent('li').children('.leftNavSpan').addClass('selected');
                    $(this).children('ul').show();
                }
            } else {
                $(this).parent('ul').removeAttr("style");
                $(this).parent('ul').parent('li').addClass('down');
                $(this).parent('ul').parent('li').children('.leftNavSpan').removeClass('selected');
                $(this).addClass('selected');

            }
        }
    });
}

function SetupSearchArea() {
    var searchButton = jQuery('#searchSubmit');
    var searchTextbox = jQuery('#searchBox');
    var searchResultsTextbox = jQuery('#searhResultKeywords');

    /* Click function to select text */
    searchTextbox.click(function () { selectAllText(jQuery(this)) });
    /* Note that clearDefaultContent above is also called directly from textbox */

    /* submits form in IE */
    jQuery(function () {
        searchTextbox.keydown(function (e) {
            if (e.keyCode == 13) {
                var btnSubmit = document.getElementById("searchSubmit");
                btnSubmit.click();
                return false;
            }
        });
    });
}

function selectAllText(textbox) {

    textbox.focus();
    textbox.select();
    try {
        if (defaultText != null) {
            if (textbox.val() == defaultText) {
                textbox.val('');
            }
        }
    } catch (ex) {
        textbox.val('');
    }

    
}




