function toggleTopNav(list_item, state) {
	if (!list_item) return;
	
	var is_selected = /selected/.test(list_item.className);
	var prev = list_item.previousSibling;
	var next = list_item.nextSibling;

	var prev_selected = (prev) ? /selected/.test(prev.className) : false;
	var next_selected = (next) ? /selected/.test(next.className) : false;
	if (state) {
		if (list_item.className.indexOf('last') == -1) {
			list_item.style.background = "#7d81be url('/img/ghs/style/nav_item.gif') no-repeat 100% 50%";
		}
		
		if (prev && prev.style) {
			prev.style.background = "#7d81be url('/img/ghs/style/nav_item.gif') no-repeat 100% 50%";
		}

	} else {

		if (is_selected) {

		} else if (prev_selected) {

			list_item.style.background = "#7d81be url('/img/ghs/style/nav_item_off.gif') repeat-x 100% 50%;";	

		} else if (next_selected) {

			if (prev && prev.style) {
				prev.style.background = "#7d81be url('/img/ghs/style/nav_item_off.gif') repeat-x 100% 50%;";
			}

		} else {

			list_item.style.background = "#7d81be url('/img/ghs/style/nav_item_off.gif') repeat-x 100% 50%;";
			if (prev && prev.style) {
				prev.style.background = "#7d81be url('/img/ghs/style/nav_item_off.gif') repeat-x 100% 50%;";
			}

		
		}

	}
}

function toggleSubNav(nav_id) {

	var subnav = document.getElementById('subnav['+nav_id+']');
	if (subnav) {
		subnav.style.display = (subnav.style.display ? '' : 'none');
	}

}

/* --------------------------- */

function open_tellafriend(complete) {
	var popup = complete ? document.getElementById('titaf_form_complete') : document.getElementById('titaf_form');
	if (popup) {
		show_overlay();
		center_layer(popup, 287, 150);
		popup.style.display = '';
	}
}

function close_tellafriend(complete) {
	var popup = complete ? document.getElementById('titaf_form_complete') : document.getElementById('titaf_form');
	if (popup) {
		hide_overlay();
		popup.style.display = 'none';
	}
}


function show_overlay() {
	var ua = new UserAgent();
	var body = document.getElementsByTagName("body")[0];
	var overlay = document.createElement('div');
	overlay.id = 'overlay';

	with (overlay.style) {
/*		display = 'none';*/
		position = 'fixed';
		top = '0px';
		left = '0px';
		zIndex = '50';
		width = '100%';
		height = '100%';
	}

	if (ua.isWinIE) {
		overlay.style.position = 'absolute';
		overlay.style.height = (body.scrollHeight > body.clientHeight ? body.scrollHeight : body.clientHeight) + 'px';
	}
	//addEvent(overlay,"click",function() { hide_overlay(); });
	body.appendChild(overlay);

}

function hide_overlay() {
	var overlay = document.getElementById('overlay');
	overlay.parentNode.removeChild(overlay);
}

function UserAgent() { // user agent information
	var ua = navigator.userAgent;
	this.isWinIE = this.isMacIE = false;
	this.isGecko  = ua.match(/Gecko\//);
	this.isSafari = ua.match(/AppleWebKit/);
	this.isOpera  = window.opera;
	if (document.all && !this.isGecko && !this.isSafari && !this.isOpera) {
		this.isWinIE = ua.match(/Win/);
		this.isMacIE = ua.match(/Mac/);
		this.isNewIE = (ua.match(/MSIE 5\.5/) || ua.match(/MSIE 6\.0/));
	}
	return this;
}

function addEvent(object, type, handler) {
	if (object.addEventListener) {
		object.addEventListener(type, handler, false);
	} else if (object.attachEvent) {
		object.attachEvent(['on',type].join(''),handler);
	} else {
		object[['on',type].join('')] = handler;
	}
}


function center_layer(layer, layer_width, top_offset) {
	if (!layer) return;
	var docElem = (window.document.documentElement) ? window.document.documentElement : docElem = window.document.body
	var scroll_top = window.pageYOffset ? window.pageYOffset : docElem.scrollTop;
	var page_width = (docElem.scrollWidth ? docElem.scrollWidth : docElem.offsetWidth);

	layer.style.left = ((page_width - layer_width) / 2) + 'px';
	layer.style.top = (top_offset + scroll_top) + 'px';

}

function submitAjaxForm(frm, callback) {
	if (typeof(frm) != 'object') frm = document.forms[frm];

	if (frm) {

		arguments = '';
		for (i = 0; i < frm.elements.length; ++i) {

			cElement = frm.elements[i];
			if (cElement.tagName && cElement.tagName == 'INPUT') {
				arguments += (arguments ? '&' : '?') + cElement.name + '=' + escape(cElement.value);
			}
		}

		url = frm.action + arguments;
		xmlHttp.post(url, 'titaf', callback);
	}
}

function setTitafComplete(id) {
	close_tellafriend(); //-- close form-popup
	open_tellafriend(true); //-- open msg-popup
}

function submitTellafriend() {
	frm = document.forms['titaf'];
	if (frm) {
		if (autoCheckForm(frm)) {
			submitAjaxForm(frm, 'setTitafComplete'); 
		}
	}
}


/*Open read more **/
$(document).ready(function(){

	$('.readon').click(function(){	

		var prev = $(this).prev();	
		
		if (prev.hasClass('xml_text'))		
		{
			prev.removeClass('xml_text');
			prev.addClass('xml_text_read');
			// replace text innerhtml
			$(this).html('Lees minder');				
			return ;
			
		} 

		if (prev.hasClass('xml_text_read'))
		{
			prev.removeClass('xml_text_read');
			prev.addClass('xml_text');
			$(this).html('Lees meer >>');	
			return;
		}
		
	});

});

