/* voor het landkaartje */
function show_info(nr) {
	if (document.getElementById('info_default')) {
		document.getElementById('info_default').style.display = 'none';
	}

	showLayer('info_'+nr, document.getElementById('location_map'), 0,0,0,0,10,10);
	document.getElementById('info_'+nr).style.display = 'inline';
	
}
function hide_info(nr) {
	document.getElementById('info_'+nr).style.display = 'none';

	if (document.getElementById('info_default')) {
		showLayer('info_default', document.getElementById('location_map'), 0,0,0,0,10,10);
	}
}

function show_point(id, h_off, v_off) {
//	alert (h_off+' - '+ v_off);
	showLayer(id, document.getElementById('location_map'), 0,0,0,0, h_off, v_off);
	document.getElementById(id).style.display = 'inline';

	show_info(id);
}

function nav_in(item){
//	document.getElementById('link_'+item).className='nav_'+item;
//	document.getElementById('link_' +item).style.color='#ffffff';	
	document.getElementById('block_'+item).src='/img/square_'+item+'.png';
	document.getElementById('pijl_'+item).style.display='';
}

function nav_out(item){
//	document.getElementById('link_' +item).style.color='#cccccc';	
	document.getElementById('block_'+item).src='/img/square_0.png';
	document.getElementById('pijl_' +item).style.display='none';
}

function subnav_in(nav_id) {
	document.getElementById('pijl_'+ nav_id).style.display='';
}

function subnav_out(nav_id) {
	document.getElementById('pijl_'+ nav_id).style.display='none';
}

function save_click(item_code) {
	setCookie('active_main_nav', item_code);	
	delCookie('active_sub_nav');
}

function save_click_sub(nav_id) {
	setCookie('active_sub_nav', nav_id);	
}


function clear_main_nav_cookie() {
//	delCookie();
}


// The specification for cookies says that browsers need support no more than 300 different cookies.
// Of those, no more than 20 should be associated with any particular server. 
// For each cookie, the data stored is not expected to exceed 4 kilobytes.
function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
		+ (path ? '; PATH=' + path : '')
		+ (domain ? '; DOMAIN=' + domain : '')
		+ (secure ? '; SECURE' : '');
}

// A complementary function to unwrap a cookie.
function getCookie(cookieName) {
	
	var cookieValue = null;
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	
	if (posName != -1) {

		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);

		if (endPos != -1) {
			cookieValue = unescape(document.cookie.substring(posValue, endPos));
		} else {
			cookieValue = unescape(document.cookie.substring(posValue));
		}
	}
	return cookieValue;
}

function delCookie(cookieName) {
	d = new Date();
	document.cookie = escape(cookieName) + '=; expires=' + getexpirydate(-1);
}

// Returns a date in UTC format which can be used to set an expiration date for a cookie
function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime (nomilli + nodays * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

// Crossbrowser compatible positioning
// Returns an object containing the total x and y offsets for obj relative to the document
function totalElementOffset(obj) {

	var yOffset = (obj.offsetTop ? obj.offsetTop : 0);
	var xOffset = (obj.offsetLeft ? obj.offsetLeft : 0);

	var elParent = obj.offsetParent;

	while (elParent) {
		yOffset += (elParent.offsetTop ? elParent.offsetTop : 0);
		xOffset += (elParent.offsetLeft ? elParent.offsetLeft : 0);
		elParent = elParent.offsetParent;
	}
	this.y = yOffset;
	this.x = xOffset;


}

function alert_r(elm) {
	var txt = '';

	for (index in elm) {
		txt += 'elm['+index+'] = '+elm[index] + '\n';
	}

	alert(txt);
}
/*
	
	Shows a layer at a specific position.
	id is the layer id, parent is the object to align 
	the layer to and the pos and align arguments specify
	the layer's position relative to the parent object;
	The vAlign/hAlign side of the layer will be placed at the
	vPos/hPos coordinate of the parent object:
	             
	          ----------------  <- [vPos 0]
			 |     PARENT     |
	          ----------------  <- [vPos 1]
             ^                ^
	      [hPos 0]         [hPos 1]
		  

	          --------------  <- [vAlign 0]
			 |     LAYER     |
	          --------------  <- [vAlign 1]
             ^               ^
	     [hAlign 0]      [hAlign 1]
		  
*/

function showLayer(id, parent, hPos, vPos, hAlign, vAlign, hOffset, vOffset) {

	var layer = document.getElementById(id);
	var offset = new totalElementOffset(parent);
	var left = offset.x;
	var top = offset.y;
//	alert(left + ' - ' + top);

	
	if (hPos == 1) left += parent.offsetWidth;
	if (vPos == 1) top += parent.offsetHeight;
	if (hAlign == 1) left -= layer.style.width.replace(/px/,'');
	if (vAlign == 1) top -= layer.style.height.replace(/px/,'');
	if (hOffset) left += hOffset;
	if (vOffset) top += vOffset;

//	alert_r(layer);

	layer.style.display = '';
	layer.style.left = left+'px';
	layer.style.top = top+'px';

}