BA_ROLLOVER_AS_SETTINGS['gn-rollover'] = null;

BAAddOnload(function(){
	function changeStatus(node, status) {
		if (!node || !node.src) return;
		node.src = node.src.replace(/(_[a-z]+)?(\.[a-z]+)$/, function(){ return (status || "") + arguments[2] });
	}

	$("#global-nav>li")
		.find("em>img")
			.each(function(index, node){
				changeStatus(node, "_s");
			}).end()
		.find("a>img")
			.mouseover(function(e){
				changeStatus(this, "_o");
			})
			.mouseout(function(e){
				changeStatus(this, "");
			}).end()
		.find("ul")
			.mouseover(function(e){
				var target = e.relatedTarget;
				while (target) {
					if (target === this) {
						return true;
					}
					target = target.parentNode;
				}
				changeStatus($(this).parents("li:first").find("a:first>img")[0], "_a");
			})
			.mouseout(function(e){
				var target = e.relatedTarget;
				while (target) {
					if (target === this) {
						return true;
					}
					target = target.parentNode;
				}
				changeStatus($(this).parents("li:first").find("a:first>img")[0], "");
			}).end()
		.each(function(index, node){
			var ul = $(node).find("ul");
			if (!ul.length) return true;

			var defaultHeight = ul.height();
			ul.css("opacity", "0").css("overflow", "hidden").height(0).hide();
			$(node)
				.bind("mouseover", function(e){
					var target = e.relatedTarget;
					while (target) {
						if (target === this) {
							return true;
						}
						target = target.parentNode;
					}
					var ul = $(node).find("ul").css("visibility", "visible");
					ul.stop().animate({
						height: defaultHeight + "px",
						opacity: 1
					}, 200);
				})
				.bind("mouseout", function(e){
					var target = e.relatedTarget;
					while (target) {
						if (target === this) {
							return true;
						}
						target = target.parentNode;
					}
					var ul = $(node).find("ul");
					ul.stop().animate({
						height: "0px",
						opacity: 0
					}, 200, function(){
						ul.css("visibility", "hidden");
					});
				});
		});
});

