var imgs;
var closeLink;

window.addEvent('domready',function(){
	// preload color portfolio images and bind hover events
	var p = $$('#content div.portfolio')[0];
	if(p){
		imgs = $(p).getElements('img');
		imgs.addEvent('mouseover', function(){
			this.src = this.src.replace(/.jpg/,'_c.jpg');
		}).addEvent('mouseout',function(){
			this.src = this.src.replace(/_c.jpg/,'.jpg');
		}).each(function(obj,i){
			var img = new Image();
			img.src = obj.src.replace(/.jpg/,'_c.jpg');
		});
	}
	// display contact form
	var isOpen = false;
	var popup = $('telePopup');
	var top =  (($(window).getSize().y)/2) - (popup.getSize().y)/2;
	closeLink = $$('#telePopup .close')[0];
	$$('.telLink').addEvent('click',function(){
		if(isOpen) return false; isOpen = true;
		popup.setStyle('opacity','0');
		popup.setStyle('display','block');
		popup.setStyle('top', top + parseInt($(window).getScroll().y) );
		popup.fade('in');
		return false;
	});
	$(closeLink).addEvent('click', function(){
		isOpen = false;
		popup.fade('out');
	});
	// Validate telefoon form
	$('telefooncontact').addEvent('submit', function(evt){
		new Event(evt).stop();
		if($('contactName').value.trim() == ''){
			alert('Invalid Naam');
			return false;
		}else	if($('contactTelephone').value.trim() == ''){
			alert('Invalid Telefoon');
			return false
		}else{
			$('telefooncontact').send().setStyle('display','none');
			$('telefoonconfirm').setStyle('display','block').fade('in');
			return false;
		}
	});
//unbind imgs bound events	
}).addEvent('unload',function(){
	if(imgs) imgs.destroy();
});