$(document).ready(function() {

  //$("#menu-tree ul").hide();
  /*$("#menu-tree li:has(ul)").each(function() {
    $(this + " div").children().slideUp(400);
  });*/

  $("#menu-tree li.p1:has(ul)").click(function(event){
    if(this == event.target || this == $(event.target).parent().get(0) || this == $(event.target).parent().parent().get(0))
    {
      var current = this;
      /*$("#menu-tree li:has(ul)").each(function() {
        if(this != current)
		{
		  $(this).children().children("ul").slideUp(400);
      $(this).children("ul").slideUp(400);
		  $(this).removeClass("open");
      $(this).addClass("close");
        }
      });*/
      $("ul:first", $(this)).slideToggle(400);
      $(this).toggleClass("open");
      $(this).toggleClass("close");
    }
  });
  
  //$("#menu-tree-services ul").hide();
  /*$("#menu-tree-services li").each(function() {
    $(this ).children("div").slideUp(400);
  });*/
  
  $("#menu-tree-services li.p1").click(function(event){
    if(this == event.target || this == $(event.target).parent().get(0) || this == $(event.target).parent().parent().get(0))
    {
      var current = this;
      /*$("#menu-tree-services li").each(function() {
        if(this != current)
		{
      $(this).children("div").slideUp(400);
		  $(this).removeClass("open");
      $(this).addClass("close");
        }
      });*/
      $("div:first", $(this)).slideToggle(400);
      $(this).toggleClass("open");
      $(this).toggleClass("close");
    }
  });
  
  //$("#menu-tree-decisions ul").hide();
  /*$("#menu-tree-decisions li").each(function() {
    $(this ).children("div").slideUp(400);
  });*/
  
  $("#menu-tree-decisions li.p1").click(function(event){
    if(this == event.target || this == $(event.target).parent().get(0) || this == $(event.target).parent().parent().get(0))
    {
      var current = this;
      /*$("#menu-tree-decisions li").each(function() {
        if(this != current)
		{
      $(this).children("div").slideUp(400);
		  $(this).removeClass("open");
      $(this).addClass("close");
        }
      });*/
      $("div:first", $(this)).slideToggle(400);
      $(this).toggleClass("open");
      $(this).toggleClass("close");
    }
  });
  
  //$("#menu-tree-experiences ul").hide();
  /*$("#menu-tree-experiences li").each(function() {
    $(this ).children("div").slideUp(400);
  });*/
  
  $("#menu-tree-experiences li.p1").click(function(event){
    if(this == event.target || this == $(event.target).parent().get(0) || this == $(event.target).parent().parent().get(0))
    {
      var current = this;
      /*$("#menu-tree-experiences li").each(function() {
        if(this != current)
		{
      $(this).children("div").slideUp(400);
		  $(this).removeClass("open");
      $(this).addClass("close");
        }
      });*/
      $("div:first", $(this)).slideToggle(400);
      $(this).toggleClass("open");
      $(this).toggleClass("close");
    }
  });

  $("#menu-tree li.p2:has(ul)").click(function(event){
    if(this == event.target)
    {
      var current = this;
      /*$("#menu-tree li.p2:has(ul)").each(function() {
        if(this != current)
		{
		  $(this).children("ul").slideUp(400);
		  $(this).removeClass("sub-open");
          $(this).addClass("sub-close");
		}
      });*/
      $("ul:first", $(this)).slideToggle(400);
	  $(this).toggleClass("sub-open");
      $(this).toggleClass("sub-close");

      //alert($(this).text());
    }
  });
  // переключение табов "Услуги/Решение/Опыт"
  $("#tab-services").click(function(event) {
    $("#tab-solutions, #tab-experience").removeClass('on').addClass('off');
    $("#tab-services").removeClass('off').addClass('on');
    $("#content-solutions, #content-experience").hide();
    $("#content-services").show();
  });
  $("#tab-solutions").click(function(event) {
    $("#tab-services, #tab-experience").removeClass('on').addClass('off');
    $("#tab-solutions").removeClass('off').addClass('on');
    $("#content-services, #content-experience").hide();
    $("#content-solutions").show();
  });
  $("#tab-experience").click(function(event) {
    $("#tab-services, #tab-solutions").removeClass('on').addClass('off');
    $("#tab-experience").removeClass('off').addClass('on');
    $("#content-services, #content-solutions").hide();
    $("#content-experience").show();
  });
  //дерево отраслей в таблице
  $(".branch-name").click(function(event) {
      var id = $(this).attr("value");
      $(".branch-hide[value="+id+"]").slideToggle(400);
      $(".branch-name[value="+id+"][id=tree]").toggleClass("branch-open");
      $(".branch-name[value="+id+"][id=tree]").toggleClass("branch-close");//.css("border","1px solid red");
//      $(".branches[value="+id+"][id=tree]").text($(".branches[value="+id+"][id=tree]").css("padding-bottom"));
  });
});