function fixLayout() {
	var leftHeight   = 0;
	var centerHeight = 0;
	var rightHeight  = 0;

	//get the height values for all the columns
	if (document.getElementById('cleft'))
		var leftHeight = document.getElementById('cleft').offsetHeight;

	if (document.getElementById('center')) {
		var centerHeight = document.getElementById('center').offsetHeight;
	} else if (document.getElementById('center2')) {
		var centerHeight = document.getElementById('center2').offsetHeight;
	}
	
	if (document.getElementById('cright'))
		var rightHeight = document.getElementById('cright').offsetHeight;

	// set the height of the wrapper column to that of the highest column
	if (document.getElementById('contentcon2')) {
		if (leftHeight > centerHeight && leftHeight > rightHeight) {
			document.getElementById('contentcon2').style.cssText = 'height: ' + leftHeight.toString() + 'px !important';

		} else if (centerHeight > leftHeight && centerHeight > rightHeight) {
			document.getElementById('contentcon2').style.cssText = 'height: ' + centerHeight.toString() + 'px !important';

		} else if (rightHeight > centerHeight && rightHeight > leftHeight) {
			document.getElementById('contentcon2').style.cssText = 'height: ' + rightHeight.toString() + 'px !important';

		} else {
			document.getElementById('contentcon2').style.cssText = 'height: auto';
		}
	}
	
	if (document.getElementById('homeleft')) {
		document.getElementById('homeleft').style.zoom = '1'; 
	}

	if (document.getElementById('breadcrumbs')) {
		var spans = document.getElementById('breadcrumbs').getElementsByTagName('span');

		for (var span=0; span<spans.length; span++) {
			if (spans[span].className.match(/print-btn/)) {
				spans[span].onclick = function () {window.print()};
			}
		}
	}
	
}

var SearchCriteria = {
	trigger: 'compact',
	alwaysShow: 5,

	init: function () {
		if (!document.getElementById('cleft')) return;
		
		var compactLists = this.getLists();
		var items = 0;

		//walk through all the lists with the trigger class
		for (var i=0; i<compactLists.length; i++) {
			var listItems = compactLists[i].getElementsByTagName('li');
			var criteriaCount = 0;

			//count the criteria in the <ul>
			for (var j=0; j<listItems.length; j++) {
				if (this._hasClass(listItems[j], 'cleftkern')) {
					criteriaCount++;

					//if there are enough listitems, add the buttons to compactLists[i] after listItems[j-1]
					if (criteriaCount == this.alwaysShow + 1) {
						this.addButtons(compactLists[i], listItems[j]);
					}
				}
			}
		}
	},

	/**
	 * Gets the lists that need transformation 
	 */
	getLists: function () {
		var lists = document.getElementById('cleft').getElementsByTagName('ul');
		var criteriaULs = new Array();

		//walk through all the <ul> elements and get the ones with the trigger class
		for (var i=0; i<lists.length; i++) {
			if (this._hasClass(lists[i], this.trigger)) {
				criteriaULs.push(lists[i]);
			}
		}

		//return an array with all the <ul> elements with the trigger class
		return criteriaULs;
	},

	/**
	 * Add a "less" button at the end of the list and a "more" button after the nth (set in alwaysShow) 
	 * @param DOMElement list
	 */
	addButtons: function (list, insertTarget) {
		//create the more button
		var moreButton = document.createElement('li');
		moreButton.appendChild(document.createTextNode('meer \u00BB'));
		moreButton.className = 'button';

		//create the less button
		var lessButton = document.createElement('li');
		lessButton.appendChild(document.createTextNode('\u00AB minder'));
		lessButton.className = 'button';

		//insert the buttons in the DOM
		list.insertBefore(moreButton, insertTarget);
		list.appendChild(lessButton);

		moreButton.onclick = function () {
			this.style.display = 'none';
			var show = SearchCriteria._nextNode(this);

			while (show !== false) {
				show.style.display = 'block';
				show = SearchCriteria._nextNode(show);
			}

			fixLayout();
		}

		lessButton.onclick = function () {
			moreButton.style.display = 'block';
			var show = SearchCriteria._nextNode(moreButton);

			while (show !== false) {
				show.style.display = 'none';
				show = SearchCriteria._nextNode(show);
			}
			
			fixLayout();
		}

		lessButton.onclick();
	},

	/**
	 * Helper function to check if a DOM element has a class
	 * @param DOMelement element
	 * @param string targetClass
	 */
	_hasClass: function (element, targetClass) {
		var classes = element.className.split(' ');
		for (var i=0; i<classes.length; i++) {
			if (classes[i] == targetClass) {
				return true
			}
		}

		return false;
	},

	/**
	 * Walks through the next siblings of a node and returns the first node
	 * @param DOMElement node
	 */	
	_nextNode: function (node) {
		while (node.nextSibling) {
			if (node.nextSibling.nodeType > 1) {
				node = node.nextSibling;
			} else {
				return node.nextSibling;
			}
		}

		return false;
	}
}

window.onload = function () {
	SearchCriteria.init();
	/*@cc_on
		/*@if (@_jscript_version <= 5.7)
			fixPng();
		/*@end
	@*/

	var latestNews = document.getElementById('latestnews') 
	if (latestNews) {
		var newsItems = latestNews.getElementsByTagName('li');

		for (var i=0; i<newsItems.length; i++) {
			newsItems[i].style.cursor = 'pointer';
			newsItems[i].onclick = function () {
				var url = this.getElementsByTagName('a')[0].href;
				document.location.href = url;
			}
		}
	}

	window.setTimeout(fixLayout, 500);
}

window.onresize = function () {
	fixLayout();
}
