/* http://www.bajoelsol.com/common/tools/load.php?js=common_nav,common_tabBox,common_archive */
function navLoad( id )
{
	if( typeof(id) == 'undefined' )
		id = 'fi_nav_ul';
		
	var nav = document.getElementById(id);
	
	var children = nav.getElementsByTagName("LI");
	for( var i = 0; i < children.length; i++ )
	{
		for( var j = 0; j < children[i].childNodes.length; j++ )
		{
			if( children[i].childNodes[j].nodeName == "UL" && children[i].childNodes[j].className.indexOf('sub') > -1 )
			{
				children[i].setAttribute('ulPos', j);
				
				if( children[i].parentNode == nav )
					children[i].childNodes[j].setAttribute('drop', 'down');
				else
					children[i].className += " hasSub";
				break;
			}
		}
		
		children[i].onmouseover = function() {
			
			if( this.className.indexOf(" over" ) == -1 )
				this.className += " over";
			
			if( this.getAttribute('ulPos') )
				showAndPosition(this);
		}
		
		children[i].onmouseout = function() {
			this.className = this.className == "over" ? "" :  this.className.replace(" over", "");
				
			if( this.getAttribute('ulPos') )
				this.childNodes[this.getAttribute('ulPos')].style.visibility = 'hidden';
		}
	}
}

function showAndPosition( li )
{
	var subMenu = li.childNodes[li.getAttribute('ulPos')];
	
	if( subMenu.getAttribute('noPos') )
	{
		subMenu.style.visibility = 'visible';
	}
	else
	{
		if( subMenu.getAttribute('drop') == "down" )
		{
			subMenu.style.left = '0px';
			subMenu.style.top = li.offsetHeight + 'px';
			if(subMenu.offsetWidth < li.offsetWidth )
				subMenu.style.width = li.offsetWidth + 'px';
		}
		else
		{
			subMenu.style.left = 'auto';
			subMenu.style.right = (-subMenu.offsetWidth) + 'px';
			subMenu.style.top = '3px';
		}
		
		subMenu.setAttribute('noPos', true);
	}
}function showTab( tab, tabContentID )
{
	// figure out the id of the tab box being worked with
	// and the number of the tab that was clicked on
	var tboxID = getTabBoxID(tab);
	var tabNum = getTabNum(tab);
	
	// get the tab box and read the values on it
	var tabBox = getEl(tboxID);
	var lastTabNum = tabBox.getAttribute('lastTab');
	var baseName = tabBox.getAttribute('baseName');
	var tabSelected = baseName + "Selected";
	
	// get the last tab and it's content container
	var lastTab = getEl(tboxID+"_"+lastTabNum+"_tab");
	var lastTabContent = getEl(tboxID+"_"+lastTabNum+"_content");
	
	// get the current tab and it's content container.
	var currTab = getEl(tboxID+"_"+tabNum+"_tab");
	var currTabContent = getEl(tboxID+"_"+tabNum+"_content");
	
	// unselect the last tab and hide it's content container
	lastTab.className = lastTab.className.replace(tabSelected, "");
	lastTabContent.style.display = 'none';
	
	// select the current tab and show it's content container
	currTab.className = currTab.className + " " + tabSelected;
	currTabContent.style.display = '';
	
	// set the last tab to the current tab
	tabBox.setAttribute('lastTab', tabNum);
}

function getTabBoxID(tab)
{
	var tabID = tab.id;
	var first = tabID.indexOf("_");
	var second = tabID.indexOf("_", (first+1));
	return tabID.substr(0, first);
}

function getTabNum(tab)
{
	var tabID = tab.id;
	var first = tabID.indexOf("_");
	var second = tabID.indexOf("_", (first+1));
	return tabID.substr((first+1), (second-first-1));
}

function highlightTab(tab, highlight)
{
	var tboxID = getTabBoxID(tab);
	var tabBox = getEl(tboxID);
	var baseName = tabBox.getAttribute('baseName');
	var style = baseName+"Highlighted";
	
	if (highlight == true)
		tab.className += " "+style;
	else
		tab.className = tab.className.replace(style, "");
}

function getEl( id )
{
	return document.getElementById(id);
}
function showToolTip( link, title, text, width, height )
{
	var pNode = link.parentNode;
	
	var tooltipDiv = createNewToolTip( title, text, width, height );
	
	var newTop = getOffsetTop(link).toString() + 'px';
	var newLeft = (getOffsetLeft(link) + link.offsetWidth + 5).toString() + 'px';
	
	var magicIFrame = document.createElement("iframe");
	magicIFrame.id = tooltipDiv.id + "_magicIframe";
	magicIFrame.style.position = "absolute";
	magicIFrame.style.width = (tooltipDiv.offsetWidth - 5).toString() + 'px';
	magicIFrame.style.height = (tooltipDiv.offsetHeight - 5).toString() + 'px';
	magicIFrame.style.left = newLeft;
	magicIFrame.style.top = newTop;
	
	tooltipDiv.style.left = newLeft;
	tooltipDiv.style.top = newTop;
	
	document.body.appendChild(magicIFrame);
	
	link.setAttribute('tooltipDivID', tooltipDiv.id);
	link.setAttribute('magicIframeID', magicIFrame.id);
}

function hideToolTip( link )
{
	if( !link.parentNode )
		return;
		
	var tooltipDiv = getEl(link.getAttribute('tooltipDivID'));
	var magicIframe = getEl(link.getAttribute('magicIframeID'));
	
	if( tooltipDiv && tooltipDiv.parentNode )
		tooltipDiv.parentNode.removeChild(tooltipDiv);
		
	if( magicIframe && magicIframe.parentNode )
		magicIframe.parentNode.removeChild(magicIframe);
	
}

function createNewToolTip( title, text, width, height )
{
	// create the title div
	var tooltipTitleDiv = document.createElement("div");
	tooltipTitleDiv.className = "tooltipTitle";
	
	// create the content div
	var tooltipContentDiv = document.createElement("div");
	tooltipContentDiv.className = "tooltipContent";
	
	// create the whole tooltip div.
	var tooltipDiv = document.createElement("div");
	tooltipDiv.id = "toolTipDiv";
	tooltipDiv.className = "tooltip";
	tooltipDiv.style.position = 'absolute';
	tooltipDiv.style.top = '-9000px';
	tooltipDiv.style.left = '-9000px';
	tooltipDiv.appendChild(tooltipTitleDiv);
	tooltipDiv.appendChild(tooltipContentDiv);
	document.body.appendChild(tooltipDiv);
	
	tooltipTitleDiv.innerHTML = title;
	
	//fix width
	alert(width);
	if (width > 200)
	{
		var ratio = 200 / width;
		width = 200;
		height = height * ratio;	
	}
	tooltipContentDiv.innerHTML = '<img src="'+text+'" width="'+width+'" height="'+height+'"/>';
	alert(tooltipContentDiv.innerHTML);
	return tooltipDiv;
}

function getOffsetTop( element )
{
	return getRealOffset( element, 'top' );
}

function getOffsetLeft( element )
{
	return getRealOffset( element, 'left' );
}

function getRealOffset( element, offset )
{
	if( !element )
		return 0;
		
	if( offset == "top" )
		var cOffset = element.offsetTop;
	else
		var cOffset = element.offsetLeft;
		
	var cNode = element.offsetParent;
	
	while( cNode )
	{
		if( offset == "top" )
			cOffset += cNode.offsetTop;
		else
			cOffset += cNode.offsetLeft;
			
		cNode = cNode.offsetParent;
	}
	
	return cOffset;
}