//	$Id$

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')
	];
	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');
	if (con == null) return;
	var nl = Common.getElementsInClass(con, 'active');
	for (var i = 0; i < nl.length; i++) {
 		Common.deleteClassName(nl[i], 'active');
		if (nl[i].nodeName.toLowerCase() == 'div')
			nl[i].style.display = 'none';
	}
};

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

HomePageTabs.setActive = function (ref, id) {
	var nl, pn = ref.parentNode;
	while (pn.nodeName.toLowerCase() != 'li' &&
		pn.nodeName.toLowerCase() != 'body' &&
		pn.nodeName.toLowerCase() != 'html') pn = pn.parentNode;
	if (!Common.inClass(pn, 'active')) {
		HomePageTabs.deactivateAll();
		pn.className += ' active';
		document.getElementById(id).className += ' active';
		document.getElementById(id).style.display = 'block';
		HomePageTabs.focusContent(id);
	}
};

HomePageTabs.delay = 50;

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 (!Common.isDOM) return;
	var menu = document.getElementById(menuId);
	if (menu == null) return;
	menu._timerId = window.setTimeout(function () {
		HomePageTabs.hideHPT(menuId);
	}, HomePageTabs.delay);
};

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 (!Common.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 (!Common.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 = Common.generateId();
		menu._triggerId = ref.id;
	}
	menu.style.display = 'block';
	HomePageTabs.setPosition(menu);
	//if (al.length > 0) al.item(0).focus();
};

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 (!Common.isDOM) return;
	var menu = document.getElementById(menuId);
	if (menu && menu._timerId) window.clearTimeout(menu._timerId);
};
