
$(document).ready(function(){
    
   var navString2 = window.location.search.split("=");
    navString2.shift();
    var j = 0; 
    $('.collapsible').each(function() {
      j++;
      if(navString2[0] == j)
      {
        $(this).find('div').show();
        $(this).find('span').removeClass("hide");
        $(this).find('span').addClass('show');
      }
    });
  
    $('.collapsible').find('a:last').css("border-bottom","1px solid #889");
  
    $('.collapsible').find('.hide').each(function(){
        $(this).parent().find('.sublinks').hide();

    });
    
    
    
     $('.collapsible').mouseover(function(){
        $(this).css("cursor", "pointer");
        $(this).addClass("ie6hover");
    });
  
    $('.collapsible').find('span').mouseover(function(){
        $(this).css("cursor", "pointer");
        $(this).addClass("ie6hover");
    });

    $('.collapsible').find('span').mouseout(function(){
        $(this).css("cursor", "standard");
        $(this).removeClass('ie6hover');
    });
      
    $('.collapsible').find('a').click(function(){
        $(this).attr("href", ($(this).attr("href") + "?nav=" +  getNavString()));
    });  
      
    $('.uncollapsible').find('a').click(function(){
        $(this).attr("href", ($(this).attr("href") + "?nav=" +  getNavString()));
    });
    
    $('#topnav').find('a').click(function(){
        $(this).attr("href", ($(this).attr("href") + "?nav=" +  getNavString()));
    });

    $('.intern').click(function(){
        $(this).attr("href", ($(this).attr("href") + "?nav=" +  getNavString()));
    });
    
    
    $('.collapsible').find('span').each(function(){
                var $this = $(this);
                if( $this.is('.show') ) {
                        $this.next().show();
                }
                if ( $this.is('.hide') ) {
                        $this.next().hide();
                }
                return false;
        });
    
    $('.collapsible').find('span').click(function(){
            var $this = $(this);
            if( $this.is('.show') ) {
                  $this.next().slideUp("slow");
                  $this.removeClass('show');
                  $this.addClass('hide');
            }
            else {
                  $('.sublinks').each(function(){
                    $(this).slideUp("slow");
                    $(this).prev().addClass('hide');
                    $(this).prev().removeClass('show');
                    
                  });
                  $this.next().slideDown("slow");
                  $this.removeClass('hide');
                  $this.addClass('show');
            }
            return false;
        }); 
});


function getNavString(){
  var navString = "";
  var i = 0;
  $('.collapsible').find('span').each(function(){
      i++;
      if($(this).is(".show")){
        navString += i;
    }
  });
  return navString;

}


