( function() {
	var A = {
		maxTabs : 3,
		init : function() {
			var C = document.getElementById("all"), D = [], G = 0, B = [], F, E = document
					.getElementById("sideleft");
			for (G = 0; G < A.maxTabs; G++) {
				F = document.getElementById("mw-tab-content-" + G);
				if (F !== null) {
					B[B.length] = F
				}
			}
			A.tabs = E.getElementsByTagName("li");
			for (G = 0; G < A.tabs.length; G++) {
				if (G === 0) {
					A.tabs.item(G).isFirst = true
				} else {
					if (G === (A.tabs.length - 1)) {
						A.tabs.item(G).isLast = true
					}
				}
			}
			for (G = 0; G < B.length; G++) {
				if (B[G].nodeName.toLowerCase() === "div") {
					D[D.length] = B[G]
				}
			}
			for (G = 1; G < D.length; G++) {
				D[G].style.display = "none"
			}
			B = jQuery("div.mw-tab-content-submenu", C).get();
			for (G = 0; G < B.length; G++) {
				A.setMenuStyles(B[G])
			}
			A.restoreActiveTabFromCookie()
		},
		setMenuStyles : function() {
			if (arguments.length < 1) {
				return
			}
			var B = arguments[0];
			B.style.backgroundColor = "#FFFFFF";
			B.style.border = "#CCC solid 1px";
			B.style.display = "none";
			B.style.position = "absolute";
			B.style.width = "208px";
			B.style.zIndex = "9"
		},
		deactivateAll : function() {
			var D = document.getElementById("all"), E, F;
			if (D === null) {
				return 

			}
			var C = jQuery("div.mw-active", D).get();
			var B = C.length;
			for (E = 0; E < B; E++) {
				F = C[E];
				mwCommon.deleteClassName(F, "mw-active");
				if (F.nodeName.toLowerCase() === "div") {
					F.style.display = "none"
				}
			}
			B = A.tabs.length;
			for (E = 0; E < B; E++) {
				F = A.tabs[E];
				if (F.isFirst) {
					F.className = "mw-first-tab"
				} else {
					if (F.isLast) {
						F.className = "mw-last-tab"
					} else {
						F.className = ""
					}
				}
			}
		},
		
		focusContent:function(G){
		var E=document.getElementById(G);
		var C=jQuery("a.mw-access",E).get();
		var B=C.length;
		  for(var D=0;D<B;D++){
			var F=C[D];
			if(F.nodeName.toLowerCase()==="a"){
				F.focus();
				return
			}
		  }
		},
		
		setActive : function(D, F) {
			var C = null, E = "", B = D.parentNode;
			A.deactivateAll();
			E = B.nodeName.toLowerCase();
			while (E !== "li" && E !== "body" && E !== "html") {
				B = B.parentNode
			}
			if (B.isFirst) {
				B.className = "mw-active-first-tab"
			} else {
				if (B.isLast) {
					B.className = "mw-active-last-tab"
				} else {
					B.className = "mw-active"
				}
			}
			A.setActivePrevious(B);
			A.setActiveNext(B);
			C = document.getElementById(F);
			C.className += " mw-active";
			C.style.display = "block";
			A.focusContent(F);
			if (B.id) {
				A.setLastTabCookie(B.id)
			}
		},
		setActiveNext : function(C) {
			var B = A.getNextTab(C);
			if (B === null) {
				return
			}
			if (B.isLast) {
				B.className = "mw-active-next-last-tab"
			} else {
				B.className = "mw-active-next-tab"
			}
		},
		setActivePrevious : function(C) {
			var B = A.getPreviousTab(C);
			if (B === null) {
				return
			}
			if (B.isFirst) {
				B.className = "mw-active-first-previous-tab"
			} else {
				B.className = "mw-active-previous-tab"
			}
		},
		delay : 400,
		delayedSetActive : function(B, C) {
			B._timerId = window.setTimeout( function() {
				A.setActive(B, C)
			}, A.delay)
		},
		cancelSetActive : function(B) {
			if (B._timerId) {
				window.clearTimeout(B._timerId)
			}
			B._timerId = null
		},
		delayedHideHPT : function(C) {
			if (!mwCommon.isDOM) {
				return 

			}
			var B = document.getElementById(C);
			if (B === null) {
				return
			}
			B._timerId = window.setTimeout( function() {
				A.hideHPT(C)
			}, A.delay)
		},
		getNextTab : function(C) {
			if (typeof C.nextSibling === "undefined") {
				return null
			}
			var B = C.nextSibling;
			while (B !== null) {
				if (B.nodeName.toLowerCase() === "li") {
					return B
				}
				B = B.nextSibling
			}
			return null
		},
		getPreviousTab : function(C) {
			if (typeof C.previousSibling === "undefined") {
				return null
			}
			var B = C.previousSibling;
			while (B !== null) {
				if (B.nodeName.toLowerCase() === "li") {
					return B
				}
				B = B.previousSibling
			}
			return null
		},
		getX : function(C) {
			var B = 0;
			if (C.offsetParent) {
				while (C.offsetParent) {
					B += C.offsetLeft;
					C = C.offsetParent
				}
			} else {
				if (C.x) {
					B += C.x
				}
			}
			return B
		},
		getY : function(B) {
			var C = 0;
			if (B.offsetParent) {
				while (B.offsetParent) {
					C += B.offsetTop;
					B = B.offsetParent
				}
			} else {
				if (B.y) {
					C += B.y
				}
			}
			return C
		},
		hideAllHPT : function() {
			if (A.hptCache === null) {
				A.hptCache = jQuery("div.mw-tab-content-submenu",
						document.documentElement).get()
			}
			for ( var B = 0; B < A.hptCache.length; B++) {
				A.delayedHideHPT(A.hptCache[B].id)
			}
		},
		hideHPT : function(C) {
			if (!mwCommon.isDOM) {
				return 

			}
			var B = document.getElementById(C);
			if (B === null) {
				return
			}
			B.style.display = "none";
			if (B._timerId) {
				B._timerId = null
			}
		},
		
	
		hptCache : null,
		hideSubmenuMarker : function() {
			var D = document.getElementById("mw-interest-dd1");
			if (D === null) {
				return
			}
			var C = D.getElementsByTagName("a");
			if (C.length > 0) {
				return
			}
			var B = document.getElementById("mw-interest-dd1-trigger");
			B.className = B.className.replace(
					/mw-tab-content-submenu-trigger/, "")
		},
		cancelDelayedHideHPT : function(C) {
			if (!mwCommon.isDOM) {
				return
			}
			var B = document.getElementById(C);
			if (B && B._timerId) {
				window.clearTimeout(B._timerId)
			}
		},
		showAccountsTab : function() {
			var C, B;
			if (typeof window.SA_Message !== "string") {
				return
			}
			C = window.SA_Message.replace(/audience=/, "");
			if (C.indexOf("all") !== 0 && C.indexOf("mw") !== 0) {
				B = jQuery("li#mw-home-tab-my-mw > a:first");
				if (B.length < 1) {
					return
				}
				if (!A.restoreActiveTabFromCookie()) {
					A.setActive(B.get(0), B.attr("href").replace(/#/, ""))
				}
			}
		},
		getLastTabCookie : function() {
			var E = -1, B = "", D = document.cookie, C = 0, F = "hplasttab=";
			E = D.indexOf(F);
			if (E < 0) {
				return null
			}
			C = E + F.length;
			B = D.substring(C).replace(/;.*$/, "");
			return decodeURIComponent(B)
		},
		restoreActiveTabFromCookie : function() {
			var C, B, D = A.getLastTabCookie();
			if (D !== null) {
				B = document.getElementById(D);
				if (B !== null) {
					C = B.getElementsByTagName("a");
					if (C.length > 0) {
						C = C.item(0);
						D = C.getAttribute("href").replace(/^[^#]*#+/, "");
						A.setActive(C, D);
						return true
					}
				}
			}
			return false
		},
		setLastTabCookie : function(C) {
			try {
				if (document.cookie.split(";").length < 17
						|| document.cookie.indexOf("hplasttab=") != -1) {
					document.cookie = "hplasttab=" + encodeURIComponent(C)
				}
			} catch (B) {
			}
		}
	};
	window.mwHomePageTabs = A;
	window.mwHomePageTabs = A
})();

