//closure wrap ensures no conflict with any other potential libraries
(function($) {
    $(document).ready(function() {

	
	
	
//Javascript for #columnOne #secondNav and #columnOne .linkswhy navigation
//Default is open if Javascript is turned off


        var path = $.url.parse(document.URL).path;


        // hide paths that do not lead to current menu item in the left menu
        // 'clickable' submenu will render slidedown animation useless since click on submenu
        // will load another page, not slidedown animation


		// find current item and add class current to it
        if ($('#secondNav .current').length == 0) {
            $('#secondNav li a[href=' + path + ']').first().parent().addClass('current');
        }

		// Needed to correct visuals of current element
        if ($('#secondNav .current>a').length != 0) {
            var elem = $('#secondNav .current>a').first();
            var innerHTML = elem.html();
            elem.replaceWith('<span>' + innerHTML + '</span>');
        }

		// Initially, we hide all interior/deeper levels of left navigation
       	$('#secondNav li ul').hide();

		// Not clear why this is needed, but it does assure the tree structure will display visible up to the root
        $('#secondNav .current').parentsUntil('#secondNav').show();

		// Display first level only
        $('#secondNav li.current>ul').show();

        // hide first item
        $('#secondNav>li:first-child').hide();

        // some functionality
        $('#secondNav a[href=#]').parent().click(function() {
            $(this).children('ul').slideToggle();
        });




		
		
		// Carried over from main.js
		$("#secondNav li span").click(function() {
			var treeNode = $(this).parent("li");
			if(treeNode.not(".current").length) {
				treeNode.siblings("li:not(.expandWhenArriving)").children("ul").slideUp();
				treeNode.children("ul").slideToggle();
			}
		});
		jQuery.fn.delay = function(time, func) { this.each(function() { setTimeout(func,time); }); return this; };
		$("body").delay(250, function() {
			$("#secondNav li.expandWhenArriving").each(function() {
				$(this).children("ul").fadeIn(1250);
			});
		});
		$(".linkswhy ul ul").css({ "display":"none" });
		$(".linkswhy li li.current").parent("ul").show();

		$("body").delay(250, function() {
			$(".linkswhy li.current").each(function() {
				$(this).children("ul").slideDown(1250);
			});
		});
		// End of carried over section






        var count = 0;
        if ($('div.linkswhy').length > 0) {
            var height_current  = $('div.linkswhy li.current ul').size();
			var elem1 = $('div.linkswhy li');
            elem1.each(function() {                				
                if(height_current)               
                {
					var text_1 = $('div.linkswhy li.current a').first().text();
					var text_2 = $('div.linkswhy li.current a').first().remove();	
					var text_3 = "<span>" + text_1 +"</span>" + $('div.linkswhy li.current').first().html();			                
					var test1 = $('div.linkswhy li.current').first().html(text_3);
					height_current = height_current - 1;
                }               
				var text = $(this).children().first().text();
                var innerEmText = $(this).children('a').text(); 
                if (text != null && text != "") {
                    $(this).children().first().text(text);
                }
                else {
                    $(this).children('a').text(innerEmText);
                }
            });				
        }


		
    });
})(jQuery)
