function empty_recursive(el){ $(el).attr('busy', 'y'); $(el).val($(el).val().substring(0, $(el).val().length-1)); if($(el).val() != ''){ setTimeout(function(){ empty_recursive($(el)); }, 2); } else{ $(el).change(); $(el).attr('busy', 'n'); } }
function refill_recursive(el){ $(el).attr('busy', 'y'); $(el).val($(el).attr('defVal').substring(0, $(el).val().length+1)); if($(el).val() != $(el).attr('defVal')){ setTimeout(function(){ refill_recursive($(el)); }, 2); } else{ $(el).change(); $(el).attr('busy', 'n'); } }		

$(function(){

	$('input[type=text], input[type=password], textarea').not('.excl').each(function(){ var c = $(this); if($(this).val().length > 0){ if(!$(this).attr('defVal') || $(this).attr('defVal').length <= 0) $(this).attr('defVal', $(this).val()); if($(this).parents('form').find('input[type=submit]').click(function(){ if(c.val() == c.attr('defVal')) c.val(''); })); $(this).focus(function(){ if($(this).val() == $(this).attr('defVal')){ empty_recursive($(this)); } }); $(this).blur(function(){ if($(this).val() == ''){ refill_recursive($(this)); } }); } });
	$('input[type=text], input[type=password], textarea').not('.excl').blur();
	$('form').submit(function(){
		$(this).find('[defVal]').each(function(){
			if($(this).val() == $(this).attr('defVal')){
				$(this).val('');
			}
		});
	});
});

function repCufon(){
	Cufon.replace('h1', { fontFamily: "ITC Avant Garde Gothic Std Demi Condensed" });
	Cufon.replace('h2:not(.nocufon)', { fontFamily: "ITC Avant Garde Gothic Std Demi Condensed" });
	Cufon.replace('h3', { fontFamily: "ITC Avant Garde Gothic Std Demi Condensed" });
	Cufon.replace('div.main.container div.top ul.menu li a', { fontFamily: "ITC Avant Garde Gothic Std Book", hover: true });
}
repCufon();
$(document).ready(function(){
	Cufon.replace('h1', { fontFamily: "ITC Avant Garde Gothic Std Demi Condensed" });
	Cufon.replace('h2:not(.nocufon)', { fontFamily: "ITC Avant Garde Gothic Std Demi Condensed" });
	Cufon.replace('h3', { fontFamily: "ITC Avant Garde Gothic Std Demi Condensed" });
	Cufon.replace('div.main.container div.top ul.menu li a', { fontFamily: "ITC Avant Garde Gothic Std Book", hover: true });

});

function shadowHeight(){
	//$('div.shadow-container').css('height', ( $("#footer2").offset().top+$('#footer2').height()+40 )+'px');
}

function slideAnim(interval, animtime){
	var cur_anim_index = 0;
	var bullet = '<div class="button bulleti">&nbsp;</div>';
	var timer;
	var entryWidth = $('#slide-anim-container #slide-anim-inner-container .slide-anim-entry:eq(0)').outerWidth();
	var max_index = parseInt($('#slide-anim-container #slide-anim-inner-container .slide-anim-entry').size()-1);

	function resetTimer(){
		timer = clearInterval(timer);
		timer = setInterval(loop, interval+animtime);
	}
	
	$('#slide-anim-container #slide-anim-inner-container .slide-anim-entry').each(function(){
		$(bullet).clone().appendTo('#slide-anim-container #slide-anim-footer #slide-anim-bullets').click(function(){
			setCurrent($('#slide-anim-container #slide-anim-footer #slide-anim-bullets .button').index(this)-1);
			loop();
			resetTimer();
		});
	});
	$('#slide-anim-container #slide-anim-inner-container' ).css('width', ((max_index+1)*entryWidth)+'px');
	$('#slide-anim-container #slide-anim-footer #slide-anim-bullets .bulleti').eq(0).removeClass('bulleti').addClass('bulleta');
	

	
	function getNext(){
		if(cur_anim_index == max_index) return 0;
		else return parseInt(cur_anim_index+1);
	}
	function setCurrent(index){
		cur_anim_index = parseInt(index);
	}
	function getCurrent(){
		return parseInt(cur_anim_index);
	}
	function loop(){
		var index = getNext();
		$('#slide-anim-container #slide-anim-footer #slide-anim-bullets .bulleta').removeClass('bulleta').addClass('bulleti');
		$('#slide-anim-container #slide-anim-footer #slide-anim-bullets .bulleti').eq(index).removeClass('bulleti').addClass('bulleta');
		$('#slide-anim-container #slide-anim-inner-container').stop().animate({ left:((index*entryWidth)*-1)+'px' }, animtime, function(){  });
		setCurrent(index);
		
	}
	
	$('#slide-anim-container #slide-anim-footer #slide-anim-nav .pn').click(function(){
		if($(this).hasClass('next')){
			loop();
			resetTimer();
		}
		else if($(this).hasClass('prev')){
			var index = getCurrent();
			if(index == 0) setCurrent(max_index-1);
			else if(index == 1) setCurrent(max_index);
			else setCurrent(index-2);
			loop();
			resetTimer();
		}
	});
	if(!(max_index > 0)) $('#slide-anim-container #slide-anim-footer #slide-anim-nav .pn').hide();
	resetTimer();
	
}
if(/chrome/.test( navigator.userAgent.toLowerCase() )){
	$(window).load(function(){
		var maxHeight = 0;
		$('div#slide-anim-container div.slide-anim-entry').show();
		$('#slide-anim-container:not(.homesl) #slide-anim-inner-container .slide-anim-entry-content').each(function(){
			var h = $(this).outerHeight();
			if(h>maxHeight) maxHeight = h;
		});
				if(maxHeight > 0) $('#slide-anim-container').height(maxHeight+50);	
				if(maxHeight > 0) $('#slide-anim-inner-container').height(maxHeight+30);	
	});
}
else{

	$(document).ready(function(){
		var maxHeight = 0;
		$('div#slide-anim-container div.slide-anim-entry').show();
		$('#slide-anim-container:not(.homesl) #slide-anim-inner-container .slide-anim-entry-content').each(function(){
			var h = $(this).outerHeight();
			if(h>maxHeight) maxHeight = h;
		});
				if(maxHeight > 0) $('#slide-anim-container').height(maxHeight+50);	
				if(maxHeight > 0) $('#slide-anim-inner-container').height(maxHeight+30);	
	
	});
}
$(document).ready(function(){

	slideAnim(8000, 1000);
	$('.button').each(function(){
		var a = $(this).find('a');
		if($(a).size() > 0){
			$(this).css('cursor', 'pointer');
		}	
	});
	$('.button').click(function(){
		var a = $(this).find('a');
		if($(a).size() > 0){
			window.location = base+$(a).attr('href');
		}
	});
	

	repCufon();

	
	$(window).resize(function(){
		shadowHeight();
	});
	//shadowHeight();
	
	$("a.fancylink").fancyZoom({scaleImg: true, closeOnclick: true});
	/*$('.publink').click(function(){
		var w = $('.publicaties').outerWidth();
		var ww = $(window).width();
		var h = $('.publicaties').height();
		var h2 = $('.publicaties').outerHeight();
		var wh = $(window).height();
		if(h > (wh*0.67)){
			h = wh*0.67;
		}
		
		var lpos = (ww/2)-(w/2);
		var tpos = (wh/2)-(h2/2);
		$('<div class="blackout">&nbsp;</div>').appendTo('body').fadeIn(1000);
		$('.publicaties').css({height: h+'px', left: lpos+'px', top: tpos+'px'}).appendTo('body').fadeIn(1000, function(){
			$('<img style="cursor:pointer;display:block;width:35px;height:34px;" class="cross" src="./images/close.png" />').appendTo('body').css({position: 'fixed', left: ((lpos+w)-22)+'px', top: (tpos-10)+'px'}).click(function(){

				$('.cross').remove();
				$('.blackout').fadeOut(1000, function(){ $(this).remove(); });
				$('.publicaties').fadeOut(1000);		
			
			});
		});
	});*/
	
	
	
	
	
	$('.nieuwsbrief').submit(function(){
		var doSubmit = true;
		var errorText = '';
		if($('input[type=radio][name=corporatie_zorg]:checked', this).length <= 0){
			var doSubmit = false;
			errorText += 'Maak een keuze uit Corporatie en Zorg<br />';
		}
		if(!$('#email', this).val().match(/^(.+)@(.+)\.(.+)$/)){
			var doSubmit = false;
			errorText += 'Vul een geldig email adres in<br />';
		}
		
		doSubmit?$('p.error', this).hide().html(''):$('p.error', this).show().html(errorText);
		return doSubmit;
	});
	
	
	
	
	
	
	
	
	
	
	
	
});

var listAccordion = function(){
	var c = this;
	var list = $('.listAccordion');
	var upTime = 800;
	var downTime = 800;
	this.init = function(){
		list.find('ul').hide();	
		list.find('>li').click(function(){
			$(list).find('>li').removeClass('active');
			list.find('ul').slideUp(upTime);
			$(this).find('ul').slideDown(downTime);
			$(this).addClass('active');
		});
		list.find('>li ul').click(function(e){ e.stopPropagation(); });
		list.find('.active ul').show();
	}
	c.init();
}
$(function(){
	new listAccordion();
});
