//	$Revision$

var homePageTabs = {};
var HomePageTabs = homePageTabs;

homePageTabs.init = function () {
	var con = document.getElementById('home-tasks'), dl = [];
	var nl = [
		document.getElementById('tab-content-0'),
		document.getElementById('tab-content-1'),
		document.getElementById('tab-content-2'),
		document.getElementById('tab-content-3'),
		document.getElementById('tab-content-4')
	];
	var ul = document.getElementById('home-task-nav');
	homePageTabs.tabs = ul.getElementsByTagName('li');
	for (var i = 0; i < homePageTabs.tabs.length; i++) {
		if (i == 0)
			homePageTabs.tabs.item(i).isFirst = true;
		else if (i == (homePageTabs.tabs.length - 1))
			homePageTabs.tabs.item(i).isLast = true;
	}
	for (var i = 0; i < nl.length; i++)
		if (nl[i].nodeName.toLowerCase() == 'div')
			dl[dl.length] = nl[i];
	for (var i = 1; i < dl.length; i++)
		dl[i].style.display = 'none';
	nl = Common.getElementsInClass(con, 'tab-content-submenu');
	for (var i = 0; i < nl.length; i++) homePageTabs.setMenuStyles(nl[i]);
};

homePageTabs.setMenuStyles = function () {
	if (arguments.length < 1) return;
	var el = arguments[0];
	el.style.backgroundColor = '#FFFFFF';
	el.style.border = '#CCC solid 1px';
	el.style.display = 'none';
	el.style.position = 'absolute';
	el.style.width = '208px';
	el.style.zIndex = '9';
}

homePageTabs.deactivateAll = function () {
	var el, con = document.getElementById('home-tasks'), nd;
	if (con == null) return;
	var nl = Misc.getElementsInClass(con, 'active');
	var len = nl.length;
	for (var i = 0; i < len; i++) {
		nd = nl[i];
 		Misc.deleteClassName(nd, 'active');
		if (nd.nodeName.toLowerCase() == 'div')
			nd.style.display = 'none';
	}
	len = homePageTabs.tabs.length;
	for (var i = 0; i < len; i++) {
		nd = homePageTabs.tabs[i];
		if (nd.isFirst)
			nd.className = 'first-tab';
		else if (nd.isLast)
			nd.className = 'last-tab';
		else
			nd.className = '';
	}
};

homePageTabs.focusContent = function (id) {
	var el = document.getElementById(id);
	var nl = Misc.getElementsInClass(el, 'access');
	var len = nl.length
	for (var i = 0; i < len; i++)
		var nd = nl[i];
		if (nd.nodeName.toLowerCase() == 'a') {
			nd.focus();
			return;
		}
};

homePageTabs.setActive = function (ref, id) {
	var nl, pn = ref.parentNode;
	homePageTabs.deactivateAll();
	while (pn.nodeName.toLowerCase() != 'li' &&
		pn.nodeName.toLowerCase() != 'body' &&
		pn.nodeName.toLowerCase() != 'html') pn = pn.parentNode;
	if (pn.isFirst)
		pn.className = 'active-first-tab';
	else if (pn.isLast)
		pn.className = 'active-last-tab';
	else
		pn.className = 'active';
	homePageTabs.setActivePrevious(pn);
	homePageTabs.setActiveNext(pn);
	document.getElementById(id).className += ' active';
	document.getElementById(id).style.display = 'block';
	homePageTabs.focusContent(id);
};

homePageTabs.setActiveNext = function (el) {
	var tab = homePageTabs.getNextTab(el);
	if (tab != null) {
		if (tab.isLast)
			tab.className = 'active-next-last-tab';
		else
			tab.className = 'active-next-tab';
	}
};

homePageTabs.setActivePrevious = function (el) {
	var tab = homePageTabs.getPreviousTab(el);
	if (tab != null) {
		if (tab.isFirst)
			tab.className = 'active-first-previous-tab';
		else
			tab.className = 'active-previous-tab';
	}
};

homePageTabs.delay = 400;

homePageTabs.delayedSetActive = function (ref, id) {
	ref._timerId = window.setTimeout(function () {
			homePageTabs.setActive(ref, id);
		}, homePageTabs.delay);
};

homePageTabs.cancelSetActive = function (ref) {
	if (ref._timerId) window.clearTimeout(ref._timerId);
	ref._timerId = null;
};

homePageTabs.delayedHideHPT = function (menuId) {
	if (!Misc.isDOM) return;
	var menu = document.getElementById(menuId);
	if (menu == null) return;
	menu._timerId = window.setTimeout(function () {
		homePageTabs.hideHPT(menuId);
	}, homePageTabs.delay);
};

homePageTabs.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;
};

homePageTabs.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;
};

homePageTabs.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;
};

homePageTabs.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;
};

homePageTabs.hideAllHPT = function () {
	if (homePageTabs.hptCache == null)
		homePageTabs.hptCache =
			Common.getElementsInClass(document.documentElement,
			'tab-content-submenu');
	for (var i = 0; i < homePageTabs.hptCache.length; i++)
		homePageTabs.delayedHideHPT(homePageTabs.hptCache[i].id);
};

homePageTabs.hideHPT = function (menuId) {
	if (!Misc.isDOM) return;
	var menu = document.getElementById(menuId);
	if (menu == null) return;
	menu.style.display = 'none';
	if (menu._timerId) menu._timerId = null;
};

homePageTabs.setPosition = function (menu) {
	if (!menu._triggerId) return;
	var trig = document.getElementById(menu._triggerId);
	var x = homePageTabs.getX(trig);
	var y = homePageTabs.getY(trig);
	menu.style.top = (y - menu.offsetHeight + 18) + 'px';
	menu.style.left = (x + trig.offsetWidth) + 'px';
};

homePageTabs.showHPT = function (ref, menuId) {
	if (!Misc.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 = Misc.generateId();
		menu._triggerId = ref.id;
	}
	menu.style.display = 'block';
	homePageTabs.setPosition(menu);
};

homePageTabs.hptCache = null;

homePageTabs.hideSubmenuMarker = function () {
	var sm = document.getElementById('interest-dd1');
	if (sm == null) return;
	var al = sm.getElementsByTagName('a');
		if (al.length > 0) return;
		var a = document.getElementById('interest-dd1-trigger');
		a.className = a.className.replace(/tab-content-submenu-trigger/, '');
};

homePageTabs.cancelDelayedHideHPT = function (menuId) {
	if (!Misc.isDOM) return;
	var menu = document.getElementById(menuId);
	if (menu && menu._timerId) window.clearTimeout(menu._timerId);
};
