// 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); }
				}
			});
		});
	};

$(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();});

// image hover
		$('a img').hover(function(){
			$(this).stop().animate({'opacity':.7}, 100);
		}, function(){
			$(this).stop().animate({'opacity':1}, 400);
		})

// image hover
		$('#taal a img').css('opacity',.6);
		$('#taal a img').hover(function(){
			$(this).stop().animate({'opacity':1}, 100);
		}, function(){
			$(this).stop().animate({'opacity':.6}, 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
		$('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;
		});

// tooltip
		$('a').tooltip({opacity: 0.95, track: true, delay: 0, showURL: false, fade: 100});
		$('img').tooltip({opacity: 0.95, track: true, delay: 0, showURL: false, fade: 100});

// fancybox
		$('a.fancy').fancybox({
			'titleShow' : false
		});

// fancybox iframe
		$(".iframe").fancybox({
				'transitionIn'	: 'fade',
				'transitionOut'	: 'fade',
				'autoScale'     : false,
				'width'		: 660	,
				'height'	: 450,
				'type'		: 'iframe',
				'scrolling'   	: 'no',
				'padding'   	: 0,
				'margin'   	: 0
		});

// docenttip
		$(".docent").docenttip({ opacity: 0.9, effect: 'slide', position: "bottom center", delay: 0, offset: [-25, 130], relative: 'true'});

// twitterfeed

//		$(".twitterfeed").twit("codarts", {
//			limit: 1,
//			label: 'twitter',
//			title: ''
//		});

// facebook feed
		$.ajax({
			url: 'https://graph.facebook.com/159138204118705/feed?access_token=246985878662243|bea1a0bed1bfe6d04d152d44.1-1412556297|vmfZiME2zZhhWF2qjVlFYk6Qmms&limit=2&callback=?',
			dataType: 'json',
			success: displayFacebookFeed
		});
		var clicks = 2;
		$('.facebookMore').live('click', function(){
			var fbUlH = parseInt($('.facebookfeed').children('ul').height());
			$('.facebookfeed').children('ul').css('min-height', fbUlH);
			$('.facebookfeed').find('li').addClass('old').animate({'opacity':0}, 350, function(){ $('.facebookfeed').find('li.old').remove() })
			$('.facebookfeed').find('p.facebookNavi').animate({'opacity':0}, 150, function(){
				$.ajax({
					url: 'https://graph.facebook.com/159138204118705/feed?access_token=246985878662243|bea1a0bed1bfe6d04d152d44.1-1412556297|vmfZiME2zZhhWF2qjVlFYk6Qmms&limit='+clicks+'&callback=?',
					dataType: 'json',
					success: displayFacebookFeed
				});
				
			
				$('.facebookfeed').find('p.facebookNavi').animate({'opacity':1}, 150, function(){
					if ( $.browser.msie ){
						this.style.removeAttribute('filter');
					}
				});
			});
			clicks = clicks+1;
			return false;
		});
		$(".facebookfeed ul").after('<p class="facebookNavi"><a class="facebookMore" href="#">meer</a></p>');

// cycle all
		$('.slides').cycle({
        		fx:  'fade',
        		timeout:  1000,
        		speed:  1000,
			pause:  true,
			next:  '.slides',
 			height: 295
		});

		$('#specialslide').cycle({
 			fx:  'fade',
 			timeout:  5000,
 			speed:  1500,
 			pause:  true
		});

		$('#ticker').cycle({
 			fx:  'fade',
 			timeout:  3000,
 			speed:  1500,
 			pause:  true
		});

// start toggle
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	if(!isiPad){

		$('.backgroundlayer, .contentlayer').css({'opacity':1, 'display':'none'});
		$('#rc, #rd, #rca').live('mouseenter mouseleave', function(alink){
			if ( alink.type == "mouseenter" ) {
				$(this).find('.backgroundlayer').css('display','block').stop().animate({'opacity':.85}, 100);
				$(this).find('.contentlayer').stop().css('display','block').animate({'opacity':1}, 10, function(){
					if (jQuery.browser.msie)  
						this.style.removeAttribute('filter'); 
				});
			}
			if ( alink.type == "mouseleave" ) {
				$(this).find('.backgroundlayer').stop().animate({'opacity':0}, 400, function(){
					$(this).css('display','none');
				});
				$(this).find('.contentlayer').stop().animate({'opacity':0}, 300, function(){
					$(this).css('display','none');
					if (jQuery.browser.msie)  
						this.style.removeAttribute('filter'); 
				});
			}

		});
	}else{

		$('.backgroundlayer, .contentlayer').css({'opacity':0, 'display':'none'});
		$('.tile').css({'display':'none'});
		$('.imagelayer').live('touchstart', function(alink){
			$(this).parent('div').children('.tile').css('display','block').children('.backgroundlayer').css('display','block').stop().animate({'opacity':.85}, 100);
			$(this).parent('div').find('.contentlayer').delay(500).css('display','block').animate({'opacity':1}, 100, function(){
				$(this).removeAttr('filter'); 
			});
			alink.preventDefault();

		});
		$('.contentlayer li a').click(function(){
			return true;
		});
		$('.backgroundlayer').live('touchstart', function(alink){
			$(this).stop().animate({'opacity':0}, 100, function(){
				$(this).css('display','none');
			});
			$(this).parent('.tile').children('.contentlayer').stop().animate({'opacity':0}, 100, function(){
				$(this).css('display','none');
			$(this).parent('.tile').css('display','none');
			});
			alink.preventDefault();
		});
	}

});
