$(document).ready(
	function () {
		if ($(".menu-item:first").length > 0) {
			$("#menu_border").css("top", $(".menu-item:first").position().top + 18).css("width", "0px");
			disable_menu_border = false;
			setTimeout(
				function () {
					p = $(".current-menu-item:first");
					if (p.length == 0) {
						p = $(".menu-item:first");
					}
				
					$("#menu_border").animate(
						{
							left: p.position().left,
							width: p.width(),
							backgroundColor: '#ca3130'
						},
						1000
					);
				},
				500
			);
		}
		
		$(".menu-item").each(
			function () {
				$(this).bind(
					"mouseover",
					function () {
						if (!disable_menu_border) {
							$("#menu_border").stop().animate(
								{
									left: $(this).position().left + 5,
									width: $(this).width() - 10,
									backgroundColor: '#ca3130'
								},
								700
							);
						}
					}
				).bind(
					"mouseout",
					function () {
						if (!disable_menu_border) {
							p = $(".current-menu-item:first");
							if (p.length == 0) {
								p = $(".menu-item:first");
							}
			
							$("#menu_border").stop().animate(
								{
									left: p.position().left,
									width: p.width(),
									backgroundColor: '#ca3130'
								},
								700
							);
						}
					}
				).bind(
					"click",
					function () {
						if (!disable_menu_border) {
							disable_menu_border = true;
							p = $(".current-menu-item:first");
							p.removeClass("current-menu-item");
							$(this).addClass("current-menu-item");
							
							$("#menu_border").stop().animate(
								{
									left: "0px",
									width: "0px",
									backgroundColor: '#121212'
								},
								1000
							);
						}
					}
				);
			}
		);
	}
);
