jQuery.fn.extend({flagNav:function(o){var $nav=$(this);var cfg={bgposout:$("a",$nav).css("background-position"),rollback:false,flagouttime:500,flagoutanim:"swing",flagdowntime:400,flagdownanim:"easeOutBounce",flagupanim:"easeInBounce",lineheight:$("li ul",$nav).css("line-height"),width:$("li",$nav).width()};cfg=$.extend(cfg,o?o:{});cfg.bgouttime=cfg.bgouttime?cfg.bgouttime:cfg.flagouttime;cfg.bgintime=cfg.bgintime?cfg.bgintime:cfg.bgouttime;cfg.flagintime=cfg.flagintime?cfg.flagintime:cfg.flagouttime;cfg.flaginanim=cfg.flaginanim?cfg.flaginanim:cfg.flagoutanim;cfg.flaguptime=cfg.flaguptime?cfg.flaguptime:cfg.flagdowntime;cfg.bgposover=cfg.bgposover?cfg.bgposover:cfg.bgposout;var parts=cfg.lineheight.match(/^([\d+-.]+)(.*)$/);cfg.heightnum=parts[1];cfg.unit=parts[2];$("ul",$nav).each(function(){$(this).data("num",$(this).children("li").length);});$("ul",$nav).css({overflow:"hidden",left:"0px",height:cfg.lineheight});var zi=0;$nav.css("z-index",zi);for(var i=$nav.children("li").children("ul");i.length;i=i.children("li").children("ul")){zi--;i.css("z-index",zi);}
$("li:has(ul)",$nav).hover(function(){var $subul=$(this).children("ul");$subul.stop().css({visibility:"visible",overflow:"hidden",height:cfg.lineheight}).animate({left:cfg.width},cfg.flagouttime,cfg.flagoutanim).animate({height:cfg.heightnum*$subul.data("num")+cfg.unit},cfg.flagdowntime,cfg.flagdownanim,function(){$subul.css({overflow:"visible"});$("ul",$subul).css({overflow:"hidden",left:"0px"});});},function(){var $subul=$(this).children("ul");if(!cfg.rollback){$subul.stop().css({visibility:"hidden",height:cfg.lineheight,left:"0px",overflow:"hidden"});}else{$subul.stop(true,false).css({overflow:"hidden"}).animate({height:cfg.lineheight},cfg.flaguptime,cfg.flagupanim).animate({left:"0px"},cfg.flagintime,cfg.flaginanim);}});$("a",$nav).css({backgroundPosition:cfg.bgposout}).hover(function(){$(this).stop().animate({backgroundPosition:cfg.bgposover},{duration:cfg.bgouttime});},function(){$(this).stop().animate({backgroundPosition:cfg.bgposout},{duration:cfg.bgintime});});return $nav;}});