/*	$Revision$ */
/*extern $, document, zibizCommon, window */
(function () {
	var zibizHomePageTabs = {
		init: function () {
			var con = document.getElementById('zibiz-home-tasks'), dl = [], i = 0;
			var nl = [
				document.getElementById('zibiz-tab-content-0'),
				document.getElementById('zibiz-tab-content-1'),
				document.getElementById('zibiz-tab-content-2'),
				document.getElementById('zibiz-tab-content-3')
				]; //document.getElementById('zibiz-tab-content-4')
			
			var ul = document.getElementById('zibiz-home-task-nav');
			zibizHomePageTabs.tabs = ul.getElementsByTagName('li');
			for (i = 0; i < zibizHomePageTabs.tabs.length; i++) {
				if (i === 0) {
					zibizHomePageTabs.tabs.item(i).isFirst = true;
				} else if (i === (zibizHomePageTabs.tabs.length - 1)) {
					zibizHomePageTabs.tabs.item(i).isLast = true;
				}
			}
			for (i = 0; i < nl.length; i++) 
			{
				if (nl[i].nodeName.toLowerCase() === 'div') {
					dl[dl.length] = nl[i];
				}
			}
			for (i = 1; i < dl.length; i++) {
				dl[i].style.display = 'none';
			}
			nl = jQuery('div.zibiz-tab-content-submenu', con).get();
			for (i = 0; i < nl.length; i++) {
				zibizHomePageTabs.setMenuStyles(nl[i]);
			}
		},
		setMenuStyles: function () {
			if (arguments.length < 1) {return;}
			var el = arguments[0];
			el.style.backgroundColor = '#f27321';
			el.style.border = '#CCC solid 1px';
			el.style.display = 'none';
			el.style.position = 'absolute';
			el.style.width = '208px';
			el.style.zIndex = '9';
		},
		deactivateAll: function () {
			var con = document.getElementById('zibiz-home-tasks'), i, nd;
			if (con === null) {return;}
			var nl = jQuery('div.zibiz-active', con).get();
			var len = nl.length;
			for (i = 0; i < len; i++) {
				nd = nl[i];
				zibizCommon.deleteClassName(nd, 'zibiz-active');
				if (nd.nodeName.toLowerCase() === 'div') {
					nd.style.display = 'none';
				}
			}
			len = zibizHomePageTabs.tabs.length;
			for (i = 0; i < len; i++) {
				nd = zibizHomePageTabs.tabs[i];
				if (nd.isFirst) {
					nd.className = 'zibiz-first-tab';
				} else if (nd.isLast) {
					nd.className = 'zibiz-last-tab';
				} else {
					nd.className = '';
				}
			}
		},
		focusContent: function (id) {
			var el = document.getElementById(id);
			var nl = jQuery('a.zibiz-access', el).get();
			var len = nl.length;
			for (var i = 0; i < len; i++) {
				var nd = nl[i];
				if (nd.nodeName.toLowerCase() === 'a') {
					nd.focus();
					return;
				}
			}
		},
		setActive: function (ref, id) {
			var el = null, nn = '', pn = ref.parentNode;
			zibizHomePageTabs.deactivateAll();
			nn = pn.nodeName.toLowerCase();
			while (nn !== 'li' && nn !== 'body' && nn !== 'html') {
				pn = pn.parentNode;
			}
			if (pn.isFirst) {
				pn.className = 'zibiz-active-first-tab';
			} else if (pn.isLast) {
				pn.className = 'zibiz-active-last-tab';
			} else {
				pn.className = 'zibiz-active';
			}
			zibizHomePageTabs.setActivePrevious(pn);
			zibizHomePageTabs.setActiveNext(pn);
			el = document.getElementById(id);
			el.className += ' zibiz-active';
			el.style.display = 'block';
			zibizHomePageTabs.focusContent(id);
		},
		setActiveNext: function (el) {
			var tab = zibizHomePageTabs.getNextTab(el);
			if (tab === null) {return;}
			if (tab.isLast) {
				tab.className = 'zibiz-active-next-last-tab';
			} else {
				tab.className = 'zibiz-active-next-tab';
			}
		},
		setActivePrevious: function (el) {
			var tab = zibizHomePageTabs.getPreviousTab(el);
			if (tab === null) {return;}
			if (tab.isFirst) {
				tab.className = 'zibiz-active-first-previous-tab';
			} else {
				tab.className = 'zibiz-active-previous-tab';
			}
		},
		delay: 400,
		delayedSetActive: function (ref, id) {
			ref._timerId = window.setTimeout(function () {
					zibizHomePageTabs.setActive(ref, id);
				}, zibizHomePageTabs.delay);
		},
		cancelSetActive: function (ref) {
			if (ref._timerId) {window.clearTimeout(ref._timerId);}
			ref._timerId = null;
		},
		delayedHideHPT: function (menuId) {
			if (!zibizCommon.isDOM) {return;}
			var menu = document.getElementById(menuId);
			if (menu === null) {return;}
			menu._timerId = window.setTimeout(function () {
				zibizHomePageTabs.hideHPT(menuId);
			}, zibizHomePageTabs.delay);
		},
		getNextTab: function (el) {
			if (typeof el.nextSibling === 'undefined') {return null;}
			var sib = el.nextSibling;
			while (sib !== null) {
				if (sib.nodeName.toLowerCase() === 'li') {return sib;}
				sib = sib.nextSibling;
			}
			return null;
		},
		getPreviousTab: function (el) {
			if (typeof el.previousSibling === 'undefined') {return null;}
			var sib = el.previousSibling;
			while (sib !== null) {
				if (sib.nodeName.toLowerCase() === 'li') {return sib;}
				sib = sib.previousSibling;
			}
			return null;
		},
		getX: function (el) {
			var x = 0;
			if (el.offsetParent) {
				while (el.offsetParent) {
					x += el.offsetLeft;
					el = el.offsetParent;
				}
			} else if (el.x) {
				x += el.x;
			}
			return x;
		},
		getY: function (el) {
			var y = 0;
			if (el.offsetParent) {
				while (el.offsetParent) {
					y += el.offsetTop;
					el = el.offsetParent;
				}
			} else if (el.y) {
				y += el.y;
			}
			return y;
		},
		hideAllHPT: function () {
			if (zibizHomePageTabs.hptCache === null) {
				zibizHomePageTabs.hptCache =
					jQuery('div.zibiz-tab-content-submenu',
						document.documentElement).get();
			}
			for (var i = 0; i < zibizHomePageTabs.hptCache.length; i++) {
				zibizHomePageTabs.delayedHideHPT(zibizHomePageTabs.hptCache[i].id);
			}
		},
		hideHPT: function (menuId) {
			if (!zibizCommon.isDOM) {return;}
			var menu = document.getElementById(menuId);
			if (menu === null) {return;}
			menu.style.display = 'none';
			if (menu._timerId) {menu._timerId = null;}
		},
		setPosition: function (menu) {
			if (!menu._triggerId) {return;}
			var trig = document.getElementById(menu._triggerId);
			var x = zibizHomePageTabs.getX(trig);
			var y = zibizHomePageTabs.getY(trig);
			menu.style.top = (y - menu.offsetHeight + 18) + 'px';
			menu.style.left = (x + trig.offsetWidth) + 'px';
		},
		showHPT: function (ref, menuId) {
			if (!zibizCommon.isDOM) {return;}
			var menu = document.getElementById(menuId);
			if (menu === null) {return;}
			var al = menu.getElementsByTagName('a');
			if (al.length < 1) {
				window.location = ref.getAttribute('href');
				return;
			}
			if (menu._timerId) {
				window.clearTimeout(menu._timerId);
				menu._timerId = null;
			}
			if (ref !== null) {
				if (!ref.id || ref.id === '' || ref.id === null) {
					ref.id = zibizCommon.generateId();
				}
				menu._triggerId = ref.id;
			}
			menu.style.display = 'block';
			zibizHomePageTabs.setPosition(menu);
		},
		hptCache: null,
		hideSubmenuMarker: function () {
			var sm = document.getElementById('zibiz-interest-dd1');
			if (sm === null) {return;}
			var al = sm.getElementsByTagName('a');
			if (al.length > 0) {return;}
			var a = document.getElementById('zibiz-interest-dd1-trigger');
			a.className = a.className.replace(/zibiz-tab-content-submenu-trigger/,
				'');
		},
		cancelDelayedHideHPT: function (menuId) {
			if (!zibizCommon.isDOM) {return;}
			var menu = document.getElementById(menuId);
			if (menu && menu._timerId) {window.clearTimeout(menu._timerId);}
		},
		showAccountsTab: function () {
			var aud, links, tab, trig;
			if (typeof window.SA_Message !== 'string') {return;}
			aud = window.SA_Message.replace(/audience=/, '');
			if (aud.indexOf('all') !== 0 && aud.indexOf('zibiz') !== 0) {
				tab = document.getElementById('zibiz-home-tab-my-zibiz');
				if (tab ===  null) {return;}
				links = tab.getElementsByTagName('a');
				if (links.length < 1) {return;}
				trig = links.item(0);
				zibizHomePageTabs.setActive(trig, 'zibiz-tab-content-3');
			}
		}
	};
	window.zibizHomePageTabs = zibizHomePageTabs;
	window.zibizHomePageTabs = zibizHomePageTabs;
})();
