var insideLayer = false;

function navOver(id, isSub, fc) {

	var pf = (isSub ? '' : '_root');

	document.getElementById('nav_item_'+id).className = 'navigation_item'+pf+'_over';
	document.getElementById('nav_label_'+id).className = 'navigation_label'+pf+'_over';

	if (fc) {
		var arrow = document.getElementById('nav_arrow_'+id);
		if (arrow) arrow.src = "/mod_bin/general/arrow.php?fc="+fc;
	}

}

function navOut(id, isSub, fc) {

	var pf = (isSub ? '' : '_root');

	document.getElementById('nav_item_'+id).className = 'navigation_item'+pf;
	document.getElementById('nav_label_'+id).className = 'navigation_label'+pf;

	if (fc) {
		var arrow = document.getElementById('nav_arrow_'+id);
		if (arrow) arrow.src = "/mod_bin/general/arrow.php?fc="+fc;
	}
	
}

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 = "#E0DCD8 url('"+g_str_hostname+"/img/nav_item.gif') no-repeat 100% 50%";
		}
		
		if (prev && prev.style) {
			prev.style.background = "#E0DCD8 url('"+g_str_hostname+"/img/nav_item.gif') no-repeat 100% 50%";
		}

	} else {

		if (is_selected) {

		} else if (prev_selected) {

			list_item.style.background = "#E0DCD8 url('"+g_str_hostname+"/img/nav_item_off.gif') repeat-x 100% 50%;";	

		} else if (next_selected) {

			if (prev && prev.style) {
				prev.style.background = "#E0DCD8 url('"+g_str_hostname+"/img/nav_item_off.gif') repeat-x 100% 50%;";
			}

		} else {

			list_item.style.background = "#E0DCD8 url('"+g_str_hostname+"/img/nav_item_off.gif') repeat-x 100% 50%;";
			if (prev && prev.style) {
				prev.style.background = "#E0DCD8 url('"+g_str_hostname+"/img/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 get_near_photo(photo_id, direction) {
	//alert(typeof(big_images));

	var prev, next;

	for (index in big_images) {
		if (typeof(big_images[index]) == 'string') {
			if (next) return index;

			if (index == photo_id) {
				if (direction == -1) return prev;
				if (direction == 1) next = true;
			}	
			prev = index;
		}
	}
	return false;
}

function show_photo(photo_id) {

	var photo_big_holder = document.getElementById('photo_big_holder');

	hide_photo();

	if (big_images[photo_id]) {
		var big_url = '/uri/?uri=' + big_images[photo_id];

		prev_photo = get_near_photo(photo_id, -1);
		removeElement('photo_back_link');
		if (prev_photo) {
			//--- show backlink
			var oBackLink = document.createElement('A');
			oBackLink.id = 'photo_back_link';
			oBackLink.href = "javascript:show_photo('"+prev_photo+"')";
			oBackLink.className = 'btn_prev';
			oBackLink.innerHTML = '&laquo; vorige';
			photo_big_holder.appendChild(oBackLink);
		}
		
		next_photo = get_near_photo(photo_id, 1);
		removeElement('photo_next_link');
		if (next_photo) {
			//--- show backlink
			var oNextLink = document.createElement('A');
			oNextLink.id = 'photo_next_link';
			oNextLink.href = "javascript:show_photo('"+next_photo+"')";
			oNextLink.className = 'btn_next';
			oNextLink.innerHTML = 'volgende &raquo;';
			photo_big_holder.appendChild(oNextLink);
		}
		
		var oImg = new Image();
		oImg.id		= 'photo_big';
		oImg.src	= big_url;
		oImg.title	= "Klik om te sluiten";
		oImg.alt	= "Klik om te sluiten";
		oImg.onclick = hide_photo;

		photo_big_holder.appendChild(oImg);

		if (big_desc[photo_id]) {
			
			var desc_span = document.createElement('DIV');
			desc_span.id = 'photo_big_desc';
			desc_span.innerHTML = big_desc[photo_id];
			photo_big_holder.appendChild(desc_span);

		}

		//--- position popup
		photo_big_holder.style.top = (document.body.scrollTop > 120) ? document.body.scrollTop + 10 : 120;
		//photo_big_holder.style.left = (Math.round((document.body.clientWidth - 780) / 2) + 204);

		photo_big_holder.style.display = '';

	}
}

function removeElement(el_id) {
	var element = document.getElementById(el_id);
	if (element) element.parentNode.removeChild(element);
}

function hide_photo() {
	var photo_big_holder = document.getElementById('photo_big_holder');
	if (photo_big_holder && document.getElementById('photo_big')) {
		photo_big_holder.removeChild(document.getElementById('photo_big'));
	}	
	if (photo_big_holder && document.getElementById('photo_big_desc')) {
		photo_big_holder.removeChild(document.getElementById('photo_big_desc'));
	}	

	photo_big_holder.style.display = 'none';


}


/* Dynamic menu D4Pro */

var menus = new Array();
var timers = new Array();

function init_menu(id) {
	if (typeof(id) == 'undefined' || !id) id = 'nav';
	menus[id] = document.getElementById(id);

	var li = menus[id].getElementsByTagName('li'), i = li.length;
	while (i--) {
		if (li[i].className == 'level_2') {

			li[i].onmouseover = showMenu;
			li[i].onmouseout = hideMenu;
		}
	}
	menus[id].onmouseout = timeout;
	menus[id].onmouseover = cleartimer;
}

	function timeout() {
		timers[this.id] = setTimeout("hideMenus(menus['"+this.id+"'], null)", 1000);
	}
	
	function cleartimer() {
		if (timers[this.id]) {
			clearTimeout(timers[this.id]);
			timers[this.id] = null;
		}
	}

	function showMenu() {
		var ul = this.parentNode;
		this.className += ' hover';
		while (ul) {
			if (ul.tagName.toLowerCase() == 'ul') {
				hideMenus(ul, this);
				break;
			}
			ul = ul.parentNode;
		}
	
		ul = this.firstChild;
		while (ul) {
			if (ul.nodeType == 1 && ul.tagName.toLowerCase() == 'ul') {
				ul.style.display = 'block';
				ul.style.visibility = 'visible'; /* necessary for IE*/
				break;
			}
			ul = ul.nextSibling;
		}
	}
	
	function hideMenu() {
		this.className = this.className.replace('hover','');
	}

	function hideMenus(level, skipli) {
		var stack = [level], i = 0, li, j, el, tag;
	
		do {
			li = stack[i].childNodes, j = li.length;
			while (j--) {
	
				el = li[j];
				if (el.nodeType == 1 && el != skipli) {
					tag = el.tagName.toLowerCase();
					if (tag == 'li') {
						stack[i++] = el;
					} else if (tag == 'ul' && el.style.display == 'block') {
						stack[i++] = el;
						el.style.display = 'none';
						el.style.visibility = 'hidden'; /* necessary for IE*/
					}
				}
			}
		} while (i--);
	}

/* --------------------------- */

function open_tellafriend() {
	var popup = document.getElementById('titaf_form');
	if (popup) {
		show_overlay();
		center_layer(popup, 287, 150);
		popup.style.display = '';
	}
}

function close_tellafriend() {
	var popup = 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 show_splash() {
	show_overlay();
	var splash_page = document.getElementById('splash_page');
	center_layer(splash_page, 270, 200);
	splash_page.style.display = '';
}

function splash_ok_redirect(url)
{
    var frm = document.createElement('FORM');
	frm.method = 'POST';
	frm.action = document.location.href;
	frm.target = '_self';

	var inp = document.createElement('INPUT');
	inp.type = 'hidden';
	inp.name = 'splash_ok';
	inp.value = '1';

	frm.appendChild(inp);

    var inp2 = document.createElement('INPUT');
	inp2.type = 'hidden';
	inp2.name = 'splash_redirect';
	inp2.value = url;

	frm.appendChild(inp2);

	document.body.appendChild(frm);

	frm.submit();
}

function splash_ok() {

	var frm = document.createElement('FORM');
	frm.method = 'POST';
	frm.action = document.location.href;
	frm.target = '_self';

	var inp = document.createElement('INPUT');
	inp.type = 'hidden';
	inp.name = 'splash_ok';
	inp.value = '1';
	frm.appendChild(inp)
	document.body.appendChild(frm)
	frm.submit();
}

function show_dlc_item(item_id) {
	if (!item_id || !dlc_items[item_id]) return;

	var item = dlc_items[item_id];
	var holder = document.getElementById('dlc_detail_item');

	//--- clear item
	while (holder.firstChild) {
		holder.removeChild(holder.firstChild);
	}

	if (item['img_uri']) {
		var img = document.createElement('img');
		img.src= '/uri/?uri=' + item['img_uri'];
		holder.appendChild(img);
	} else {

		var h3 = document.createElement('h3');
		h3.appendChild(document.createTextNode(item['title']));
		holder.appendChild(h3);
	}

	var paragraph = document.createElement('p');
	paragraph.innerHTML = item['desc'];
	holder.appendChild(paragraph);

	if (item['link']) {
		var link = document.createElement('A');
		link.href = '/uli/?uli=' + item['link'];
		link.target = '_blank';
		link.appendChild(document.createTextNode(item['link_txt']));
		holder.appendChild(link);
	}

}


function ctrl_set_mandatory(att_code, state) {
	var tbl = document.getElementById(att_code+'_ctrl_maincontainer');
	tbl.rows[0].cells[1].innerHTML = state ? '<span class="ctrl_mandatory" id="'+att_code+'_mandatory">&nbsp;*</span>' : '';
}
		
function tmai_kyv_checkform(frm, button) {
						
	if (frm) {
	
		if (autoCheckForm(frm)) {
			
			if (document.getElementById(button)) document.getElementById(button).value = 'pressed';

			var user_name = document.getElementById("tmai_usr_name");
			user_name.value = frm.elements['tmai_usr_email'].value;

			return true;
			
		}
		
	}
	
	return false;

}

