// site specific functions

createMailto = function(pers, domain, customText) {
	var email = pers + '@' + domain;
	(customText == null) ? lnk = email : lnk = customText;
	document.write('<a href="mailto:'+email+'">'+lnk+'</a>');
}

validateEmail = function(add) { 
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/; 
	return emailPattern.test(add); 
} 

initAlignedImages = function() {
	$('img').each(function(e) { $(this).addClass($(this).attr('align')); });
}

initNewsletterSubscription = function() {
	f = document.getElementById('news-subscribe');
	f.onsubmit = function() {
		if (!validateEmail(document.getElementById('news-email').value)) { alert('Sorry, het e-mailadres wat is ingevuld is incorrect.'); return false; }
	};
	
	fld = document.getElementById('news-email');
	fld.defaultValue = fld.value;
	fld.onfocus = function() {
		if (this.value == this.defaultValue) { this.value = ''; this.className = "focus"; }
	}
	fld.onblur = function() {
		if (this.value == '') { this.value = this.defaultValue; this.className = ""; }
	}
}

initPhotoOverlays = function() {
	var cnt = 1;
	$('.photos').each(function(e) {
		$(this).find('img').each(function(e) {
			$(this).wrap('<a href="'+$(this).attr('src')+'" rel="sect'+cnt+'" title="'+$(this).attr('alt')+'"></a>')									  
		});
		
		$(this).find('a').each(function(e) {	
			$(this).colorbox({
				 	transition:"elastic", 
					current: "foto {current} / {total}",
					onOpen:function(){ $('object').css('visibility', 'hidden'); },
					onClosed:function(){ $('object').css('visibility', 'visible'); }
			});	
		});
		cnt++;
	});
}

initNav = function() {
	$('#nav1 .has-sub').mouseover(function(e) { this.className = "has-sub hover"; });
	$('#nav1 .has-sub').mouseout (function(e) { this.className = "has-sub"; });
}

$(document).ready(function() {
	initNewsletterSubscription();
	initPhotoOverlays();
	initAlignedImages();
	initNav();
});





