// JavaScript Document
$(document).ready(function() {
$("ul#nav ul").hide();
$('ul#nav li:has(ul)').each(function(i) {
$(this).childnode().slideUp(400);
});

//* Here
$("li.toggle").each(function(i) {
 $(this).attr("id", i);
});

$('ul#nav li:has(> a)').each(function(i) {
 var count = i;
 $(this).find("a").click(function() {
  var str = "&class=";
  var href = $(this).attr("href");
  $(this).parents("li.toggle").each(function(i) {
   str += ((i) ? " " : "") + ($(this).attr("class") + '_' + $(this).attr("id")).replace(/\s|toggle/g, "");
  });
  
  if (str == "&class=") 
  	str = "";
	
  $(this).attr("href", href + str);
 });
});

var _class = gClass.split(" "); 

for (var i = 0; _class[i]; ++i) {
 var idx = _class[i].split('_');
 $("li.toggle:eq(" + idx[1] + ")").childnode("ul:eq(0)").attr("style", "display:block"); //slideToggle(0);
}

//***

$('li.d1:has(ul)').click(function(event){
		if (this == event.target) {
		current = this;
		$('ul#nav li:has(ul)').each(function(i) {
		if (this != current) {$(this).childnode().slideUp(400);}
		});
		$(this).childnode("ul:eq(0)").slideToggle(400);


		}
	});

$('li.d2:has(ul)').click(function(event){
		if (this == event.target) {
		current = this;
		$('li.d2:has(ul)').each(function(i) {
		if (this != current) {$(this).childnode().slideUp(400);}
		});
		$('li.d3:has(ul)').each(function(i) {
		if (this != current) {$(this).childnode().slideUp(400);}
		});
		$(this).childnode("ul:eq(0)").slideToggle(400); 


		}
	});

$('li.d3:has(ul)').click(function(event){
		if (this == event.target) {
		current = this;
		$('li.d3:has(ul)').each(function(i) {
		if (this != current) {$(this).childnode().slideUp(400);}
		});
		$(this).childnode("ul:eq(0)").slideToggle(400); 

		}
	});

});
