Cufon.replace('a.nav')('#sidemenu h2')('a.subnav', {hover: true});

$(document).ready(function(){
	setSlider();
	
	$('a.nav').hover(
		function(){
			$width = $(this).width() +10;
			$left  = $(this).position().left -5 - 230;
			if($left < 0){
				$left = 0;
				$width = $width -5;
			}
			$('#slideblock').stop(true).animate({
				left : $left,
				width: $width
			},500);
		},
		function(){
			$width = $('a.hoofdNavActive').width() +10;
			$left  = $('a.hoofdNavActive').position().left -5 - 230;
			if($left < 0){
				$left = 0;
				$width = $width -5;
			}
			$('#slideblock').delay(500).stop(true).animate({
				left : $left,
				width: $width
			},500);
		}
	);
	
	 $('#zoekform input[type="text"]').focus(function(){
     if($(this).val() == 'zoekterm'){
       $(this).val('');
     }
   });
	 $('#zoekform input[type="text"]').blur(function(){
     if($(this).val().trim() == ''){
       $(this).val('zoekterm');
     }
   });
	
	$('#zoekform').find('form').submit(function(e){
	  location.href="/zoek/"+$('#zoekform input[type="text"]').val();
	  e.preventDefault();
	})
	
	var videoplayeroption = {
		type: 'iframe',
		padding: 0,
		scrolling: 'no'
	};
	 
	$('#videotxt a').fancybox(videoplayeroption);
	$('#videoimg a').fancybox(videoplayeroption);
	$('a.videobox').fancybox(videoplayeroption);

	jQuery('ul#twitter_update_list').jcarousel({
        vertical: true,
        auto: 7,
        scroll: 1
    });	
	$('div.textslider').tekstslider();
	
	  /* Fotoalbums */  
  if($('.fotoalbum-detail').length > 0) {
    var w = $('.fotoalbum-detail .thumbs .mask .holder .thumb').length * 85;
    $('.fotoalbum-detail .thumbs .left').click(function() {
      if($('.fotoalbum-detail .thumbs .mask .holder').css('left').replace('px', '') < 0) {
        $('.fotoalbum-detail .thumbs .mask .holder').animate({left:'+=108px'}, 400);
      }
    });
    $('.fotoalbum-detail .thumbs .right').click(function() {
      if(Number($('.fotoalbum-detail .thumbs .mask .holder').css('left').replace('px', '')) > 427 - w) {
        $('.fotoalbum-detail .thumbs .mask .holder').animate({left:'-=108px'}, 400);
      }
    });
    $('.fotoalbum-detail .thumbs .mask .holder .thumb img').click(function() {
      var newSrc = $(this).attr('src').replace('_small', '_normal');
      $('.fotoalbum-detail .groot img').fadeOut(200, function() {
        $(this).attr('src', newSrc);
      });
    });
    $('.fotoalbum-detail .groot img').load(function(){setTimeout(imgLoaded, 200);});
    setTimeout(imgLoaded, 500);
  }
	
});



$(window).load(function(){
	setSlider();
});

$(window).resize(function(){
	setSlider();
});


function imgLoaded() {
  if($('.fotoalbum-detail .groot img').height() != $('.fotoalbum-detail .groot').height()) {
		$('.fotoalbum-detail .groot ').animate({height:$('.fotoalbum-detail .groot img').height()}, {duration:400, complete:function() {
      $('.fotoalbum-detail .groot img').fadeIn(400);
    }});
  } else {
    $('.fotoalbum-detail .groot img').fadeIn(400);
  }
}

function setSlider(){
	$width 	= $(window).width() - 231 - $('#main').offset().left;
	$left 	= $('#menu').offset().left + 230 ;
	//console.log('Window: '+$width);
	$('#slider').css({
		width: $width,
		left: $left
	});
	//console.log('Slider: '+$('#slider').width());
			$width = $('a.hoofdNavActive').width() +10;
			$left  = $('a.hoofdNavActive').position().left -5 - 230;
			if($left < 0){
				$left = 0;
				$width = $width -5;
			}
			$('#slideblock').css({
				left : $left,
				width: $width
			});
	
}

