// 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;
		});
	};
// center align image in maskdiv
	$.fn.centerAlignMask = function() {
		return this.each(function() {
			var maskedH = $(this).children().height(),
				maskedW = $(this).children().width(),
				maskH = $(this).height(),
				maskW = $(this).width(),
				marginT = Math.floor((maskH-maskedH)/2),
				marginL = Math.floor((maskW-maskedW)/2);

			$(this).children().css({'margin-top':marginT, 'margin-left':marginL});

			return false;
		});
	};
// form-value
	jQuery.fn.toggleVal = function(focusClass) {
		this.each(function() {
			$(this).live('focus blur', function(event) {
				if (event.type == 'focus') {
					// clear value if current value is the default
					if($(this).val() == this.defaultValue) { $(this).val(""); }
				
					// if focusClass is set, add the class
					if(focusClass) { $(this).addClass(focusClass); }
				} else {
					// restore to the default value if current value is empty
					if($(this).val() == "") { $(this).val(this.defaultValue); }
				
					// if focusClass is set, remove class
					if(focusClass) { $(this).removeClass(focusClass); }
				}
			});
		});
	};
// 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(){
// 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();});
		$('a img').hover(function(){
			$(this).stop().animate({'opacity':.7}, 100);
		}, function(){
			$(this).stop().animate({'opacity':1}, 400, function() {
				if ($.browser.msie)
				this.style.removeAttribute('filter');
			});
		});
// 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();
// new_project is center+center aligned
		$('.new_project').centerAlignMask();
		if(parseInt($('.post').css('width')) == 450){
			$('.post iframe').css({
				'width':450
			});
		} else {
			$('.post iframe').css({
				'width':410
			});
		}
// itemthumb centered
		$('.item_thumb').centerAlignMask();
// fancybox
		$('a.fancy').fancybox({
			'titleShow' : false
		});
	});
// na browser resize, afbeelding ook resizen
	$(window).bind("resize", function(){
		$('.bg-image-wrap').resizenow();
		// new_project is center+center aligned
		var np_H = $('.new_project img').attr('height'),
			np_W = $('.new_project img').attr('width');
		if($('.new_project').css('width') != '180px'){
			$('.new_project img').css({
				'margin-top': Math.floor((195-np_H)/2),
				'margin-left': Math.floor((260-np_W)/2)
			});
		} else {
			$('.new_project img').css({
				'margin-top': Math.floor((120-np_H)/2),
				'margin-left': Math.floor((180-np_W)/2)
			});
		}
		if($('.post').css('width') == '450px'){
			$('.post iframe').css({
				'width':450
			});
		} else {
			$('.post iframe').css({
				'width':410
			});
		}
	});
