var pos = 0;
var moving = false;
var gallery_pos = 0;
var gallery_moving = false;
var gallery_pages;
var intval;
var fadeOut;


function email_gogo() {
	$('form_login_email').submit();
	$('form_login_email').style.visibility = 'hidden';
	$('roundcube_email_iframe').style.visibility = '';
}


function load_talentInt(id) {
	intval = setInterval("talentShowRandom('"+id+"');", 8000);
}


function talentShowRandom (id) {
	new Ajax.Updater(
		'talenten_overview',
		'site/slideshow.php',
		{
			method: 'post',
			parameters: 'id='+id,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function() {
				Effect.Appear('talenten_overview', {duration: 1});
				fadeOut = setTimeout("Effect.Fade('talenten_overview', {duration: 1})",6500)
			}
		}
	);
}

function verwijder_vakantie (id) {
	$('huidige_vakanties').style.display = 'none';
	
	new Ajax.Updater(
		'huidige_vakanties',
		'actions.php',
		{
			method: 'post',
			parameters: 'verwijder=1&id='+id,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function() {
				Effect.Appear('huidige_vakanties', {duration: 0.5});
			}
		}
	);
}


function load_user_info(uid) {
	$('user_details').style.display = 'none';
	handler = 'site/user_info.php';
	new Ajax.Updater(
		'user_details',
		'ajax.php',
		{
			method: 'get',
			parameters: 'page='+handler+'&u='+uid,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function() {
				Effect.Appear('user_details', {duration: 0.5});
			}
		});
}

function showCollegaInfo(id) {
	
	for (i = 1; $('interne_collega_details_'+i); i++)
	{
		$('interne_collega_details_'+i).style.display = 'none';
		$('foto_'+i).style.borderColor = 'black';
	}
	
	$('interne_collega_details_'+id).style.display = '';
	$('foto_'+id).style.borderColor = '#06648D';
}

function load_email(u,p) {
	new Ajax.Updater(
		'',
		'roundcube/index.php',
		{
			method: 'post',
			parameters: '_action=login&_user='+u+'&_pass='+p,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache']
		});
}

function numeric_add_string(n, s) {
	s = s.replace(',', '.');
	s = parseFloat(s);
	if (""+s != 'NaN') return n+s;
	return n;
}

function update_uren_totaal() {

	weektotaal = 0;
	
	var dagtag = new Array('', 'ma', 'di', 'wo', 'do', 'vr', 'za', 'zo');
	
	for (dag = 1; dag <= 7; dag++) {
		dagtotaal = 0;
		
		dagtotaal = numeric_add_string(dagtotaal, $('uren_'+dagtag[dag]+'_regulier').value);
		dagtotaal = numeric_add_string(dagtotaal, $('uren_'+dagtag[dag]+'_overuren').value);
		dagtotaal = numeric_add_string(dagtotaal, $('uren_'+dagtag[dag]+'_onregelmatig').value);
		dagtotaal = numeric_add_string(dagtotaal, $('uren_'+dagtag[dag]+'_vakantie').value);
		dagtotaal = numeric_add_string(dagtotaal, $('uren_'+dagtag[dag]+'_ziek').value);
		dagtotaal = numeric_add_string(dagtotaal, $('uren_'+dagtag[dag]+'_overig').value);
		
		if (dagtotaal) {
			weektotaal += dagtotaal;
			if (parseInt(dagtotaal) != dagtotaal) {
				dagtotaal = dagtotaal.toFixed(2);
			}
			$('day_total_'+dag).innerHTML = (''+dagtotaal).replace('.', ',');
		} else {
			$('day_total_'+dag).innerHTML = '&nbsp;';
		}
	}
	
	if (weektotaal) {
		if (parseInt(weektotaal) != weektotaal) {
			weektotaal = weektotaal.toFixed(2);
		}
		$('week_total').innerHTML = (''+weektotaal).replace('.', ',');
	} else {
		$('week_total').innerHTML = '&nbsp;';
	}
	
}

function save_uren() {
	if ($('uren_week').options) {
		if ($('uren_week').options[$('uren_week').selectedIndex].text.indexOf('ingevuld') > 0) {
			var doorgaan = confirm('Voor deze week zijn de urenstaten al ingevuld.\n\nClick op OK om nog een urenstaat in te vullen voor deze week.');
			if (!doorgaan) return false;
		}
	}
	
	$('saving').innerHTML = "<img style='margin-bottom: 40px;' src='images/indicator_black.gif' alt='Loading' title='loading' />";
	form_values = Form.serialize('uren_invullen');
	handler = 'site/uren/uren_opslaan.php';
	new Ajax.Updater(
		'uren_ajax_feedback',
		'ajax.php',
		{
			method: 'post',
			parameters: 'page='+handler+'&'+form_values,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			evalScripts:true
		});
	
	return false;
}

function gallery_move(direction, page_count) {
	if (direction == -1) {
		gallery_pos--;
		if (gallery_pos >= 0) {
			gallery_moving = true;
			setTimeout('gallery_moving = false;', 1000);
			Effect.MoveBy('gallery_thumbs', 0, 468);
		} else {
			gallery_pos = 0;
		}
	} else {
		gallery_pos++;
		if (gallery_pos < page_count) {
			gallery_moving = true;
			setTimeout('gallery_moving = false;', 1000);
			Effect.MoveBy('gallery_thumbs', 0, -468);
		} else {
			gallery_pos--;
		}
	}
}

function signout() {
	handler = 'logout.php';
	new Ajax.Request(
		'ajax.php',
		{
			parameters : 'page='+handler,
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function() {
				window.location.reload();
			}
		});
}

function roundcube_logout() {
	new Ajax.Request(
		'roundcube/index.php',
		{
			method: 'post',
			parameters: '_action=logout',
			requestHeaders: ['Expires', 'Thu, 17 May 2001 10:17:17 GMT', 'Cache-Control', 'no-cache, must-revalidate', 'Pragma', 'no-cache'],
			onComplete: function() {
				signout();
			}
		});
}

