// resize functie (deel code van supersized.js)
	$.fn.resizenow = function() {
		return this.each(function() {
			var imgH = $(this).children().height(),
				imgW = $(this).children().width(),
				biwH = $(window).height(),
				biwW = $(window).width(),
				ratio = imgH/imgW;
	
			if ((biwH/biwW) > ratio){
				$(this).height(biwH);
				$(this).width(biwH / ratio);
				$(this).children().height(biwH);
				$(this).children().width(biwH / ratio);
			} else {
				$(this).width(biwW);
				$(this).height(biwW * ratio);
				$(this).children().width(biwW);
				$(this).children().height(biwW * ratio);
			}
			$(this).children().css('left', (biwW - $(this).width())/2);
			$(this).children().css('top', (biwH - $(this).height())/2);
	
			return false;
		});
	};

// preload
	$.fn.preloader = function(options){
		var defaults = {
			delay:0,
			preload_parent:this,
			check_timer:300,
			ondone:function(){ },
			oneachload:function(image){  },
			fadein:300 
		};

		var options = $.extend(defaults, options),
			root = $(this),
			images = root.find("img").css({"visibility":"hidden",opacity:0}),
			timer,
			counter = 0,
			i=0,
			checkFlag = [],
			delaySum = options.delay ,

		init = function(){
			timer = setInterval(function(){
				if(counter>=checkFlag.length){
					clearInterval(timer);
					options.ondone();
					return;
				}
				for(i=0;i<images.length;i++){
					if(images[i].complete==true){
						if(checkFlag[i]==false){
							checkFlag[i] = true;
							options.oneachload(images[i]);
							counter++;
							
							delaySum = delaySum + options.delay;
						}
						$(images[i]).css("visibility","visible").delay(delaySum).animate({opacity:1},
						options.fadein,
						function(){ $(this).parent().removeClass("preloader");});
					}
				}
			},options.check_timer)
		};

		images.each(function(){
			if($(this).parent(options.preload_parent).length==0)
				$(this).wrap("<div class='preloader' />");
			else
				$(this).parent().addClass("preloader");
			checkFlag[i++] = false;
		}); 
		images = $.makeArray(images); 

		var icon = jQuery("<img />",{
			id : 'loadingicon' ,
			src : 'images/load.gif'
		}).hide().appendTo("body");

		timer = setInterval(function(){
			if(icon[0].complete==true){
				clearInterval(timer);
				init();
				icon.remove();
				return;
			}
		},100);
	}

	$(document).ready(function(){
	
		$('#mainwrap').css('opacity', 0).delay(100).animate({'opacity':1}, 400, function() {
				if ($.browser.msie)
				this.style.removeAttribute('filter');
			});
// png voor IE
		$('body').pngFix();
// warning if using IE6
	if (($.browser.msie) && ($.browser.version == "6.0")){
		$('#wrap').prepend('<div style="position:relative;left:0;top:0;height:54px;width:100%;display:block;background: pink ;font-weight:bold;border-bottom:5px solid red;"><p style="padding:10px;">U bekijkt deze site in Internet Explorer 6. Sommige functies werken niet met deze browser. Daarom adviseren wij u de browser te updaten.<br /><a href="http://www.mozilla-europe.org/nl/firefox/">"Firefox"</a>, <a href="http://www.apple.com/safari/">"Safari"</a>, <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">"Internet Explorer"</a>, <a href="http://www.google.com/chrome">"Google Chrome"</a> en <a href="http://www.opera.com/">"Opera"</a> zijn allemaal uitstekende opties om uw verouderde en onveilige browser te vervangen.</p></div>');
	}
// enter does submit if IE
	if ($.browser.msie){
		$('input').keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents('form').submit();
				return false;
			}
		});
	}
// dotted linkline
		$('a').focus(function() {this.blur();});
		$('div:not(.mainbox) a img').hover(function(){
			$(this).stop().animate({'opacity':.7}, 100);
		}, function(){
			$(this).stop().animate({'opacity':1}, 400);
		})

// als links niet in markup mogen ivm worst-in-blik.
		$('a.verborgen').each(function(){
			var hiddenLink = $(this).text(),
				splitLink = hiddenLink.split('$'),
				emailLink = splitLink[0]+'@'+splitLink[1]+''+splitLink[2]+'.'+splitLink[3];
			$(this).attr('href', 'mailto:'+emailLink);
			$(this).text(emailLink);
			$(this).removeClass('verborgen');
		});
// values van label in input
// form als t-shirt
		$('label.hidden').each(function(){
			var tekst = $(this).text();
			$(this).next('input').val(tekst);
			$(this).hide();
		});
// focus op input
		$('textarea, input[type="text"]').addClass("idleField");
		// textarea
		$('textarea').focus(function() {
			$(this).removeClass("idleField").addClass("focusField");
		});
		$('textarea').blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
		});
		//input type=text
		$('input[type="text"], textarea').live('focus', function() {
			$(this).removeClass("idleField").addClass("focusField");
			var defVal = $(this).prev('label').text();
			if (this.value == this.defaultValue){ 
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		$('input[type="text"], textarea').live('blur', function() {
			$(this).removeClass("focusField").addClass("idleField");
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});
// printbutton
		$('#printwindow').click(function(){
			window.print();
			return false;
		});
// javascript is on...
		$('.bg-image')
			.addClass('wrapped-image')
			.removeClass('bg-image')
			.wrap('<div class="bg-image-wrap" />');
// ...then we can call the resize function for the .bg-image
		$('.bg-image-wrap').resizenow().preloader();
// box_half even groot
		var box_hH = 0,
			allH = 0,
			this_p_H = 0,
			this_p_Hn = 0,
			this_h2_H = 0,
			this_h2_Hn = 0,
			thisH = 0,
			thisHn = 0;
		$('.fixed_h').each(function(){
				thisH = $(this).find('img').attr('height');
				this_p_H = $(this).children('p').outerHeight();
				this_h2_H = $(this).children('h2').outerHeight();
			if(thisH > thisHn){
				thisHn = thisH;
			}
			if(this_p_H > this_p_Hn){
				this_p_Hn = this_p_H;
			}
			if(this_h2_H > this_h2_Hn){
				this_h2_Hn = this_h2_H;
			}
			if(this_h2_Hn != 0) {
				allH = thisHn + this_p_Hn + this_h2_Hn+25;
			} else {
				allH = thisHn + this_p_Hn;
			}
			if(allH > box_hH){
				box_hH = allH;
			}
		});
		var box_thH = 0;
		$('.fixed_th').each(function(){
			var thistH = $(this).children('p').height();
			if(thistH > box_thH){
				box_thH = thistH;
			}
		});
		$('.fixed_h').css('height', box_hH);
		if(this_h2_Hn != 0) {
			$('.fixed_h img').css('top', this_h2_Hn+25);
		} else {
			$('.fixed_h img').css('top', 0);
		}
		$('.fixed_h p').css({
			'top':this_h2_Hn+thisHn+35, 
			'position':'absolute', 
			'left':0
		});
		$('.fixed_th').css('height', box_thH);

//hoverbreder navigation
		$('.navigation_top .prev, .navigation_top .next').hover(function(){
			$(this).children('span').fadeIn(300);
		}, function(){
			$(this).children('span').fadeOut(300);
		});


// footer magic
//		$('#footer p').hover(function(){
//			$('#mainwrap').stop().animate({'opacity': 0}, 200);
//		}, function(){
//			$('#mainwrap').stop().animate({'opacity': 1}, 400, function() {
//				if ($.browser.msie)
//				this.style.removeAttribute('filter');
//			});
//		});
// fancybox
		$('a.fancy').fancybox({
			'titleShow' : true,
                        'overlayOpacity' : 0.7,
                        'overlayColor' : '#000'
		});

// fancybox vimeo
	$("a.video").click(function() {
		$.fancybox({
                        'overlayOpacity' : 0.7,
                        'overlayColor' : '#000',
			'padding'		: 0,
			'margin'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'		: 600	,
			'height'		: 339,
			'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			'type'			: 'swf'
		});
		return false;
	});

	});
// na browser resize, afbeelding ook resizen
	$(window).bind("resize", function(){
		$('.bg-image-wrap').resizenow();
	});
