var errmsg = null;

/* SHOW / HIDE SENDTOAFRIENDCARD
----------------------------------------------------------------*/
function init ()
{
	if (errmsg) alert (errmsg);
	init_sendtoafriend_card ();
	init_Print ();
	init_Lokaties ();
	// init_enquete_popup ();
	
}


function init_enquete_popup () {
	
	// Alleen tonen op homepage
	if (window.location.toString() == 'http://www.bibliotheeklekijssel.nl/') {
		
		/*today_date = new Date();
		
		cookie_value = "getoond=true;";
		cookie_expires_date = new Date();
		cookie_expires_date.setFullYear(2010, 0, 1);
		cookie_expires = "expires="+cookie_expires_date.toGMTString()+";";
		
		cookie_string = document.cookie.toString();
		if (cookie_string.match(cookie_value) == null && today_date < cookie_expires_date) {
		*/
			tb_show("", "/pop-up.html?height=200&width=320&modal=true", false);
		/*
			document.cookie = cookie_value+cookie_expires;
		}
		*/
	}
	
}



/* LOKATIES SCRIPT
----------------------------------------------------------------*/
var lok_info_obj = null;
var lok_bullet_obj = null;
var timeoutId = null; 

function init_Lokaties ()
{ 	
	lokaties = Array ('lopik', 'ijsselstein', 'benschop', 'houten-centrum', 'houten-schoneveld', 'vianen');
	pos = Array ('lt', 'lt', 'lt', 'rt', 'rt', 'lb');
	
	for (i = 0; i < lokaties.length; ++i)
	{
		var elem = document.getElementById (lokaties[i]);
		if (elem)
		{
			elem.onmouseover = function () { showLokatie (this); }
			elem.foldoutdirection = pos[i];
		}
	}
}

function showLokatie (obj)
{
	if (timeoutId != null) {window.clearTimeout (timeoutId); hidelokatie (); }
	
	lok_info_obj =	document.getElementById (obj.id+"-info")
	lok_bullet_obj = obj
	
	lok_info_obj.style.top = "-1000px" ;
	lok_info_obj.style.left = "-1000px" ;
	lok_info_obj.style.display = "block";
	
	if (lok_bullet_obj.foldoutdirection == 'lt')
	{
		t = (parseInt (lok_bullet_obj.offsetTop) - parseInt (lok_info_obj.offsetHeight)) + 6;
		l = (parseInt (lok_bullet_obj.offsetLeft) - parseInt (lok_info_obj.offsetWidth));
	
		lok_info_obj.style.top = t + "px";
		lok_info_obj.style.left = l + "px" ;
		
		lok_info_obj.onmouseout = function () { if (timeoutId != null) window.clearTimeout (timeoutId); timeoutId = window.setTimeout ('hidelokatie ()', 1000); }
		lok_info_obj.onmouseover = function () { window.clearTimeout (timeoutId); }
		lok_bullet_obj.onmouseout = function () { if (timeoutId != null) window.clearTimeout (timeoutId); timeoutId = window.setTimeout ('hidelokatie ()', 1000); }
		lok_bullet_obj.onmouseover = function () { window.clearTimeout (timeoutId); }
	} else if (lok_bullet_obj.foldoutdirection == 'rt')
	{
		t = (parseInt (lok_bullet_obj.offsetTop) - parseInt (lok_info_obj.offsetHeight)) + 6;
		l = parseInt (lok_bullet_obj.offsetLeft) + 6;
	
		lok_info_obj.style.top = t + "px";
		lok_info_obj.style.left = l + "px" ;
		
		lok_info_obj.onmouseout = function () { if (timeoutId != null) window.clearTimeout (timeoutId); timeoutId = window.setTimeout ('hidelokatie ()', 1000); }
		lok_info_obj.onmouseover = function () { window.clearTimeout (timeoutId); }
		lok_bullet_obj.onmouseout = function () { if (timeoutId != null) window.clearTimeout (timeoutId); timeoutId = window.setTimeout ('hidelokatie ()', 1000); }
		lok_bullet_obj.onmouseover = function () { window.clearTimeout (timeoutId); }
	} else if (lok_bullet_obj.foldoutdirection == 'lb')
	{
		t = parseInt (lok_bullet_obj.offsetTop) + 10;
		l = (parseInt (lok_bullet_obj.offsetLeft) - parseInt (lok_info_obj.offsetWidth)) +6;
	
		lok_info_obj.style.top = t + "px";
		lok_info_obj.style.left = l + "px" ;
		
		lok_info_obj.onmouseout = function () { if (timeoutId != null) window.clearTimeout (timeoutId); timeoutId = window.setTimeout ('hidelokatie ()', 1000); }
		lok_info_obj.onmouseover = function () { window.clearTimeout (timeoutId); }
		lok_bullet_obj.onmouseout = function () { if (timeoutId != null) window.clearTimeout (timeoutId); timeoutId = window.setTimeout ('hidelokatie ()', 1000); }
		lok_bullet_obj.onmouseover = function () { window.clearTimeout (timeoutId); }
	}
	
}
function hidelokatie ()
{
	if (lok_bullet_obj != null)
	{
		lok_info_obj.style.display = 'none';
		lok_bullet_obj.onmouseout = null;
		lok_bullet_obj.onmouseover = function () { showLokatie (this); }
		lok_bullet_obj = null ;
	}
	timeoutId = null;
}

/* STAF SCRIPT
----------------------------------------------------------------*/
function init_sendtoafriend_card ()
{
	if (document.getElementById ('staf_btn') && document.getElementById ('staf') && document.getElementById ('staf_closebtn'))
	{
		document.getElementById ('staf_closebtn').onclick = function () { hide_sendtoafriend_card (); this.blur (); return false; }
		document.getElementById ('staf_closebtn').onmouseover = function () { this.style.cursor = "pointer"; }
		document.getElementById ('staf_btn').onclick = function () { show_sendtoafriend_card (); this.blur (); return false; }	
		document.getElementById ('send-to-a-friend_card_frm-submit').onclick = function () { send_sendtoafriend_form (); this.blur (); return false; }
		document.getElementById ('staf_btn').style.display = 'inline';
	}
}

function show_sendtoafriend_card ()
{
	document.getElementById ('staf').style.top = "-1000px" ;
	document.getElementById ('staf').style.left = "-1000px";
	document.getElementById ('staf').style.display = "block";
	pageOffset = findPageOffset ();
	windowSize = findWindowSize ();
	position = new Array ();
	positionY = pageOffset[1] + Math.floor ((windowSize[1]-parseInt (document.getElementById ('staf').offsetHeight))/3);
	positionX = pageOffset[0] + Math.floor ((windowSize[0]-parseInt (document.getElementById ('staf').offsetWidth))/2);
	
	document.getElementById ('staf').style.top = positionY+ "px";
	document.getElementById ('staf').style.left = positionX+ "px";
	document.getElementById ('staf').style.display = "block";
}

function hide_sendtoafriend_card ()
{ 
	if (document.getElementById ('staf'))
	{
		document.getElementById ('staf').style.display = "none";
	}
}

function send_sendtoafriend_form ()
{ 
  var err = false;
  var afz_naam = document.getElementById('afz_naam');   
  if (afz_naam.value == '') { afz_naam.style.borderColor = 'red'; err = true; } else { afz_naam.style.borderColor = '#fff'; }
  
  var afz_email = document.getElementById('afz_email');   
  if (afz_email.value == '') { afz_email.style.borderColor = 'red'; err = true; } else { afz_email.style.borderColor = '#fff'; }
  
  var ontv_naam = document.getElementById('ontv_naam');   
  if (ontv_naam.value == '') { ontv_naam.style.borderColor = 'red'; err = true; } else { ontv_naam.style.borderColor = '#fff'; }
  
  var ontv_email = document.getElementById('ontv_email');   
  if (ontv_email.value == '') { ontv_email.style.borderColor = 'red'; err = true; } else { ontv_email.style.borderColor = '#fff'; }
    
  if (!err) { document.stoaf_frm.submit(); }

}

/* PRINT SCRIPT
----------------------------------------------------------------*/
function init_Print ()
{
	if (window.print && document.getElementById ("print-btn"))
	{ 
		document.getElementById ("print-btn").style.display = 'inline';
		document.getElementById ("print-btn").onclick  = function () { window.print (); return false; }
	}
}


/* findPageOffset 
----------------------------------------------------------------*/
function findPageOffset ()
{
	if (window.pageYOffset)
	{
		pageOffset = [parseInt (window.pageXOffset), parseInt (window.pageYOffset)];
	} else {
		pageOffset = [parseInt (document.documentElement.scrollLeft),  parseInt (document.documentElement.scrollTop)];
	}
	return pageOffset;
}


/* findWindowSize
----------------------------------------------------------------*/
function findWindowSize ()
{
	if (window.innerHeight)
	{
		windowSize = [parseInt (window.innerWidth),  parseInt (window.innerHeight)];
	} else {
		windowSize = [parseInt (document.documentElement.clientWidth), parseInt (document.documentElement.clientHeight)];
	}
	return windowSize;
}

/* findPos (obj) written by ppk, www.quirksmode.org
----------------------------------------------------------------*/
function findPos (obj)
{
	var x = '';
	for (a in obj) x = x + a + ' ';
	x = '';
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		x = curleft;
		while (obj = obj.offsetParent)
		{
			x = x + ' ' + obj.id + ':' + obj.offsetLeft;
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft, curtop];
}

/* SHORT GENERIC ONLOAD BY BROTHERCAKE
----------------------------------------------------------------*/
if (typeof window.addEventListener != 'undefined') {
	window.addEventListener ('load', init, false);
} else if (typeof document.addEventListener != 'undefined') {
	document.addEventListener ('load', init, false);
} else if (typeof window.attachEvent != 'undefined') {
	window.attachEvent ('onload', init);
}
