jQuery(function($){
	$.fn.LblockTopMenu = function(options) {
		var opts = $.extend(options);
		var LblockTopMenu = $(this);
		var LblockTopMenuList = LblockTopMenu.find('>ul>li');
		var submenu = LblockTopMenu.find('.submenu');
		var submenuList = submenu.find('>ul>li');

		function showMenu() {
			t = $(this).parent('li');
			if (!t.hasClass('active')) {
				LblockTopMenuList.removeClass('active');
				t.addClass('active');
				submenu.hide();
				t.find('.submenu').show().css('top', 0).animate( { top: 30, opacity:1 }, 200 );
			}
		}

		function hideMenu() {
			LblockTopMenuList.removeClass('active');
			submenu.hide();
			activeMenu();
		}

		function activeMenu() {
			if(opts.d1) {
				t = LblockTopMenuList.eq(opts.d1-1); 
				t.addClass('active');
				t.find('.submenu').show().css('top', 0).animate( { top: 30, opacity:1 }, 200 );
				if(opts.d2) {
					t.find('.submenu>ul>li').eq(opts.d2-1).addClass('on');
				}
			}
		}

		return this.each(function() {
			activeMenu();
			LblockTopMenuList.find('>a').mouseover(showMenu).focus(showMenu);
			LblockTopMenu.mouseleave(hideMenu);
		});
	}
});
