// fisheye bug
( function( $ ) {
	$.dequeue = function( a , b ){
		return $(a).dequeue(b);
	};
})( jQuery ); 
// form-value
	jQuery.fn.toggleVal = function(focusClass) {
		this.each(function() {
			$(this).focus(function() {
				// 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); }
			}).blur(function() {
				// 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); }
			});
		});
	}
//preloader
jQuery.fn.onImagesLoaded = function(_cb) { 
	return this.each(function() {

		var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
			_cont = this,
				i = 0,
		_done=function() {
			if( typeof _cb === 'function' ) _cb(_cont);
		};

		if( $imgs.length ) {
			$imgs.each(function() {
				var _img = this,
				_checki=function(e) {
					if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
						{
						if( ++i===$imgs.length ) _done();
						}
						else if( _img.readyState === undefined ) // dont for IE
						{
						$(_img).attr('src',$(_img).attr('src')); // re-fire load event
						}
					}; // _checki \\

				$(_img).bind('load readystatechange', function(e){_checki(e);});
				_checki({type:'readystatechange'}); // bind to 'load' event...
			});
		} else _done();
	});
};



$(document).ready(function(){
// png voor IE
	$('body').pngFix();
// dotted linkline
	$('a').focus(function() {this.blur();});
// submenu
	$('#nav li ul').hide();
	$('#nav li a.active').next('ul').show(); 
// 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');
	});
// pdf icon replacer
$('a[href$=".pdf"]').addClass('pdf');
// overlay
	$('#overlay img, #content_box, #dock, #content_side, #nav, #logo').css('opacity', 0);
	$('#dock, #overlay').css('display','block');
	$('#content_box .big').css({
		'position': 'absolute',
		'top': '0px',
		'left': '50%',
		'cursor':'pointer',
		'float':'none'
	});
	// fitted
	$('body').onImagesLoaded(function(_this){
		$('.fitted img').wrap('<div id="overlaywrap" />').animate({'opacity': 0}, 500).animate({'opacity': 1}, 1000).animate({'opacity': 1}, 2000).animate({'opacity': 0}, 1000,
			function(){
				$('#overlay').animate({'height': 0}, 10);
			});

		// full90
		var windowH = $(window).height();
		var windowW = $(window).width();
		var imgH = $('#overlay > img:visible').height();
		var imgW = $('#overlay > img:visible').width();
		var nimgH = imgH*((windowW*.9)/imgW);
		var nimgW = imgW*((windowH*.9)/imgH);

		if( windowH > windowW ){ 
			if( nimgW < windowW ){
				$('.full > img:visible').css({
					'height':windowH*.9,
					'width':nimgW,
					'margin-left':'-'+nimgW/2+'px', 
					'margin-top':'-'+(windowH*.9)/2+'px'
				});
			} else {
				$('.full > img:visible').css({
					'width':windowW*.9,
					'height':nimgH,
					'margin-left':'-'+(windowW*.9)/2+'px', 
					'margin-top':'-'+nimgH/2+'px'
				});
			};
		} else {
			if( nimgH < windowH ){
				$('.full > img:visible').css({
					'width':windowW*.9,
					'height':nimgH,
					'margin-left':'-'+(windowW*.9)/2+'px', 
					'margin-top':'-'+nimgH/2+'px'
				});
			} else {
				$('.full > img:visible').css({
					'height':windowH*.9,
					'width':nimgW,
					'margin-left':'-'+nimgW/2+'px', 
					'margin-top':'-'+(windowH*.9)/2+'px'
				});
			};
		}

		// full100
		if( windowH > windowW ){
			if( (imgW * (windowH/imgH)) < windowW ){
				$('.full100 > img:visible').css({
					'width':windowW,
					'height':imgH * (windowW/imgW) +'px',
					'margin-top':'-'+(imgH * (windowW/imgW))/2+'px', 
					'margin-left':0,
					'left':0
				});
			} else {
				$('.full100 > img:visible').css({
					'height':windowH,
					'width':imgW * (windowH/imgH) +'px',
					'margin-left':'-'+(imgW * (windowH/imgH))/2+'px', 
					'margin-top':0,
					'top':0
				});
			}
		} else {
			if( (imgH * (windowW/imgW)) < windowH ){
				$('.full100 > img:visible').css({
					'height':windowH,
					'width':imgW * (windowH/imgH) +'px',
					'margin-left':'-'+(imgW * (windowH/imgH))/2+'px', 
					'margin-top':0,
					'top':0
				});
			} else {
				$('.full100 > img:visible').css({
					'width':windowW,
					'height':imgH * (windowW/imgW) +'px',
					'margin-top':'-'+(imgH * (windowW/imgW))/2+'px', 
					'margin-left':0,
					'left':0
				});
			}
		}

		$('.full > img:visible').css({
			'margin-left':'-'+$('.full > img:visible').width()/2+'px', 
			'margin-top':'-'+$('.full > img:visible').height()/2+'px'
		});
		$('.full > img:visible, .full100 > img:visible')
			.animate({'opacity': 0},500)
			.animate({'opacity': 1}, 1000)
			.animate({'opacity': 1}, 2000)
			.animate({'opacity': 0}, 1000,
				function(){
					$('#overlay').animate({'height': 0}, 10);
				});
		$('#nav, #logo')
			.css('opacity', 0)
			.animate({'opacity': 0}, 1000)
			.animate({'opacity': 1}, 1000,
				function() {
				if ($.browser.msie)
					this.style.removeAttribute('filter');
				}
			);
		$('#content_box, #dock, #content_side')
			.css('opacity', 0)
			.animate({'opacity': 0}, 1500)
			.animate({'opacity': 1}, 1000,
				function() {
				if ($.browser.msie)
					this.style.removeAttribute('filter');
				}
			);
	}); 
// paginaopbouw
		$('#content_box').find('img').each(
			function(){
				var marginLeft = -(($(this).width() / 2)-38);
				$(this).css('margin-left', marginLeft);
			}
		)
// dock
	// init
		var bgColor = $('a.dock-item').css("background");
		$('#content_box img.big').css('display', 'none');
		$('#content_box img.big:first').fadeIn(1000).addClass('active');
		$('.dock-container img:first').addClass('active').css('opacity', .5).parent('a').css('background','none');
		$('#content_side #blockimages div').css('display', 'none');
		$('#content_side #blockimages div:first').css('display', 'block');
	// thumb bottom-align
		$('.dock-item img').each(
			function(){
				var width = $(this).width();
				var height = $(this).height();
 				$(this).parent('a.dock-item').css({'height':height, 'width':width, 'margin-top':85-$(this).height()+'px'});
				
			}
		);
	// thumb hover
		$('a.dock-item').hover(
			function(){
				$(this).find('img:not(.active)').stop().animate({"opacity": 0}, 300);
			}, function(){
				$(this).find('img:not(.active)').stop().animate({"opacity": 1}, 300);
		});
	// thumbclick
		$('a.dock-item').click(
			function(){
				var thisRel = $(this).attr('rel');
				$('.dock-item').css('background',bgColor).find('img').stop().css('opacity',1);
				$('.dock-item img.active').removeClass('active').css('opacity', 1);
				$(this).css('background','none').find('img').addClass('active').css('opacity', .5);
				$('#content_box .big').css('display', 'none');
				$('#content_box').find('img.'+thisRel+'').fadeIn(1000);
				$('#content_side #blockimages div:not(.'+thisRel+')').css('display', 'none');
				$('#content_side #blockimages div.'+thisRel).css('display', 'block');

				return false;
			}
		);
	// vergroting click
	//	$('#content_box img.big:not(:last)').click(
	//		function(){
	//			var thisRel = $(this).attr('rel');
	//			$(this).css('display', 'none');
	//			$(this).next('img').fadeIn(1000);
	//			$('.dock-item').css('background',bgColor);
	//			$('.dock-container').find('a.'+thisRel+' img').removeClass('active').css('opacity', 1)
	//			$('.dock-container').find('a.'+thisRel+'').next('.dock-item').find('img').addClass('active').css({'opacity': .5,'background':'none'});
	//			$('#content_side #blockimages div').css('display', 'none');
	//			$('#content_side #blockimages div.'+thisRel).next('div').css('display', 'block');
//
	//			return false;
	//		}
	//	);
	// is er maar afbeelding-> dock niet tonen
		if($('.dock-container > a').size() == 1){
			$('.dock-container').css({'display':'none'});
		}
});
