$(document).ready(function() {
						   
  $(".tab_container").hide();
  $(".tab_subcontainer").hide();
  $(".left").height($(document).height()-100);
  $("#content_home").height($(document).height()-100);
	
  $("ul.subnavi li span").resize(function() {
											
	$("ul.subnavi li").each(function() {
	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });

  	  if($(this).hasClass('.active')) {
    	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
  	  } else {
    	$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
  	  }
		
	  if($(this).hasClass('.active2')) {
  	    $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
	  } else {
  	    $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  }

  	  $(this).hover(
    	function () {
      	  $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
    	}, 
        function () {
          if($(this).hasClass('.active') || $(this).hasClass('.active2')) {
	    	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
      	  } else {
        	$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  	  }
    	}
  	  );
	});

	$("ul#naviLeft li").each(function() {

  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
  	    
	  if($(this).hasClass('.active')) {
    	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
  	  } else {
    	$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
  	  }

  	  $(this).hover(
    	function () {
      	  $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
    	}, 
        function () {
          if($(this).hasClass('.active')) {
	    	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
      	  } else {
        	$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  	  }
    	}
  	  );
	});
	  
	$("ul.subnaviLink li").each(function() {
  	  $(this).hover(
    	function () {
      	  $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
    	}, 
    	function () {
      	  $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
    	}
  	  );
	});
  
    $("ul.level li").each(function() {
	  $(this).hover(
  		function () {
    	  $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
  		}, 
  		function () {
    	  if($(this).hasClass('.active')) {
	  		$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
    	  } else {
      		$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
		  }
  		}
	  );
	});
  });

  $("ul.subnavi li").each(function() {
	$(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });

	if($(this).hasClass('.active')) {
  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
	} else {
  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
	}
	
	if($(this).hasClass('.active2')) {
  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
	} else {
  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
	}

	$(this).hover(
  	  function () {
    	$(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
  	  }, 
  	  function () {
      	$(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
  	  }
	);
  });

  $("ul#naviLeft li").each(function() {

    $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
	
    if($(this).hasClass('.active')) {
      $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
  	} else {
      $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
  	}

    $(this).hover(
      function () {
      	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
      }, 
      function () {
        if($(this).hasClass('.active')) {
	      $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
      	} else {
          $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  	}
      }
  	);
  });
  
  $("ul.subnaviLink li").each(function() {
  	$(this).hover(
      function () {
      	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
      }, 
      function () {
        $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
      }
  	);
  });
  
  $("ul.level li").each(function() {
	$(this).hover(
  	  function () {
    	$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
  	  }, 
  	  function () {
    	if($(this).hasClass('.active')) {
	  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
    	} else {
      	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
		}
  	  }
	);
  });

  $('#container').click(function(){ 
	$(".tab_container").hide();
	$(".tab_subcontainer").hide();
	
	$("ul.subnavi li").each(function() {
	  if($(this).hasClass('.active')) {
	   $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  }
	});
	
	$("ul.subnavi li").removeClass("active");
	
	$("ul.level li").each(function() {
	  if($(this).hasClass('.active')) {
		$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  }
	});
	$("ul.level li").removeClass("active");
  });

  $("ul.subnavi li").click(function() {
	
	if($(this).hasClass('.active')) {
	  $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
	} else {
      $("ul.subnavi li").each(function() {
	    if($(this).hasClass('.active')) {
		  $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	    }
	  });
	}
	$("ul.subnavi li").removeClass("active");

	$("ul.level li").removeClass("active");
	
	$(this).addClass("active");
	$(".tab_container").hide();
	$(".tab_subcontainer").hide();

	var activeNavi = $(this).find("a").attr("href"); 
	$(activeNavi).show(); 
	$(activeNavi).height($(document).height()-100);
	
	$("ul.level li").each(function() {
	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });

	  if($(this).hasClass('.active')) {
  		$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
	  } else {
  		$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  }
	});
	
	$("ul.subnaviLink li").each(function() {
  	  $(this).find('a').css({ height: $(this).find('span').height()+ 1 +'px' });
	  
  	  if($(this).hasClass('.active')) {
  		$(this).css({ height: $(this).find('span').height()+ 1 +'px' });
	  } else {
  		$(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	  }
	});
		
    return false;
  });
	
  $("ul.level li").click(function() {
								  
	if($(this).hasClass('.active')) {
	  $(this).css({ height: $(this).find('span').height()+ 1 +'px' });
	} else {
      $("ul.level li").each(function() {
	    if($(this).hasClass('.active')) {
		  $(this).css({ height: $(this).find('span').height()+ 8 +'px' });
	    }
	  });
	}
	
	$("ul.level li").removeClass("active");
	$(this).addClass("active");
	
	$(".tab_subcontainer").hide();

	var activeNavi = $(this).find("a").attr("href"); 
	$(activeNavi).show(); 
	$(activeNavi).height($(document).height()-100);

	return false;
  });

});
