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

$j(function(){

  var ul;
  var children;

	$j('ul#menu-mainmenu > li, ul#menu-mainmenu-en > li, ul#menu-mainmenu_in > li, ul#menu-meinmenu-en_in > 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");


      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','220px');
    }
	});

  function shiftLeft(i) {

    if (children[i]) {

      if (i == 0) {
        $j(ul).animate({
            height: "+=50px"
        }, 70 );
      }
      else {
        $j(ul).animate({
            height: "+=50px"
        }, 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);
    });
  }

});

