var bDebug = false;
var bListerLoaded = false;
var bResize = false;
var sWaitImage = '/imagelib/acsi.eu/nav/ajax-indicator2.gif';
var oOpenDiv;

function init(bMenuHandlers, bFoldOutOnInit)
{
	bFoldOutOnInit = (!bFoldOutOnInit) ? false : bFoldOutOnInit;

	if (bMenuHandlers)
	{
		addOnclickHandlers();
		if (bFoldOutOnInit)	showCurrentSubMenu();
	}
	
	if (bResize)
	{
		initPage();
	}

	// Google Analytics code
	//var _uacct = sGoogleAnalyticsID;
	//urchinTracker();
}

// Check if content height is smaller then iScreenHeight
// If so, adjust the content height to the screen height
function initPage(PageExeptionIdentifier)
{
	clearInterval(TimeOutID);
	var iFooterHeight   = xHeight("Footer");
	var iHeaderHeight   = xHeight("Header");
	var iScreenHeight   = xClientHeight();
	var iLeftDivHeight  = xHeight("MenuLeft");
	var iRightDivHeight  = xHeight("MenuRight");

	var iMarginBottom   = 10; // ruimte aan de onderkant.
	var iMarginTop      = 5;


	if ( !bListerLoaded ) //Only on first excecution if this function
	{
		resizeArticles();
	}

	if (PageExeptionIdentifier)
	{
		// Give page exceptions
		switch(PageExeptionIdentifier)
		{
			case 'sitemap':
			var iContentDivHeight = 800;
			break;
			default:
			var iContentDivHeight = xHeight("Content");
		}
	}
	else
	{
		// default
		var iContentDivHeight = xHeight("Content");

	}

	// Add Top menu height + content height
	var iContentHeight  = iContentDivHeight + iHeaderHeight + iMarginBottom + iFooterHeight;
	var iLeftDivHeight  = iLeftDivHeight + iHeaderHeight + iMarginBottom + iFooterHeight + 20;
	var iRightDivHeight = iRightDivHeight + iHeaderHeight + iMarginBottom + iFooterHeight + 20;

	// Find the maximum height
	var iUseHeight = Math.max(iContentHeight, iScreenHeight, iLeftDivHeight, iRightDivHeight);

	// substract topmenu
	iUseHeight = iUseHeight - iHeaderHeight - iFooterHeight;

	// Reset all div heights
	xHeight("LeftBorder" , iUseHeight);
	xHeight("RightBorder", iUseHeight);

	//Reposition Tents
	//if (typeof(aTentjes) != 'undefined' && aTentjes.length > 0)
	//	repositionTents("MapLeft");

	if (!bListerLoaded)
	{
		xAddEventListener(window, "resize", ResizeListener, false);
		bListerLoaded = true;
	}
}

var TimeOutID;
function ResizeListener()
{
	if (TimeOutID)
	{
		clearInterval(TimeOutID);
	}

	TimeOutID = setInterval("initPage()", 1000);
}


/*
 * Adjust layout height conform content or screen height
 */
function fnAdjustLayout()
{
	oWrapper    = $('Container');
	aWrapperDim = oWrapper.getCoordinates();
	aWindowDim  = window.getCoordinates();

	iUseHeight  = Math.max(aWrapperDim.height, aWindowDim.height);
	iNewHeight = iUseHeight - $('Header').getCoordinates().height -  $('Footer').getCoordinates().height;

	$('Content').setStyle('height', iNewHeight);

}

/*function resizeArticles()
{
	var iMaxHeight = 0;
	var oRoot = document.getElementById('Content');
	var aElements = getElementsByClass(oRoot, 'div', 'ArticleHalf');

	// Determine maximum article height
	for (var i = 0; i < aElements.length; i++)
	{
		aChildren = aElements[i].childNodes;
		if (aChildren)
		{
			for (var j = 0; j < aChildren.length; j++)
			{
				if (aChildren[j].className == 'ArticleBody')
				{
					iHeight = xHeight(aChildren[j]);
					if (iHeight > iMaxHeight)
						iMaxHeight = iHeight;
				}
			}
		}
	}

	iCorrection = 0;//20;
	iNewHeight = (iMaxHeight - iCorrection);

	for (var i = 0; i < aElements.length; i++)
	{
		aChildren = aElements[i].childNodes;
		if (aChildren)
		{
			for (var j = 0; j < aChildren.length; j++)
			{
				if (aChildren[j].className == 'ArticleBody')
				{
					xHeight(aChildren[j], iNewHeight);
				}
			}
		}
	}
}*/

function resizeArticles()
{
	var i = 1;
	var iRowNumber = 0;
	var iMaxHeight = 0;
	var aMaxHeight = {};

	$$('div.ArticleHalf').each(function(oArticle) {
		oArticleBody = oArticle.getElement('div.ArticleBody');
		iArticleHeight = oArticleBody.getSize().y;
		if (i % 2 == 1)
		{
			iRowNumber++;
			aMaxHeight[iRowNumber] = 0;
		}
		if (iArticleHeight > aMaxHeight[iRowNumber])
			aMaxHeight[iRowNumber] = iArticleHeight;
		i++;
	});

	var i = 1;
	var iRowNumber = 0;

	$$('div.ArticleHalf').each(function(oArticle) {
		oArticleBody = oArticle.getElement('div.ArticleBody');
		if (i % 2 == 1)
		{
			iRowNumber++;
		}
		oArticleBody.setStyle('height', aMaxHeight[iRowNumber]);
		i++;
	});
}

function getElementsByClass(oElementRoot, sElementType, sClassName)
{
	var aElementArray = new Array();
	var aUnfilteredElements = new Array();

	aUnfilteredElements = oElementRoot.getElementsByTagName(sElementType);
	for (var i = 0; i < aUnfilteredElements.length; i++)
	{
		if (aUnfilteredElements[i].className == sClassName)
			aElementArray[aElementArray.length] = aUnfilteredElements[i];
	}
	return (aElementArray);
}

function fnSwitchTab(oTabElement, sDivIDToShow, bScrollTop)
{
	var oItemToShow = $(sDivIDToShow);

	$ES('UL','detailtabs').each(function(oUl) {
	  for (var i = 0; i < oUl.childNodes.length; i++)
	  {
		  if (oUl.childNodes[i].nodeName == 'LI')
			  oUl.childNodes[i].className = '';
	  }
	});

	if (oOpenDiv)
		oOpenDiv.setStyle('display', 'none');

	if (bScrollTop) window.scroll(0,0);
	if (oTabElement.nodeName == 'A')
		oTabElement = oTabElement.getParent();
	oTabElement.className = 'current';
	oItemToShow.setStyle('display', 'block');
	oOpenDiv = oItemToShow;

	init();
}

window.addEvent('domready', function() {
	if ($('locale_wrapper'))
	{
		fLocaleList	= new fLocaleList('locale_wrapper');
	}
	
	var poll = new Poll();
	poll.addFormBehaviour();
});

//22-12-2008 12:12 - BG - Tooltips initializatie onder load event geplaatst (wegens "operation aborted" errors)
//see: http://www.sigsiu.net/forum/index.php?PHPSESSID=3dpngd1l64d9nofr9n0ion49t6&/topic,8984.0.html#msg32115
window.addEvent("load", function()
{
	//Initialize Tooltips
	new Acsi_Tips($$('.tooltip'), { showDelay: 300 });
});

Cufon.replace('div#tabs>ul>li>a', { fontFamily: 'Myriad Pro', fontWeight: 700 });
Cufon.replace('.Myriad', { fontFamily: 'Myriad Pro', fontWeight: 900 });
Cufon.replace('.Angelina', { fontFamily: 'Angelina' });
Cufon.replace('.Tekton', { fontFamily: 'Tekton Pro' });