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

// vertical align
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};

$(function(){
		$('.scroll-pane').jScrollPane({dragMaxHeight:20, scrollbarMargin:0, scrollbarWidth:8});
});


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

	$(document).ready(function(){

// png voor IE
		$('body').pngFix();
		
// align image to bottom
			$('#archief img').each(function(){
				var imgAh = $(this).height();
				var imgAw = $(this).width();
				$(this).parent('div').css({'height':imgAh, 'width':imgAw,'margin-top': 220-$(this).height()});
			});

// slider
			$('.slider').cycle({ fx:'fade', speed:300, timeout:0, pause:1, next:'.slider img', pager:'#imagepager', cleartype:1, fit:1, random:0 });
		
// arrow
//			var wH = $(window).height();
//			var dH = $('#mainwrap').height();
//			if (wH < dH){
//				if($('#left').hasClass('breed')){
//					$('#content').addClass("arrowbreed");
//				} else {
//					$('#content').addClass("arrow");
//				}
// 			}

// arrowstart
			var wH = $(window).height();
			var dH = $('#mainwrap').height();
			if (wH < dH){$('.start').addClass("arrow");}
			
// toggleval
		$('#zoek,#we_subscribe_email__').toggleVal();
		
// validate
		$('#easyform').validate();		

// focus op input
		$('input[type="text"], textarea').addClass("idleField");
		$('input[type="text"], textarea').focus(function() {
			$(this).removeClass("idleField").addClass("focusField");
		});
		$('input[type="text"], textarea').blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
		});
		$('.locaties input[type="text"], .locaties textarea').addClass("locField");
		$('.locaties input[type="text"], .locaties textarea').focus(function() {
			$(this).removeClass("locField").addClass("locFocField");
		});
		$('.locaties input[type="text"], .locaties textarea').blur(function() {
			$(this).removeClass("locFocField").addClass("locField");
		});

// form als t-shirt
		$('label.hidden').hide();

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

// printbutton
		$('#printwindow').click(function(){
			window.print();
			return false;
		});
// functies FAQ
		$('.antwoord').css({'display':'none'});
		$('h4.vraag').css({'cursor':'pointer'});
		$('h4.vraag').click(function(){
			$(this).toggleClass('open').next('.antwoord').slideToggle(200);
			return false;
		});
// lees meer tjap
		$('.meer_lezen').hide();
		$('.lees_meer').click(function(){
			$(this).parent('p').hide();
			$(this).parent('p').next('.meer_lezen').slideToggle(300);
		});

// mobile...
           var agent=navigator.userAgent.toLowerCase();
           var is_iphone = ((agent.indexOf('iphone')!=-1));
           if (is_iphone) {}
           else {

// 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();
		
// accordeon
		$('div.accordeon h2').next('div').not('.open').prev('h2').addClass('even');
		$('div.accordeon > div:not(.open)').css({'display':'none'});
		$('div.accordeon h2').live('click', function(){
			$(this).toggleClass('even');
			$(this).next('div').slideToggle(200);
		});

// tooltip
		//$('tr').tooltip({opacity: 0.5, track: true, delay: 0, showURL: false, fade: 100, extraClass: "table"});
		$('li').tooltip({opacity: 0.5, track: true, delay: 0, showURL: false, fade: 100, extraClass: "list"});
		$('img').tooltip({opacity: 0.5, track: true, delay: 0, showURL: false, fade: 100});
                $('.form_submit').tooltip({opacity: 0.5, track: true, delay: 0, showURL: false, fade: 100});
		
// a img hover
		$('#startlogo a').hover(
			function(){
				$(this).stop().animate({"opacity": 0}, 150);
			}, function(){
				$(this).stop().animate({"opacity": 1}, 300);
		});
		
		
// a img hover
		$('a img, #shows li img, #events li img, #archief li img, #nieuwsbrief .form_submit').hover(
			function(){
				$(this).stop().animate({"opacity": .6}, 150);
			}, function(){
				$(this).stop().animate({"opacity": 1}, 300);
		});

// strong

$('p span').each(function(){
//alert($(this).attr('style'));
	if($(this).attr('style') == 'font-weight: bold;'){
		$(this).wrapInner('<strong />');
		$(this).attr('style', '');
	}
});
$('p span').each(function(){
//alert($(this).attr('style'));
	if($(this).attr('style') == 'font-style: italic;'){
		$(this).wrapInner('<em />');
		$(this).attr('style', '');
	}
});

// news
		
//		$('#agendalink').click(function() {
//			if ($(this).hasClass('small') ) {
//				$('#nieuws').fadeOut("fast");
//			} else {
//				$('#agenda').fadeIn("fast");
//				$('#nieuws').fadeOut("fast");
//				$(this).addClass('small');
//				$('#nieuwslink').removeClass('small');
//			}
//		});
		
//		$('#nieuwslink').click(function() {
//			if ($(this).hasClass('small') ) {
//				$('ul#agenda').fadeOut("fast");
//			} else {
//				$('#nieuws').fadeIn("fast");
//				$('#agenda').fadeOut("fast");
//				$(this).addClass('small');
//				$('#agendalink').removeClass('small');
//			}
			
//		});

		
// fancybox
//		$('a.fancy').fancybox({
//			'titleShow'     : false,
//			'transitionIn'	: 'elastic',
//			'transitionOut'	: 'elastic',
//			'easingIn'      : 'easeOutBack',
//			'easingOut'     : 'easeInBack',
//			'overlayColor'  : '#333',
//			'overlayOpacity': '0.7'
//		});
//
//                $(".iframe").fancybox({
//                        'width' : '60%',
//                        'height' : '60%',
//                        'autoScale' : false,
//                        'transitionIn' : 'none',
//                        'transitionOut' : 'none',
//                        'type' : 'iframe'
//                 });		

	});

// na browser resize, afbeelding ook resizen
	$(window).bind("resize", function(){
		$('.bg-image-wrap').resizenow(); 
		// arrow
		var wH = $(window).height();
		var dH = $('#mainwrap').height();
		if (wH < dH){
			if($('#left').hasClass('breed')){
				$('#content').addClass("arrowbreed");
			} else {
				$('#content').addClass("arrow");
			}
		}
		if (wH > dH){
			if($('#left').hasClass('breed')){
				$('#content').removeClass("arrowbreed");
			} else {
				$('#content').removeClass("arrow");
			}
		}
	});
	
