﻿/* Dit bestand heet custom.js en niet global.js omdat visual studio mij om één of andere reden geen global.js liet maken in deze map */
function OpenPics(url, iwidth, iheight) {
    window.open(url, "afbeelding", "width=" + iwidth + ",height=" + iheight + ",left=125,top=100");
}
$(function() {
	// Als de breedte van het submenu kleiner is dan zijn parent-listitem, dan moet de breedte ingesteld worden, anders niet.
	$("#mainmenu ul ul").each(function() {
		var w = $(this).parent().width();
		$("a", this).css({ width: w });
		if ($(this).width() < $(this).parent().width()) {
			$(this).width($(this).parent().width());
		}
	});

	// Dropdowns:
	$("#mainmenu li").hover(function() {
		// mouseOver					
		$("ul", this).show();
	}, function() {
		// mouseOut
		$("ul", this).hide();
	});

	// Kijken of alle verplichte velden ingevuld zijn
	$("form").each(function() {
		$(this).submit(function() {
			var ok = true;
			var m = 'Niet alle verplichte velden zijn ingevuld!';
			$(".required", this).each(function() {
				if ($(this).val() == '') { ok = false; }
			});
			$(".requiredMail", this).each(function() {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($(this).val()) == false) {
					m = 'Het ingevoerde e-mail adres is onjuist!';
					return false;
				}
			});
			if (ok) {
				return true;
			} else {
				alert(m);
				return false;
			}
		});
	});

	$("form.poll").submit(function() {
		var ok = false;
		$("input[type=radio]", this).each(function() {
			if ($(this).attr("checked") != false) {
				ok = true;
			}
		});
		if (ok) {
			return true;
		} else {
			alert('U dient een keuze te maken voor de poll!');
			return false;
		}
	});

	// Links openenen in een extern venster, de xhtml-strict manier:
	$("a[rel=external]").click(function() {
		window.open($(this).attr('href'));
		return false;
	});


	// Week overzichten op statistieken pagina
	$('.stats_item').bind('click', function() {

		$('.stats_item').removeClass('active');
		$(this).addClass('active');

		var strTitel = $(this).attr('rel').split('|')[0]
		var strMedia = $(this).attr('rel').split('|')[1]

		$('#stats_details a').attr('href', '/image.aspx?id=' + strMedia + '&mode=full&type=stats');
		$('#stats_details a').attr('title', strTitel);

		$('#stats_details img').attr('src', '/image.aspx?id=' + strMedia + '&mode=thumb2&type=stats')
		$('#stats_details a').attr('alt', strTitel);

		return false;
	});

	$('.stats a.header').bind('click', function() {
		var strWekenId = '#weken_' + $(this).attr('rel');
		$('.stats li').removeClass('active');
		$('.stats li').find('.klap').text('klap open');
		$(strWekenId).addClass('active');
		$(strWekenId).find('.klap').text('klap dicht');
		return false;
	});

});
