var loader = 0;
var kompasloaded = false;
function showKompas(swf){
	var swf = swf;
	if(!swf) swf = 'swf/kompaslarge.swf'
	if((swf == 'swf/kompaslarge.swf' && taal == 'NL') || swf != 'swf/kompaslarge.swf' ){
		$("#kompasover2").css('width',$(window).width()+'px')
		$("#kompasover").css('width','0%');
		//if(!kompasloaded){
			$('#flashkompasload').flash(
				{ src: swf, wmode: 'transparent', height: '100%', width: '100%',  id:'flashkompaslarge', name:'flashkompaslarge', swliveconnect:'true'},
				{ version: 8 }
			);
			kompasloaded = true;
		//}
		
		$("#kompasover").show().animate({"width":'100%'},1000,function(){
			$("#kompasover2").css('width','100%')
		});			
	}
}

function hideKompas(){
	
	$("#kompasover2").css('width',($(window).width())+'px')
	$("#kompasover").animate({"width":'0%'},1000,false, function(){
		$("#flashkompas").html('<div id="flashkompasload"></div>');
	});		
	//$("#flashkompas").html('<div id="flashkompasload"></div>');
	//$("#kompasover .bg").hide("slow");						
	//$("#kompasover #flashkompas").hide("slow",function(){ $("#kompasover").hide(); });				
}


function showslogan(id){
	if($(".slogan.active").length > 0){
		$(".slogan.active").removeClass('active').find('h1').fadeTo(500,0, function(){
			showslogan2(id)															
		});
	}else{
		showslogan2(id);	
	}
}
function showslogan2(id){
	$("#"+id).addClass('active');
	$("#"+id).stop(true,true).css({'left':'0px'}).animate({'left':'-=100px'},2500,'easeOutCubic').find('h1').fadeTo(2400,1);																			

}


$(document).ready(function(){	
   initLinks();
	$("a[keyword]").live("click",function(){
		if($(this).hasClass('projecttab')){
			clickProjectTab($(this).attr('keyword'));
		}else{
			$.historyLoad($(this).attr('keyword'));
		}
		$('html, body').animate({scrollTop: '0'}, 500);	
		return false;
	});
	$.historyInit(pageload);
	
	//$("#logo").click(function(){startsite();return false;});
	
	// FLASH ELEMENTEN	
	$('#flashcontainer #flashbg').flash(
										
		{ src: 'swf/bg.swf', wmode: 'opaque', bgcolor:'#FFFFFF', height: '100%', width: '100%',  id:'flashbg', name:'flashbg', swliveconnect:'true', vars: { foto: backgrounds[currentbackground], doload:'true', scaler:'ja', xpos:'0', newsize:'stage',noscanlines:noscanlines } },
		{ version: 8 }
	);

	$('#kompas #kompasflash').flash(
		{ src: 'swf/kompas.swf', wmode: 'transparent', height: '120', width: '120',  id:'flashkompas', name:'flashkompas', swliveconnect:'true'},
		{ version: 8 }
	);
	$('#tagline #taglineloader').flash(
		{ src: 'swf/tagline.swf', wmode: 'transparent', height: '120', width: '240',  id:'taglineflash', name:'taglineflash', swliveconnect:'true'},
		{ version: 8 }
	);
	setTimeout('tagline()',200);
	// GROTE KOMPAS INSCHUIVEN EN INLADEN
	$('#kompas').click(function(){
		// showKompas();				
	});
	
	// KOMPAS WEER LATEN VERDWIJNEN
	$('#kompasover').click(function(){
		// hideKompas();
	});
	
	reArrangeContent();
	$(".slogan").each(function(){
		var newpos = ((($("#semiblack").height()-$(this).height())/2));
		$(this).css('top',newpos+'px');
	});
	
	showslogan('slogan_0');
	
	$("#slogan ul").elNews();
	
	$(window).bind('resize', function() {
		reArrangeContent();
		 bgpos();
		bgsize(currentheight);
	});
	
	$(window).bind('scroll', function() {
		 bgpos();
	});
	
	
	if(!homepage){
		expand();
	}	
	var oldcoor = false;
	$().mousemove(function(e){
		var xcoord = e.pageX - $("#kompas").offset().left;
		var ycoord = e.pageY - $("#kompas").offset().top;
		if(xcoord +''+ ycoord != oldcoor){
			sendflash("flashkompas",'js_xmouse',xcoord);
			sendflash("flashkompas",'js_ymouse',ycoord);
			oldcoor = xcoord+''+ycoord;
		}
   }); 
	initForms();
});


function bgpos(){
	if($(".contentpage").length > 0){
		newpos = $(window).scrollTop();
		if(newpos + $(window).height() > $("#col_3").height()){
			newpos = $("#col_3").height() - $(window).height();
		}
		$("#bg").css('top',newpos+'px')	
	}
	
}
// HISTORY PLUGIN, INLADEN PAGINA
function pageload(hash) {
	$("#extracontents").stop().hide('fast',function(){ $("#extracontents").html('');});
	loader++;
	if(hash) {
		if($.browser.msie) {
			hash = encodeURIComponent(hash);
		}
		loadPage(hash);
	} else {
		loadPage(startpage);
	}
}

// INLADEN PAGINA
function loadPage(href){
	var kwar = href.split('/');
	thiskw = kwar[0];
	startsite();
	if($("#mainmenu a[keyword="+thiskw+"]").length > 0){
		// ALS ER EEN KLIK OP MAINMENU IS
		$("#mainmenu a[keyword="+thiskw+"]").each(function(){
			activateMainButton($(this));
			loadsubmenu(thiskw);
		});
	}else if($("#submenu a[keyword="+thiskw+"]").length > 0){
		// ALS ER EEN KLIK OP MAINMENU IS
		$("#submenu a[keyword="+thiskw+"]").each(function(){
			activateSubButton($(this));
		});
	}else{
		// TERUG NAAR EEN SUBMENU WAT UITGELADEN IS..
		loadsubmenu(thiskw);
	}
	// EVEN WACHTEN TOT HOME RESIZED IS ALS IE NOG BESTAAT
	if($(".contenthome").length > 0){
		setTimeout("loadAjaxPage('"+href+"')",1000);
	}else{
		loadAjaxPage(href);
	}
} 


// PAGINA INLADEN
function loadAjaxPage(href){
	if(href){
		if(parseInt($("#col_3").css('marginLeft')) > -420){
			collapse(href);
		}else{
			$.ajax({
				type: 	'GET',
				url: 	'loader.php',
				data: 	'p='+href,
				success: function(msg){
					
					var ar = Array();
					ar = msg.split('[SPLITCONTENT]');
					$("#col_3 .text").html(ar[0]);
					$("#col_4 .text").html(ar[1]);
					$("#extracontents").html(ar[2]);
					$("#extracontents").stop().show('fast');
					setTimeout(expand);
				},
				error: function(xhr, ajaxOptions, thrownError){
					alert(xhr.status);
					alert(thrownError);
				}
			});
			
		}
	}
}

// HOOFDKNOP ACTIVEREN
function activateMainButton(el){
	if(typeof(el) == 'string'){
		el = $("#mainmenu a[keyword="+el+"]");
	}
	if(!el.hasClass('active')){
		$("#mainmenu a.active").removeClass('active');	
		el.addClass('active');
		followmainmenu();
	}
}

// PIJLTJE VAN HOOFDMENU BEWEGEN
function followmainmenu(){
	if($("#mainmenu a.active").length > 0){
		pos = $("#mainmenu a.active").offset().top - $("#col_1").offset().top;
		$("#arrow_main").stop().animate({'top':pos+'px'}, 300, "easeOutCubic", false);
	}
}

// SUBKNOP ACTIVEREN
function activateSubButton(el){
	if(typeof(el) == 'string'){
		el = $("#submenu a[keyword="+el+"]");
	}
//	$("#mainmenu").html($("#mainmenu").html() + "<br />"+el.attr('keyword'));

	if(el.length > 0){
		// SUBSUBLINK
		if(el.parent().parent().hasClass('nivo2')){
			if(el.parent().parent().prev().hasClass('active')){
				activateSubButton(el.parent().parent().prev());
				// IS AL UITGEKLAPT
			}else{
				// BOVENLIGGENDE OOK UITKLAPPEN
				activateSubButton(el.parent().parent().prev());
			}
			if($("#submenu .nivo2 a.active").attr('keyword') != el.attr('keyword')){
				$("#submenu .nivo2 a.active").removeClass('active');
			}
			el.addClass('active');
		}else{
			if($("#submenu li > a.active").attr('keyword') != el.attr('keyword')){
				if($("#submenu li > a.active").next(".toggle.show").length > 0){
					$("#submenu li > a.active").next(".toggle.show").removeClass("show").stop(true,true).hide("fast",function(){ followsubmenu()});
				}	
				$("#submenu a.active").removeClass('active');
			
				el.addClass('active');
			}

				if(el.next(".toggle:not(.show)").length > 0){
					el.next(".toggle:not(.show)").stop(true,true).addClass("show").show("fast",function(){followsubmenu()});
				}			
			$("#submenu .nivo2 a.active").removeClass('active');
		}
		$(".lastclicked").removeClass('lastclicked');
		el.addClass('lastclicked');
		followsubmenu();
	}
}

// PIJLTJE VAN SUBMENU BEWEGEN
function followsubmenu(){
	if($("#submenu a.active").length > 0){
		pos = $("#submenu a.lastclicked").offset().top - $("#submenucontainer").offset().top;
	}else{
		pos = '-400';
	}
	$("#arrow_sub").stop().animate({'top':pos+'px'}, 800, "easeOutCubic", false);		
	followmainmenu();
}

//INKLAPPEN VAN SITE
function collapse(href){
	$("#col_4").stop(true).animate({'left':'-600px'},500,"easeOutSine", false);
	$("#col_3").stop(true).animate({'marginLeft':'-420px'},500,"easeOutSine", function(){
		if(href){
			loadAjaxPage(href);	
		}
	});
}

//UITKLAPPEN VAN SITE
function expand(){
	reArrangeContent();
	if($("#col_4 .text").html() != ''){
		$("#col_3").css('width','420px');
		$("#col_3").stop(true).animate({'marginLeft':'400px'},1000,"easeOutSine", function(){ });
		$("#col_4").stop(true).animate({'left':'820px'},1000,"easeOutSine", false);
	}else{
		$("#col_3").css('width','600px');
		$("#col_3").stop(true).animate({'marginLeft':'400px'},1000,"easeOutSine", false);
	}
}

// SUBMENU INLADEN
function loadsubmenu(href){
	if(parseInt($("#submenucontainer").css('left')) > -200){
		$("#submenucontainer").stop().animate({'left':'-200px'},300,"easeOutSine", function(){loadsubmenu(href)});
	}else{
		if(href){
			$.ajax({
				type: 	'GET',
				url: 	'submenu.php',
				data: 	'p='+href,
				success: function(msg){
					$("#submenu").html(msg);
					initLinks();
					followsubmenu();
					$("#submenucontainer").stop().animate({'left':'0px'},500,"easeOutSine");
					
				},
				error: function(xhr, ajaxOptions, thrownError){
					alert(xhr.status);
					alert(thrownError);
				}
			});
		}
	}
}

// TAGLINE WIJZIGEN IN
function tagline(){
	var html2 = '';
	if($("#taglinedata").length > 0){
		html2 = $("#taglinedata").html();
	}else if($("#taglinedata2").length > 0){
		html2 = $("#taglinedata2").html();
	}
	html2 = html2.split('&amp;').join('&');
	sendflash("taglineflash",'titel',html2); 
}

// CONTENT EVEN REANGEREN..
var minheight = $(window).height();
function reArrangeContent(){
	if($(".contentpage").length > 0){
		if($("#col_4 #contents").height() > $("#col_3 #contents").height()){
			var contentheight = $("#col_4 #contents").height();	
		}else{
			var contentheight = $("#col_3 #contents").height();	
		}
		
		if(contentheight < $(window).height()){
			var contentheight = $(window).height();
		}
		
		
		contentheight = contentheight
		$("#col_3, #shifter, #contentcontainer, #backgroundcolors").css('height',contentheight+'px');
		//, #col_4
		$("#flashbg").css('height',$(window).height()+'px');
		if($("#bg").height() > contentheight){
			bgsize(contentheight);
		}
		followmainmenu();
		followsubmenu();
	}
	minheight = $(window).height();
	if(minheight < 500) minheight = 500;
	$("#kompas").css('top',(minheight-120)+'px');
	$("#tagline").css('top',(minheight-135)+'px');
	initKlantenlijst();
	initGallery();
	initReferentielijst();
	initHeaders();
	initLinks();
	initForms();
}

function initForms() {
	$("#ajaxformulier").unbind('submit').submit(function(){
		var form = $(this);
		var data = $(this).serialize();
		$(this).find('input, textarea, checkbox, radio, select').each(function(){
			if($(this).attr('title')){
				ar = $(this).attr('name').split('[]');
				naam = ar[0];
				data += '&veldnamen['+encodeURIComponent(naam)+']=' + encodeURIComponent($(this).attr('title'))
			}
		});
		$.ajax({
			type: 	$(this).attr('method'),
			url: 	$(this).attr('action'),
			data: 	data,
			success: function(msg){
				if(form.attr('target')){
					$("#"+form.attr('target')).html(msg);
				}
			},
			error: function(xhr, ajaxOptions, thrownError){
				alert(xhr.status);
				alert(thrownError);
			}
		});
		return false;
	});

        $(".radInteresse").change(function (){
            if ($(this).val() == "Interesse begin 2011")
                $(".interesseMaand").show();
            else
                $(".interesseMaand").hide();
        });
}

function initLinks(){
	$('.totop').unbind().bind("click",function(){ 
		$('html, body').animate({scrollTop: '0px'}, 300);
		return false;
	});
	$("a[href$=kompas]").unbind().bind("click",function(){ 
		showKompas();
		return false;
	});
	$("a[href$=.swf]").unbind().bind("click",function(){ 
		showKompas($(this).attr('href'));
		return false;
	});
	/*
	$("#mainmenu a, #submenu a").each(function(){
		var urlArray = $(this).attr('href').split('/');
		var page = urlArray[urlArray.length-1].replace(/.html/, '');
		$(this).attr('keyword',page);
	});	
	*/
	$("a:not([target])[href*=.html]").each(function(){
//		pagear[1] = pagear[1].replace(/\?/, '');
		var url = $(this).attr('href').replace($('base').attr('href'),'');
		url  = url.split(/.html/);
//		pagear[1] = pagear[1].replace(/\?/, '');
		$(this).attr('keyword',url[0]);
//		$(this).attr('querystring',pagear[1]);
	});	
	
	$('div#nieuws').each(function(){
		if(parseInt($(this).attr('rel')) > 0 ){
			position = 	$('div#nieuws .item[rel='+$(this).attr('rel')+']').offset().top - 30;
			setTimeout(function(){ $('html, body').animate({scrollTop: position+'px'}, 1200); }, 800);
		}
	});
}
function initHeaders(){
	//$("h1, h2").each(function(){
//		if($(this).find("img").length <= 0){
//			$(this).html('<img src="header.jpg?id='+$.md5($(this).html().replace('\n','').replace('\r',''))+'">');
//		}
//	});	
}
/***GALLERY***/
function initGallery(){
	$("#gallerylinks a").unbind('hover').hover(
		function(){ 
			hovered = $(this);
			$(this).find('.transparent').stop(true).fadeTo(100,0,function(){});
		},
		function(){ 
			hovered = $(this);
			if(!$(this).hasClass('active')){
				$(this).find('.transparent').stop(true).fadeTo(100,0.5,function(){});
			}
		}
	)	
	$("#gallerylinks a").disableTextSelect().unbind('click').click(
		function(){ 
			$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0.5).parent().removeClass('active');
			$(this).addClass('active');
			$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0);
			showActiveGallery();
			return false;
		}
	)	
	$("#gallerylinks").attr('currentpos',0);
	if($("#gallerylinks").height() > $("#gallerythumbs").height()){	
		$("#gallerythumbs .volgende").unbind('click').click(function(){
			$("#gallerylinks").attr('currentpos',$("#gallerylinks").attr('currentpos')-220);
			if($("#gallerylinks").attr('currentpos') <= -$("#gallerylinks").height()){
				$("#gallerylinks").attr('currentpos',$("#gallerylinks").attr('currentpos') - -220);
			}else{
				$("#gallerylinks").stop().animate({'top':$("#gallerylinks").attr('currentpos')+'px'},500);
			}
			return false;
		});
		$("#gallerythumbs .vorige").unbind('click').click(function(){

			$("#gallerylinks").attr('currentpos',$("#gallerylinks").attr('currentpos') - -220);
			if($("#gallerylinks").attr('currentpos') > 0){
				$("#gallerylinks").attr('currentpos',$("#gallerylinks").attr('currentpos')-220);
			}else{
				$("#gallerylinks").stop().animate({'top':$("#gallerylinks").attr('currentpos')+'px'},500);				
			}
			return false;
		});
	}else{
		$("#gallerythumbs .volgende").hide();
		$("#gallerythumbs .vorige").hide();		
	}
	
	$("#gallery #vorige").disableTextSelect().unbind('click').click(function(){
		el = $("#gallerylinks .active").prev();
		if(el.length == 0){
			el = $("#gallerylinks a:last");
		}
		$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0.5).parent().removeClass('active');
		el.addClass('active');
		$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0);
		showActiveGallery();
	});
	
	$("#gallery #volgende").disableTextSelect().unbind('click').click(function(){
		el = $("#gallerylinks .active").next();
		if(el.length == 0){
			el = $("#gallerylinks a:first");
		}
		$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0.5).parent().removeClass('active');
		el.addClass('active');
		$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0);
		showActiveGallery();
	});
	
	setTimeout(showActiveGallery,1000);	
	
	$("#gallery #navigatie").css('top',(minheight-90)+'px');	
}

function showActiveGallery(){
	if($("#gallerylinks .active").length > 0){
		bgloadAll($("#gallerylinks .active").attr('rel'), 0, 'ja', 0, 0, '1');
		$("#gallery h1").html($("#gallerylinks .active").attr('title'));
		
		if($("#gallerylinks .active").attr('title')){
			$("#gallery #titel").show('fast');
		}else{
			$("#gallery #titel").hide('fast');
		}
		$("#gallerylinks .active .transparent").stop(true).fadeTo(100,0);
		var pos = Math.floor($("#gallerylinks a").index($("#gallerylinks .active")) / 16) * -220;
		$("#gallerylinks").attr('currentpos',pos);
		$("#gallerylinks").stop().animate({'top':$("#gallerylinks").attr('currentpos')+'px'},500);
	}
}

/***KLANTENLIJST***/
function initKlantenlijst(){
	
	$("#klantenlijst a").unbind('hover').hover(
		function(){ 
			hovered = $(this);
			if($("#extracontents").find('#customerlogo').length <= 0){
				$("#extracontents").html('<div id="customerlogo"></div>')	
			}
			$("#customerlogo").stop(true).fadeTo(100,0,function(){
					$("#customerlogo").html('<img id="showlogo" src="" />'); 
					$("#customerlogo #showlogo").attr('src',hovered.attr('logo'));
					$("#showlogo").load(function(){
						$("#customerlogo").fadeTo(300,1);
					 });
			});
		},
		function(){
			hovered = $(this);
			$("#customerlogo").stop(true).fadeTo(300,0,function(){});
		}
	)
	if($("#klantenlijst ul li").length > 2){
		$("#klantenlijst #vorige").show();
		$("#klantenlijst #volgende").show();
	}else{
		$("#klantenlijst #vorige").hide();
		$("#klantenlijst #volgende").hide();
	}
	
	$("#klantenlijst #vorige").disableTextSelect().unbind('click').click(function(){
		el = $("#klantenlijst ul .active").prev();
		if(el.length > 0){
			$("#klantenlijst ul .active").removeClass('active');
			el.addClass('active');
			pos = el.parent().children().index(el) * el.width() * -1;
			$("#klantenlijst ul").stop().animate({'left':pos + 'px'},500);
		}
	});
	$("#klantenlijst #volgende").disableTextSelect().unbind('click').click(function(){
		el = $("#klantenlijst ul .active").next();
		if(el.length > 0){
			$("#klantenlijst ul .active").removeClass('active');
			el.addClass('active');
			pos = el.parent().children().index(el) * el.width() * -1;
			$("#klantenlijst ul").stop().animate({'left':pos + 'px'},500);
		}
	});	
	
	$("#klantenlijst #navigatie").css('top',(minheight-90)+'px');	
}


/***REFERENTES***/
function initReferentielijst(){
	
		$("#referentielijst .scroll").jScrollPane({scrollbarWidth:9, showArrows:false, scrollbarMargin:20});
		
	$("#referentielinks a").unbind('hover').hover(
		function(){ 
			hovered = $(this);
			$(this).find('.transparent').stop(true).fadeTo(100,0,function(){});
		},
		function(){ 
			hovered = $(this);
			if(!$(this).hasClass('active')){
				$(this).find('.transparent').stop(true).fadeTo(100,0.5,function(){});
			}
		}
	)	
	$("#referentielinks a").disableTextSelect().unbind('click').click(
		function(){ 
			$("#referentielinks .active .transparent").stop(true).fadeTo(100,0.5).parent().removeClass('active');
			$(this).addClass('active');
			$("#referentielinks .active .transparent").stop(true).fadeTo(100,0);
			showActiveReferentie();
			return false;
		}
	)	
	
	
	$("#referentielijst #volgende").disableTextSelect().unbind('click').click(function(){
		el = $("#referentielinks .active").next();
		if(el.length == 0){
			el = $("#referentielinks a:first");
		}
		$("#referentielinks .active .transparent").stop(true).fadeTo(100,0.5).parent().removeClass('active');
		el.addClass('active');
		$("#referentielinks .active .transparent").stop(true).fadeTo(100,0);
		showActiveReferentie();
	});
	
	$("#referentielinks").attr('currentpos',0);
	if($("#referentielinks").height() > $("#referentiethumbs").height()){	
		$("#referentiethumbs .volgende").unbind('click').click(function(){
			$("#referentielinks").attr('currentpos',$("#referentielinks").attr('currentpos')-220);
			if($("#referentielinks").attr('currentpos') <= -$("#referentielinks").height()){
				$("#referentielinks").attr('currentpos',$("#referentielinks").attr('currentpos') - -220);
			}else{
				$("#referentielinks").stop().animate({'top':$("#referentielinks").attr('currentpos')+'px'},500);
			}
			return false;
		});
		$("#referentiethumbs .vorige").unbind('click').click(function(){

			$("#referentielinks").attr('currentpos',$("#referentielinks").attr('currentpos') - -220);
			if($("#referentielinks").attr('currentpos') > 0){
				$("#referentielinks").attr('currentpos',$("#referentielinks").attr('currentpos')-220);
			}else{
				$("#referentielinks").stop().animate({'top':$("#referentielinks").attr('currentpos')+'px'},500);				
			}
			return false;
		});
	}else{
		$("#referentiethumbs .volgende").hide();
		$("#referentiethumbs .vorige").hide();		
	}	

	setTimeout(showActiveReferentie,1000);	
	$("#referentielijst #navigatie").css('top',(minheight-90)+'px');
}

function showActiveReferentie(){
	$("#referentielijst .active").each(function(){
		newpos = '-'+$(this).height()+'px';
		$(this).removeClass('active').stop(true).animate({'top':newpos},500);
		
	});
	
	$("#referentielinks .active .transparent").stop(true).fadeTo(100,0);
			
	if(parseInt($("#referentielijst #"+$("#referentielinks .active").attr('rel')).css('top')) < '-999'){
		$("#referentielijst #"+$("#referentielinks .active").attr('rel')).css({'top':(-$(this).height())+'px'})	
	}
	$("#referentielijst #"+$("#referentielinks .active").attr('rel')).addClass('active').stop(true).animate({'top':'0px'},500);

	var pos = Math.floor($("#referentielinks a").index($("#referentielinks .active")) / 16) * -220;
	$("#referentielinks").attr('currentpos',pos);
	
	$("#referentielinks").stop().animate({'top':$("#referentielinks").attr('currentpos')+'px'},500);
}



// ACHTERGROND INFO VERZENDEN NAAR FLASH
var xposshift = 0;

var bgInterval = null;
var bgloadto = null;
var firstload  = false;


if(backgrounds.length > 1){
	bgInterval = setInterval(bgload2,5000);
}

function startSlideShow(){
		firstload = true;
	if(backgrounds.length > 1){
		bgInterval = setInterval(bgload2,5000);
	}
	bgload2()
}
function bgload2(){	
	clearTimeout(bgloadto);
	currentbackground++;
	if(currentbackground >= backgrounds.length) currentbackground = 0;
	
	showslogan('slogan_'+currentbackground);
	if(firstload == true){
		dobgload2();
	}else{ 
		bgloadto = setTimeout(dobgload2,2500);
	}
	firstload = false;
}
function dobgload2(){
	bgload(backgrounds[currentbackground], backgroundoptions[0], backgroundoptions[1], backgroundoptions[2], backgroundoptions[3], backgroundoptions[4]);
}
function bgloadAll(src, size, scalemode, xpos, timeoutlength, nolines){
	if(bgInterval){
		clearTimeout(bgloadto);
		clearInterval(bgInterval);
	}
	backgroundsArray 		= src;
	backgrounds			 	= backgroundsArray.split(';');
	currentbackground 		= -1;
	backgroundoptions 		= (size + ';' + scalemode + ';' + xpos + ';' + timeoutlength + ';' + nolines).split(';');

	startSlideShow();
}
function bgload(src, size, scalemode, xpos, timeoutlength, nolines){
	if(!scalemode){
		scalemode = 'nee';
	}
	if(!src){
		$("#flashbg").hide();
	}else{
		$("#flashbg").show();
	}
	sendflash("flashbg",'foto',			src);
	sendflash("flashbg",'newsize',		size);
	sendflash("flashbg",'scaler', 		scalemode);
	sendflash("flashbg",'nolines', 	nolines);
	if(timeoutlength){
		sendflash("flashbg",'timeoutlength', 		timeoutlength);
	}
	xpos = parseInt(xpos);
	if(!xpos){
		xposshift = 0;
	}else{
		xposshift = parseInt(xpos);
	}	

	if($(".contentpage").length > 0){
		var newpos2 	= parseInt(xposshift);
		newpos2 		+= parseInt($("#col_2").offset().left);
		newpos2 		+= parseInt($("#col_2").width());
		sendflash("flashbg",'xpos', newpos2);
	}else{
		sendflash("flashbg",'xpos',xposshift);	
	}
	sendflash("flashbg",'doload','true');
	//setTimeout("sendflash('flashbg','doload', 'true')",200);
}


// VANUIT FLASH COMMANDO KRIJGEN OM TE RESIZEN
function flashbg_DoFSCommand(command, args){
	if (command == "resize") { 
		bgsize(args)
	}
	if (command == "cancelresize"){
		if(waitforswitchto){
			clearTimeout(waitforswitchto);
			waitforswitchto = null;
		}
	}
}
// VANUIT FLASH COMMANDO KRIJGEN OM TE OPENEN
function flashkompas_DoFSCommand(command, args){
	if (command == "open") { 
		showKompas()
	}
}
// VANUIT FLASH COMMANDO KRIJGEN OM TE SLUITEN
function flashkompaslarge_DoFSCommand(command, args){
	if (command == "close") { 
		hideKompas()
	}
}
// ACHTERGROND RESIZEN INDIEN NODIG, DIT WORDT AANGEROEPEN VANUIT DE FLASH
var currentheight = null;
var waitforswitchto = null;
function bgsize(pixels){
	if(waitforswitchto){
		clearTimeout(waitforswitchto);
		waitforswitchto = null;
	}
	pixels = false;
	/*
	if(!pixels || pixels == '0' || pixels == 'undefined'){
		$("#bg").css({'height':'100%'});
	}else{
		$("#bg").css({'height':pixels+'px'});
	}
	
	if($(".contentpage").length > 0){
		bgwidth = ($("#col_2").offset().left+$("#col_2").width());
		$("#bg").css({'left':bgwidth+'px'});
		$("#bg").css({'width':($(window).width() - bgwidth)+'px'});
	}else{
		sendflash("flashbg",'scaler','true');			
	}
	*/
	currentheight = pixels;
	if($(".contentpage").length > 0){
		sendflash("flashbg",'newxpos', ($("#col_2").offset().left+$("#col_2").width()+parseInt(xposshift)));
	}
	waitforswitchto = setTimeout("sendflash('flashbg','switchFoto','true');bgpos();;",1300);
	
}


// ANIMATIE VAN SPLASH NAAR CONTENT, ALLEEN ALS BEPAALDE CLASS ACTIVE IS
function startsite(){
	if($(".contenthome").length > 0){
		$("#languages span").hide();
		$("#slogan").hide();
		$(".nextmessage").hide();
//		$("#bg").css('height',$(this).height()+'px');
		//$("#bg").stop().animate({'height':'400px'},1000);
		$("#contentcontainer").animate(
			{'height':$(document).height()+'px','top':'0%'},
			1000,
			"easeOutSine", 
			function(){
				$(".contenthome").removeClass('contenthome').addClass('contentpage');
				reArrangeContent();	
			}
		);
		$("#semiblack").fadeTo(500,0);
	}
}
function clickProjectTab(kw){
	$(".projecttab.active").removeClass('active');
	$(".projecttab[keyword="+kw+"]").addClass('active');
	$("#tekstload").stop(true,true).hide("fast",function(){
		$(this).load('modules/trainingcat.inc.php?cursus='+kw,function(){
			$(this).stop(true,true).show("fast",function(){
				reArrangeContent();							 
			});
		});
	})
}


