
Cufon.set('fontFamily', 'addled').replace('h1')('h2.sidebar-title')('a.showmorelink')('.home_blok h2');
Cufon.set('fontFamily', 'GOSI2').replace
('a.nav', {hover: true})
('a.subnav', {hover: true})
('a.subnav2', {hover: true})
('.bieb', {hover: true})
('#login h4')('#logout h4')('.block_bookmark h3')('.block_zoeken h4')('.block_nieuwsbrief h4')('#right_block h4')('.block_zoekcursus h4')('#slide_right a');

$(document).ready(function(){
	
    $("a[ href ^= '#' ]").each(function(){
		var href = window.location + $(this).attr('href').replace('/#.*/i','');
		$(this).attr('href',href);
	});
	
	$('input.zoek').focus(function(){
		if($(this).val()=='zoekterm'){
			$(this).val('');
		}
	});
	
	$('a.fancybox').fancybox({
	  height: 300,
	  width: 300,
	  type: 'iframe'
	});
	
	$('a.showmorelink').toggle(
	function(){
		$('div.showmore').slideDown();		
	},
	function(){
		$('div.showmore').slideUp();		
	}
	);
	
	$('a.showmoreCursus').toggle(
	function(){
		$(this).addClass('biebActive');	
		$('div.showmore').slideDown();
		
	},
	function(){
		$(this).removeClass('biebActive');	
		$('div.showmore').slideUp();		
	}
	);
	
	setBackground();
	
	$('#addbookmark').click(function(){
		$('#bookmarkform').toggle();
		return false;
	});	
	
	$('#bookmarks').change(function(){
		window.open($(this).val());
	});
	
	$('#openclose').click(function(){
		var height = $('#newsslide').height();
		//alert(height);
		switch(height) {
			case 0:
				$('#left_arrow').attr('src', 'images/arrow_dark_left.png')			
				$('#newsslide').animate({
					height: 125,
					marginBottom: 0
				}, 300);
			break;
			default: 
				$('#newsslide').animate({
					height: 0,
					marginBottom: 16
				}, 300);
				$('#left_arrow').attr('src', 'images/arrow_dark_right.png')
		}
	})
	
	$("#twitter").gosiTwitter({userName: "Denieuwstepabo", numTweets: 3, loaderText: "Loading tweets..."});
	
	if($('#homecontent').length > 0){
		$('#openclose').trigger('click');
	}
	
	if($('#homesplash').length > 0){
		$('#openclose').trigger('click');
	}
	
	$('div.home_blok').hover(function(){
		$(this).find('img').stop(true).animate({
				marginLeft: -50,
				opacity: 1
		}, 200)
	},function(){
		$(this).find('img').stop(true).animate({
			marginLeft: 0,
			opacity: 0.9
		}, 200)
	});
	
	$('#newslist ul').cycle({
		fx: 'scrollHorz',
		timeout: 6000,
		prev: '#left_arrow',
		next: '#right_arrow',
		cleartypeNoBg:   true
	});
	var lastItem = false;
	$('#slide_left div').cycle({
		fx: 'scrollVert',
		timeout: 5000,
		pager:  '#slide_pager', 
	    pagerAnchorBuilder: function(idx, slide) { 
	        // return selector string for existing anchor 
	        return '#slide_pager a:eq(' + idx + ')'; 
	    } ,
		cleartypeNoBg:   true,
		pagerClick: function(zeroBasedSlideIndex, slideElement){
			href = $('#slide_pager a:eq(' + zeroBasedSlideIndex + ')').attr('href');
			target = $('#slide_pager a:eq(' + zeroBasedSlideIndex + ')').attr('target');
			if(target == '_blank'){
				window.open(href);
			}else{
				location.href = href;
			}
		},
		before: function(currSlideElement, nextSlideElement, options, forwardFlag){
					if(lastItem){
						$('#slide_pager').animate({
							top: 0
						}, 500);
						lastItem = false;
					}
				},
		after: function(currSlideElement, nextSlideElement, options, forwardFlag){
				if($('#slide_pager a.activeSlide').index() == ($('#slide_pager a').length - 1)){
						lastItem = true;
				}
				if($('#slide_pager a.activeSlide').length > 0 && $('#slide_pager a').length > 2){
					if(($('#slide_pager a.activeSlide').position().top + $('#slide_pager').position().top) == 95 && !lastItem){
						$('#slide_pager').animate({
							top: $('#slide_pager').position().top - 95
						}, 500);
					}
					if(($('#slide_pager a.activeSlide').position().top == 0 && $('#slide_pager').position().top < 0)){
						$('#slide_pager').animate({
							top: 0
						}, 500);
					}
					
				}
				
		}
	});
	
	if($('#slide_pager').find('a').length == 1){
		$('#slide_pager').find('a').addClass('activeSlide')
	}
	
	$('#uitgelicht div.uitgelichtslide').cycle({
		fx: 'fade',
		timeout: 6000,
		cleartypeNoBg:   true
	});
	
	$('#themaselect').gosiSelect();
	
	if($('#playerLite').length > 0){
		var movie = $('#playerLite').attr('rel');
		//alert(movie);
		loadMovie(movie);
	}
	
	
	
	/*
	$("a.nav").mouseover(function(){
		//juist plaatsten van het submenu
		clearTimeout(timer);
		$('ul.dropdownnav').css("display","none");
		positie = $("li.collectie").position();
		$("#collectie_submenu").css("display","block");
		$("#collectie_submenu").css("left",positie.left+"px");
		$("li.collectie>a").addClass("t_actief");
	}).mouseout(function(){
		timer=setTimeout(function(){
			$("#collectie_submenu").css("display","none");
			$("li.collectie>a").removeClass("t_actief");
		}, 250);
	}); */
	
	var subHomeTo;actief=0;
	$('.home_blok').mouseover(function(){	
		if($(this).hasClass("pabo")){
			clearTimeout(subHomeTo);
			submenu = $(this).children(".submenu_home");
			submenu.slideDown(400);
		}
	}).mouseout(function(){
		submenu = $(this).children(".submenu_home");
		if($(this).hasClass("pabo")){
			//Bij het weggaan van een knop de timeout starten			
			subHomeTo = setTimeout(function(){
				submenu.slideUp(400);
			},600);
		}
	});
	
	var subTo;var laatste_actief="";laatste_submenu_actief="";
	$('#hoofdnav>li.nav').mouseover(function(){	
		if($($ul).length>0){
			clearTimeout(subTo);
			$ul = $(this).attr('rel');
			//Alleen omhoog laten gaan als er een andere knop wordt gemouseoverd.
			if(laatste_actief!=$(this).attr('rel')){
				$('ul.dropdownnav').stop(true,true).css("display","none");
				$($ul).css({marginLeft:($($($ul).attr('rel')).position().left - 5)}); 
				$($ul).slideDown(400);			
			}	
			//Huidige knop actief maken
			laatste_actief=$(this).attr('rel');		
		}
	}).mouseout(function(){
		$ul = $(this).attr('rel');
		if($($ul).length>0){
			//Bij het weggaan van een knop de timeout starten
			subTo = setTimeout(function(){
				$($ul).slideUp(400);
			},800);
		}
	});
	
	$('ul.dropdownnav').mouseover(function(){
		clearTimeout(subTo);
	}).mouseout(function(){
		subTo = setTimeout(function(){
			$('ul.dropdownnav').slideUp(400);
		},800);		
	});
		
});

$(window).load(function(){
	setBackground();
});

$(window).resize(function(){
	setBackground();
});

function loadMovie(movie){
	var flashvars = {
		vidWidth: "510",
		vidHeight: "280",
		vidPath: movie,
		thumbPath: "",
		autoPlay: "false",
		autoLoop: "false",
		watermark: "hide",
		showControls: "true",
		vidAspectRatio: "fit"
		}
		var params = {
		menu: "true",
		allowfullscreen: "true",
		allowscriptaccess: "always"
		};
		var attributes = {
		id: "playerLite",
		name: "playerLite"
		};
	swfobject.embedSWF("playerlite.swf", "playerlite", flashvars.vidWidth, flashvars.vidHeight, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function setBackground(){
	var windowheight 	= $(window).height();
	var windowwidth 	= $(window).width();
	var documentheight 	= $(document).height();
	var contentheight	= $('#main').height();
	
	if(contentheight > windowheight){
		toHeight = contentheight;
	}else{
		toHeight = windowheight;
	}
	
	$('#backgroundimage').css({
		height: toHeight ,
		width: windowwidth
	});
	
	$('#backgroundimage').find('img').css({
		height: toHeight,
		width: 'auto',
		marginLeft: -($(this).width()-($(this).width()%2))/2
	});	
	if( $('#backgroundimage').find('img').width() < windowwidth){
		$('#backgroundimage').find('img').css({
			width: windowwidth,
			height: 'auto',
			marginLeft: -($(this).width()-($(this).width()%2))/2
		});	
	}
}

