var reg_email = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4}$/;

$(document).ready(function(){
	var cookie_name = "textsize";
	var cookie_options = { path: '/' };
	var increase_factor = 1.2;
	
	// Als cookie is gezet fontsize uit cookie overnemen.
	if($.cookie(cookie_name)) {
		var $getSize = $.cookie(cookie_name);
		$("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")});
	}
	
	// oorspronkelijke letter grootte
    $("#resetFont").click(function(){
    	$('html').css('font-size', '');
    	$.cookie(cookie_name, null, cookie_options);
		return false;
    });
   
	// Tekst vergroten
	$("#increaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*increase_factor;
		$('html').css('font-size', newFontSize);
		$.cookie(cookie_name, newFontSize, cookie_options);
		return false;
	});
  
	// Tekst verkleinen
	$("#decreaseFont").click(function(){
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum/increase_factor;
		$('html').css('font-size', newFontSize);
		$.cookie(cookie_name, newFontSize, cookie_options);
		return false;
	});
	
	// hoofdmenu 
	$('div#hoofdmenu > ul > li > a').bind('mouseenter', function() {
		$(this).addClass('selected');
		$(this).parent().siblings().children('a').removeClass('selected');
		$(this).parent().siblings().children('ul').hide();
		$(this).siblings('ul').show();
	});
	
	$('div#hoofdmenu > ul > li').bind('mouseleave',function() {
		$(this).children('ul').hide();
		$(this).children('a').removeClass('selected');
	});
	
	// hoofdmenu item topnode class active geven
	$('div#hoofdmenu > ul > li:has(a.is_context) > a').addClass('active');
	
	// bij laatste menuitem de border weghalen
	$('div#hoofdmenu > ul > li:last > a').css({borderRight:"0px"});
	
	//menuleft alle onderliggende pagina's display: none geven
	$('#sub_menu_middel > ul > li > ul').css({display:"none"});
	
	// menu left topnode a class active geven
	$('div#sub_menu_middel > ul > li:has(a.is_context) > a').addClass('active');
	
	// menu left topnode ul class show geven
	$('div#sub_menu_middel > ul > li:has(a.is_context) > ul').addClass('show');
	$('div#sub_menu_middel > ul > li:has(a.is_context) > ul').css({display:"block"});
	
	$('#portretlinks p').hide();
	
	//als class firstlink is dan hele blok als link door middel van 1 a tag
	$('.firstlink').each(function() {
		$(this).click(function() {
			document.location.href = $(this).find('a.home_nieuws_leesmeer[href]').get(0).href;
		});
		$(this).bind('mouseenter',function() {
			$(this).find('a.home_nieuws_leesmeer[href]').eq(0).addClass('hover');
		});
		$(this).bind('mouseleave',function() {
			$(this).find('a.home_nieuws_leesmeer[href]').eq(0).removeClass('hover');
		});
	})
	
	// nieuwsarchief: bij ul li structuur een class toevoegen voor maand en titel
	$('ul#nieuws_archief > li > ul').addClass('nieuws_maand');
	$('ul#nieuws_archief > li > ul > li > ul').addClass('nieuws_titel');
	
	// nieuwsarchief: jaar tallen even of oneven in de rij.
	$('ul#nieuws_archief > li:even').addClass('even');
	$('ul#nieuws_archief > li:odd').addClass('odd');
	
	$('ul#nieuws_archief  li  h1').click(function() {
		$(this).parent().toggleClass('open')
		$(this).siblings('ul').eq(0).slideToggle();
		return false;
	});	
	
	$('ul.nieuws_maand  li  h2').click(function() {
		$(this).parent().toggleClass('open')
		$(this).siblings('ul').eq(0).slideToggle();
		return false;
	});	
	
	// a tag met de class new-window openen in een nieuw venster
	$('a.new-window').click(function(){
	   window.open(this.href);
	   return false;
	});
	
	// inputfield zoeken
	$('#input_search').focus( function() {
			(this).value = '';
	});
	
	$('#input_search').blur( function() {
		if ((this).value == ''){
			(this).value = 'Zoekterm';
		}
	});
	
	$('#zoekblokform').submit( function() {
		if(this['input_search'].value.length <= 2) {
			return false;
		} else if(this['zoekbloktekst'].value == 'Zoeken' 
			   || this['zoekbloktekst'].value == 'zoeken' 
			   || this['zoekbloktekst'].value == 'zoek'
			   || this['zoekbloktekst'].value == 'Zoek'
			   || this['zoekbloktekst'].value == 'zoekterm'
			   || this['zoekbloktekst'].value == 'Zoekterm') {
			return false;
		}
	});
	
	$('.button_zoek').click( function() {
		formobj = this.parentNode.parentNode;
		$(formobj).submit();
	});
	
	// PrettyPhoto (lightbox)
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', 				/* fast/slow/normal */
		padding: 40, 							/* padding for each side of the picture */
		opacity: 0.9, 							/* Value between 0 and 1 */
		showTitle: true, 						/* true/false */
		allowresize: false, 					/* true/false */
		counter_separator_label: ' van de ', 	/* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', 				/* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	
	//DMS
	$('#bestanden tr').hover(function() {
		$(this).find('td').each(function() {
			$(this).addClass('selected');
		});
	}, function() {
		$(this).find('td').each(function() {
			$(this).removeClass('selected');
		});
	}).click(function() {
		//download
		var $td = $(this).find('td').eq(0);
		var type = $td.attr('class');
		
		if (type.indexOf('bestand') != '-1') {
			var item_id = $td.attr('id').replace('item_', '');
			document.location.href = baseUrl + currentUrl + '?download=1&item_id=' + item_id;
		} else if (type.indexOf('link') != '-1') {
			var $a = $(this).find('td a').eq(0);
			window.open($a.attr('href'), $td.val());
			return false;
		} else {
			// notitie
			var item_id = $td.attr('id').replace('item_', '');
			$.get(baseUrl + currentUrl + '?item_id=' + item_id, function(data) {
				$('div#notitie_full td.note_elem').each(function() {
					var obj = JSON.parse(data);
					for (i in obj) {
						if (i == $(this).attr('id')) {
							$(this).text(obj[i]);
							break;
						}
					}
				});
				$.modal($('#notitie_full').html(), {
					overlayClose:true,
					minHeight: 300,
					minWidth: 500
				});
			}, 'json');
		}
	});
});

