/**
 * @author andrea jahn
 */
var $j = jQuery.noConflict();

$j(function(){

  var ul;
  var children;

	$j("ul#menu-left-menu > li, ul#menu-left-menu-english > li").hover(

  function(e){

		if($j(this).hasClass('current-menu-ancestor') || $j(this).hasClass('current-menu-item')) return;

    ul = $j(this).children("ul")[0];

		if (ul) {
      children = $j(ul).children("li");

/*
      if (children[0]) {
        // $j(this).css("background-image", "url(http://localhost/kiz-invasiv/wp-content/themes/kiz-invasiv/img/bg_mainMenua_ohneStrich.png)");
        $j(this).css("background-image", "url(http://www.kardiologie-im-zentrum.de/wp-content/themes/kiz4a/img/bg_mainMenua_ohneStrich.png)");
      }
*/

      stopAll();
      shiftLeft(0);
		}
    
	},
  function(e){

		if($j(this).hasClass('current-menu-ancestor') || $j(this).hasClass('current-menu-item')) return;

		ul = $j(this).children("ul")[0];

    if (ul) {

      children = $j(ul).children("li");

      stopAll();

      $j(ul).animate({
          height: "0px"
      }, 300 );

      $j(ul).children("li").css('paddingLeft','180px');
    }
	});

  function shiftLeft(i) {

    if (children[i]) {

      if (i == 0) {
        $j(ul).animate({
            height: "+=36px"
        }, 70 );
      }
      else {
        $j(ul).animate({
            height: "+=30px"
        }, 70 );
      }


      $j(children[i]).delay(100*i).animate({
          'paddingLeft' : '0'
      }, 350, shiftLeft(i+=1));
    }

  }

  function stopAll() {

    $j(ul).stop(true, false);

    $j(ul).children("li").each(function(index) {
      $j(this).stop(true, false);
    });
  }

});

