﻿sitemapToggle = function(){   
            var lists = $("#SiteMap li.haschildren"); // all lists in list item
			//loop through them - hide from start and add even listeners
			lists.each(function() 
			{
                var ul = $(this).find('ul')[0];
                var span = $(this).find('span')[0];
                //add event listener for click
			    $(span).click(function()
			    {
                    if ($(ul).is(':visible') ) 
                    {
                        $(ul).hide();
                        $(span).html("+");
                        $(span).removeClass('collapse');
                        $(span).addClass('expand');
                        
                     }
                    else 
                    {
                        $(ul).show();
                        $(span).html("-");
                        $(span).addClass('collapse');
                        $(span).removeClass('expand');
                    }
                });
            });
            
            $("#showdefault").click(function()
            {
                var ullists = $("#SiteMap ul"); // all lists in list item
                ullists.each(function() 
			    {
                    var rootElem = $(this).parent("div:first")[0];
                    var parentUL = $(this).parents("ul:first")[0];
                    var grandparent =  $(parentUL).parent("div:first")[0];
                    var sitemapLeft = $("#SiteMapLeft")[0];
                    var sitemapMiddle = $("#SiteMapMiddle")[0];
                    var sitemapRight = $("#SiteMapRight")[0];
                    if ( rootElem == sitemapLeft || grandparent == sitemapLeft || rootElem == sitemapMiddle || grandparent == sitemapMiddle || rootElem == sitemapRight || grandparent == sitemapRight) 
                    {
                        $(this).show();
                    } 
                    else 
                    {
                       $(this).hide(); // show first level lists, hide the rest
                        
                    }
                });
            
                var lists = $("#SiteMap li.haschildren"); // all lists in list item
			    //loop through them - hide from start and add even listeners
			    lists.each(function() 
			    {
                    var ul = $(this).find('ul')[0];
                    var span = $(this).find('span')[0];
			        if ($(ul).is(':visible') ) 
                    {
                        $(span).removeAttr("class").addClass('collapse');
                        $(span).html("-");
                    }
                    else 
                    {
                        $(span).removeAttr("class").addClass('expand');
                        $(span).html("+");
                    }
                });
            });
            
            $("#expandall").click(function()
            {
                 var ullists = $("#SiteMap ul"); // all lists in list item
                ullists.each(function() 
			    {
                    $(this).show();
                });
                var lists = $("#SiteMap li.haschildren"); // all lists in list item
			    //loop through them - hide from start and add even listeners
			    lists.each(function() 
			    {
                     var ul = $(this).find('ul')[0];
                    var span = $(this).find('span')[0];
			        if ($(ul).is(':visible') ) 
                    {
                        $(span).removeAttr("class").addClass('collapse');
                        $(span).html("-");
                    }
                    else 
                    {
                        $(span).removeAttr("class").addClass('expand');
                        $(span).html("+");
                    }
                });
            });
            
             $("#collapseall").click(function()
             {
                 var ullists = $("#SiteMap ul"); // all lists in list item
                ullists.each(function() 
			    {
                  var rootElem = $(this).parent("div:first")[0];
                  var sitemapLeft = $("#SiteMapLeft")[0];
                   var sitemapMiddle = $("#SiteMapMiddle")[0];
                  var sitemapRight = $("#SiteMapRight")[0];
                    
                  
                  if (rootElem == sitemapLeft || rootElem == sitemapMiddle || rootElem == sitemapRight ) 
                    {
                        $(this).show();
                    } 
                    else 
                    {
                       $(this).hide(); // show first level lists, hide the rest
                        
                    }  
                   
                });
                var lists = $("#SiteMap li.haschildren"); // all lists in list item
			    //loop through them - hide from start and add even listeners
			    lists.each(function() 
			    {
                    var ul = $(this).find('ul')[0];
                    var span = $(this).find('span')[0];
			        if ($(ul).is(':visible') ) 
                    {
                        $(span).removeAttr("class").addClass('collapse');
                        $(span).html("-");
                    }
                    else 
                    {
                        $(span).removeAttr("class").addClass('expand');
                        $(span).html("+");
                    }
                });
            });
            
            $("#showdefault").click();
    };

    $(document).ready(function(){
	    sitemapToggle();
    });
