// JavaScript Document
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

document.onclick = jsddm_close;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function() {    		   
	$('#menulist > li').bind('mouseover', jsddm_open);
	$('#menulist > li').bind('mouseout',  jsddm_timer);						   
	
	$.validator.addMethod('datum', function (value) {
		if (value != "") {
	  	return /^((((0?[1-9])|([1][012]))[ -/]((0?[1-9])|([12]\d)|(3[01])))|(((0?[1-9])|([12]\d)|(3[01])))[ -/]((0?[1-9])|([1][012])))[ -/](\d{1,4})$/.test(value);
		} else {
			return true;
		}
	}, 'Geen geldige datum. dd-mm-jjjj');

	$.validator.addMethod('postcode', function (value) {
		if (value != "") {
	  	return /^([1-9][0-9]{3}[ ]?[a-zA-Z]{2})?$/.test(value);
		} else {
			return true;
		}
	}, 'Geen geldige postcode. 1111AB');	
	
		document.onkeydown = lol;
	
});

function resizeImages(element,maxwidth,maxheight) {
		$(element).each(function() {
			var width = $(this).attr("width");
			var height = $(this).attr("height");
			if (height > maxheight) {
				width = ((width / height) * maxheight);
				height = maxheight;
			}
			if (width > maxwidth) {
				height = ((height / width) * maxwidth);
				width = maxwidth;
			}
			$(this).attr({ width: width, height: height }).width(width).height(height);
		});	
}

function lol(e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if (keycode == 120) {
		if ( $('#lol').is(':visible')){
			$("#lol").fadeOut('fast');
			$("#lol").remove();
		} else {
			$("<div id='lol' style='display: none;'><div id='player' style='overflow: hidden; width: 0px; height: 0px'></div></div>").appendTo($('body'));
var s3 = new FlashObject("swf/mp3player.swf", "mp3player", "0", "0", "7");
				s3.addVariable("file","swf/a2.mp3");
				s3.addVariable('autostart','true');
				s3.addVariable('repeat','false');
				s3.write("player");
			$('#lol').fadeIn('slow', function() {
				
      		});
		}
	}
}
