
// BROWSER UPDATE SCRIPT
var $buoop = {} 
$buoop.ol = window.onload; 

window.onload= function()
{ 
	$("#javadisabled").css({"display":"none"});
	if ($buoop.ol) $buoop.ol(); 
	var e = document.createElement("script"); 
	e.setAttribute("type", "text/javascript"); 
	e.setAttribute("src", "http://browser-update.org/update.js"); 
	document.body.appendChild(e);
	$(window).hashchange();
}
var first_build = true;
var animate_posts = 0;
var animated_posts = 0;
var last_page = '';
var last_opened_post = new Object();
$(window).hashchange(function()
{
	if (!inanimate)
	{
		var speed = 360;
		var delay_time = 0;
		if (first_build) delay_time = 360;
		var page = window.location.hash.substr(2);
		if ( $( '#direct_page' ).html() && $( '#direct_page' ).html() != '' ) { page = $( '#direct_page' ).html(); $( '#direct_page' ).html(''); }
		var post_info = false;
		$.ajax({
			url: base_url + 'ajax/' + page,
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				// console.log(XMLHttpRequest.responseText); //
			},
			success: function(data, textStatus, XMLHttpRequest)
			{
				// How much should be animated //
				animate_posts = 0;
				animated_posts = 0;
				// Hide the footer //
				$( '#footer' ).stop(true,false).css({ 'opacity':0 });
				// Place the new data in a temporary div //
				$( '#temp_container' ).html( data );
				if ( $( '#temp_container' ).height()+12 > max_height ) max_height = $( '#temp_container' ).height()+12;
				// Set the menu selecteds //
				$.each( $( '#header' ).find( 'a' ), function() {
					$( this ).css( {'color':''} );
					var href = $( this ).attr('href').split('/');
					if ( href[href.length-1] != "") 
					{
						var selected = $( '#temp_container' ).find('.selected_menu_items:contains(",en/' + href[href.length-1] +',")');
						if ( $( selected ).length > 0 ) $( this ).css( {'color':'#20abcd'} );
					}
				});
				// What type of page is it //
				var single_page = $( '#temp_container' ).children( '.page' ).length > 0;
				var current_page = false;
				if ( $( '#temp_container' ).children( '.page' ).children( '.path' ).length > 0 )
				{
					current_page = $( '#temp_container' ).children( '.page' ).children( '.path' ).html().replace("/", "_")
				}
				// Close all the blog items which are not in use //
				$.each( $( '#content' ).find( '.page' ), function() {
					// Hide de Vimeo //
					var vimeo_height = $( this ).find( '.dark_background' ).height() + 'px';
					$( this ).find( '.dark_background' ).css({ 'height' : vimeo_height }).html("<div class='vimeo een_image image_border' style='height:100%'></div>");
					$( this ).stop(true,true).slideUp(speed, function() {
						$( 'div' ).remove( '.page' );
					});
					$( this ).find( '.dark_background' ).stop(true,true).slideUp(speed*.9);
					// delay_time = speed;
				});
				$.each( $( '#content' ).find( '.makingof' ), function() {
					$( 'div' ).remove( '.makingof' );
				});
				var slideUp = false;
				$.each( $( '#content' ).children( '.blogpost' ), function() 
				{
					var hide = false;
					if ( single_page && current_page && current_page != $( this ).attr('id') )
					{
						hide = true;
					}
					else if ( !single_page && $( '#temp_container' ).children( '#' + $( this ).attr('id') ).length < 1)
					{
						hide = true;
					} 
					if ( hide )
					{
						var pos = $( this ).offset();
						if (pos.top < ( $( window ).scrollTop() + $(window).height() ) )
						{
							$( this ).children( '.info' ).css({'left':$( this ).children( '.background' ).css('left'),'top':$( this ).children( '.background' ).css('top')});
							$( this ).children( '.info' ).stop(true,false).animate({'opacity':0},speed*.5);
							$( this ).children( '.background' ).animate({"opacity":0}, speed*.5);
							$( this ).stop(true,true).slideUp(speed);
							slideUp = true;
						}
						else
						{
							$( this ).stop(true,false).css({"display":"none"});
						}
					}
					if ( last_opened_post.id  && $( this ).attr('id') == last_opened_post.id )
					{
						// Reset the last opened post //
						$( this ).children( '.background' ).stop(true,false);
						var height = $( this ).children( '.image' ).children( '.een_image' ).children('a').children( 'img' ).height();
						animate_posts++;
						if ( $( this ).children( '.info' ).hasClass( 'tekstrechts' ) || $( this ).children( '.info' ).hasClass( 'tekstlinks' ) || $( this ).children( '.info' ).hasClass( 'rechtshoog' ) || $( this ).children( '.info' ).hasClass( 'linkshoog' ) )
						{
							$( this ).children( '.image' ).children( '.een_image' ).animate( {'height':height} , speed*2 );
							$( this ).children( '.background' ).animate({
								'height'	: last_opened_post.height,
								'top'		: last_opened_post.top
							}, speed);
							$( this ).delay(speed).children( '.background' ).animate({
								'width'		: last_opened_post.width,
								'left'		: last_opened_post.left,
							}, speed, function() {
								animated_posts++;
								animation_finished(page);
							});
						}
						else if ( $( this ).children( '.info' ).hasClass( 'drieblokken' ) )
						{
							$( this ).children( '.image' ).children( '.een_image' ).animate( {'height':height} , speed*2 );
							$( this ).children( '.background' ).animate({
								'width'		: last_opened_post.width,
								'left'		: last_opened_post.left,
								'height'	: 262,
								'top'		: 0
							}, speed, function() {
								animated_posts++;
								animation_finished(page);
							});
							$( this ).delay(speed).children( '.background' ).animate({
								'height'	: last_opened_post.height,
								'top'		: last_opened_post.top
							}, speed);
						}
						else
						{
							$( this ).children( '.background' ).animate({
								'height'	: last_opened_post.height,
								'top'		: last_opened_post.top
							}, speed);
							$( this ).delay(speed).children( '.background' ).animate({
								'width'		: last_opened_post.width,
								'left'		: last_opened_post.left,
							}, speed, function() {
								animated_posts++;
								animation_finished(page);
							});
						}
						var height = 0;
						if ( $( this ).children( '.info' ).hasClass( 'drieblokken' ) )
						{
							var height = 124;
							$( this ).children(".image").find(".image_1").animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
							$( this ).children(".image").find(".image_2").animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
							$( this ).children(".image").find(".image_3").animate({"height":262},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						}
						else if ( $( this ).children( '.info' ).hasClass( 'vierblokken' ) )
						{
							var height = 190;
							var current_delay = delay_time+speed;
							$.each($( this ).children(".image").children('.vierblokken_image'), function() {
								$( this ).animate({"height":height},speed).delay(current_delay).animate({"opacity":1},speed);
								current_delay += 50;
							});
						}
						post_info = last_opened_post;
						var is_in_next_page = ( $( '#temp_container' ).find( '#'+post_info.id ).length > 0 );
						$( this ).children( '.info' ).animate({ 'opacity':0 }, speed*.5, function() {
							var temp_opacity = 0;
							if ( is_in_next_page ) temp_opacity = 1;
							$( this ).css( { 'width':post_info.width,'height': post_info.height,'left':post_info.left,'top': post_info.top} ).html( post_info.post ).animate({ 'opacity':temp_opacity }, speed);
							if (temp_opacity == 1) temp_opacity = .9
							$( this ).parent().children( '.background' ).animate( {'opacity':temp_opacity}, speed );
						} );
						$( this ).children( '.background' ).animate( {'opacity':.9}, 100 );
						last_opened_post = new Object();
					}
				});
				if ( slideUp ) delay_time += speed;
				
				if ( !single_page )
				{
					$.each( $( '#temp_container' ).children( '.blogpost' ), function() 
					{
						var post = false;
						var post_is_new = false;
						var openup_post = false;
						if ( $( '#content' ).children( '#' + $( this ).attr('id') ).length < 1 || $( this ).attr('id').substr(0,6) == "about_" )
						{	
							post = $( this );
							$( post ).children( '.info' ).css({ 'opacity':0 });
							$( post ).children( '.background' ).css({ 'opacity':0 });
							if (!first_build || $( this ).attr('id').substr(0,6) == "about_") $( post ).css( {'overflow':'hidden'} ).hide();
							post_is_new = true;
							openup_post = true;
						}
						else
						{	
							post = $( '#content' ).children( '#' + $( this ).attr('id') );
							if ( !$( post ).is(":visible") )
							{
								$( post ).children( '.info' ).css({ 'opacity':0 });
								$( post ).children( '.background' ).css({ 'opacity':0 });
								openup_post = true;
							}
							$( '#content' ).remove( '#' + $( this ).attr('id') );
						}
						$( post ).appendTo( '#content' );
						var image_start_opacity = 1;
						if ( post_is_new ) image_start_opacity = 0;
						
						if ( $( post ).children( '.info' ).hasClass( 'drieblokken' ) )
						{
							
							$( post ).children(".image").find(".image_1").css({"opacity":image_start_opacity});
							$( post ).children(".image").find(".image_2").css({"opacity":image_start_opacity});
							$( post ).children(".image").find(".image_3").css({"opacity":image_start_opacity});
						}
						else if ( $( post ).children( '.info' ).hasClass( 'vierblokken' ) )
						{
							$.each($( post ).children(".image").children('.vierblokken_image'), function() {
								$( this ).css({"opacity":image_start_opacity});
							});
						}
						else
						{
							$( post ).children( '.image' ).find( 'img' ).css({"opacity":image_start_opacity});
							$( post ).children( '.image' ).find( 'iframe' ).css({"opacity":image_start_opacity});
						}
						
						$( post ).stop(true,true).delay(delay_time).slideDown(speed, function() {
							var post_animated_already = ( post_info.id && $( post ).attr('id') == post_info.id );
							if ( !post_animated_already )
							{
								if ( $( this ).children( '.info' ).length > 0 && $( this ).children( '.background' ).length > 0 )
								{
									var info_offest = $( this ).children( '.info' ).offset();
									var parent_offset = $( this ).offset();
									
									$( this ).children( '.background' ).stop(true,false);
									$( this ).children( '.background' ).height( $( this ).children( '.info' ).height() );
									$( this ).children( '.background' ).width( $( this ).children( '.info' ).width() );

									$( this ).children( '.background' ).css( {'left' : info_offest.left-parent_offset.left, 'top' : info_offest.top-parent_offset.top} );
									$( this ).children( '.background' ).css( {'display':'block'} );
									$( this ).children( '.info' ).css({ 'opacity':1, 'background-color':'transparent' });

									$( this ).children( '.background' ).animate( {'opacity':.9}, 100 );
									
									if ( openup_post )
									{
										$( this ).children( '.background' ).stop(true,false);
										var height = $( this ).children( '.image' ).children( '.een_image' ).find( 'img' ).height();
										var width = $( this ).children( '.info' ).width()+12;
										if ( $( this ).children( '.info' ).hasClass( 'tekstrechts' ) )
										{
											$( this ).children( '.background' ).css( {'left' : info_offest.left-parent_offset.left+width, 'top' : info_offest.top-parent_offset.top} );
											$( this ).children( '.background' ).stop(true,false).delay(100).animate( {'left':info_offest.left-parent_offset.left,'opacity':.9}, speed );
											$( this ).children( '.info' ).stop(true,false).css({ 'left':info_offest.left-parent_offset.left+width }).delay(100).animate( {'left':info_offest.left-parent_offset.left}, speed );
										}
										else if ( $( this ).children( '.info' ).hasClass( 'rechtshoog' ) )
										{
											$( this ).children( '.background' ).css( {'left':info_offest.left-parent_offset.left+width, 'top':2, 'height':height } );
											$( this ).children( '.background' ).stop(true,false).delay(100).animate( {'left':info_offest.left-parent_offset.left,'opacity':.9}, speed );
											$( this ).children( '.info' ).stop(true,false).css({ 'left':info_offest.left-parent_offset.left+width }).delay(100).animate( {'left':info_offest.left-parent_offset.left}, speed );
										}
										else if ( $( this ).children( '.info' ).hasClass( 'tweeblokkeninforight' ) )
										{
											$( this ).children( '.background' ).css( {'left':info_offest.left-parent_offset.left+width, 'top':2, 'height':height } );
											$( this ).children( '.background' ).stop(true,false).delay(100).animate( {'left':info_offest.left-parent_offset.left,'opacity':.9}, speed );
											$( this ).children( '.info' ).stop(true,false).css({ 'left':info_offest.left-parent_offset.left+width }).delay(100).animate( {'left':info_offest.left-parent_offset.left}, speed );
										}
										else if ( $( this ).children( '.info' ).hasClass( 'linkshoog' ) )
										{
											$( this ).children( '.background' ).css( {'left':info_offest.left-parent_offset.left-width, 'top':2, 'height':height } );
											$( this ).children( '.background' ).stop(true,false).delay(100).animate( {'left':info_offest.left-parent_offset.left,'opacity':.9}, speed );
											$( this ).children( '.info' ).stop(true,false).css({ 'left':info_offest.left-parent_offset.left-width }).delay(100).animate( {'left':info_offest.left-parent_offset.left}, speed );
										}
										else
										{
											$( this ).children( '.background' ).css( {'left' : info_offest.left-parent_offset.left-width, 'top' : info_offest.top-parent_offset.top} );
											$( this ).children( '.background' ).stop(true,false).delay(100).animate( {'left':info_offest.left-parent_offset.left,'opacity':.9}, speed );
											$( this ).children( '.info' ).stop(true,false).css({ 'left':info_offest.left-parent_offset.left-width }).delay(100).animate( {'left':info_offest.left-parent_offset.left}, speed );
										}
									}
								}
								if ( openup_post )
								{
									var height = 0;
									if ( $( this ).children( '.info' ).hasClass( 'drieblokken' ) )
									{
										var height = 124;
										$( this ).children(".image").find(".image_1").css({"opacity":image_start_opacity}).stop(false,true).animate({"height":height},speed*.2).delay(0).animate({"opacity":1},speed*.5);
										$( this ).children(".image").find(".image_2").css({"opacity":image_start_opacity}).stop(false,true).animate({"height":height},speed*.2).delay(speed*.33).animate({"opacity":1},speed*.5);
										$( this ).children(".image").find(".image_3").css({"opacity":image_start_opacity}).stop(false,true).animate({"height":262},speed*.2).delay(speed*.66).animate({"opacity":1},speed*.5);
									}
									else if ( $( this ).children( '.info' ).hasClass( 'vierblokken' ) )
									{
										var height = 190;
										var current_delay = 0;
										$.each($( this ).children(".image").children('.vierblokken_image'), function() {
											$( this ).css({"opacity":image_start_opacity}).stop(false,true).animate({"height":height},speed).delay(current_delay).animate({"opacity":1},speed*.5);
											current_delay += speed*.25;
										});
									}
									else
									{
										$( this ).children( '.image' ).find( 'img' ).css({"opacity":image_start_opacity}).stop(false,true).animate({"opacity":1},speed);
										$( this ).children( '.image' ).find( 'iframe' ).css({"opacity":image_start_opacity}).stop(false,true).animate({"opacity":1},speed);	
									}
								}
							}
						});
						if ( first_build ) delay_time += speed;
					});
				}
				
				if (single_page && $( '#content' ).children( '#' + current_page ).length > 0 )
				{	
					// Open single post //
					var page_info_height = $( '#temp_container' ).children( '.page' ).children( '.page_info' ).height();
					var open_post = $( '#content' ).children( '#' + current_page );
					var info_offest = $( open_post ).children( '.info' ).offset();
					var parent_offset = $( open_post ).offset();
					if ( $( open_post ).children( '.info' ).hasClass( 'tekstlinks' ) || $( open_post ).children( '.info' ).hasClass( 'tekstrechts' ) || $( open_post ).children( '.info' ).hasClass( 'rechtshoog' ) || $( open_post ).children( '.info' ).hasClass( 'linkshoog' ) )
					{
						if ( $( open_post ).children( '.share' ).css( 'opacity' ) != '0')
						{	// Hide the share buttons //
							var share_animate_to = 692;
							info_offest.left = info_offest.left+90;
							if ( $( open_post ).children( '.info' ).hasClass( 'tekstlinks' ) ) {
								share_animate_to = -94;
								info_offest.left = info_offest.left-180;
							}
							$( open_post ).children( '.share' ).animate({
								"left"	: share_animate_to,
								"opacity": 0
							},speed);
						}
					}
					last_opened_post = new Object({
						'id'		: $( open_post ).attr( 'id' ),
						'post'		: $( open_post ).children( '.info' ).html(),
						'left'		: info_offest.left-parent_offset.left,
						'top'		: info_offest.top-parent_offset.top,
						'width'		: $( open_post ).children( '.info' ).width(),
						'height'	: $( open_post ).children( '.info' ).height()
					});
					if ( $( open_post ).children( '.info' ).hasClass( 'tekstrechts' ) || $( open_post ).children( '.info' ).hasClass( 'tekstlinks' ) )
					{
						$( open_post ).children( '.background' ).animate({"top":2,"height":page_info_height}, speed*.5);
						$( open_post ).children( '.background' ).delay(speed*.5).animate({"left":2,"width":688}, speed*.5);
						$( open_post ).children( '.image' ).children(".een_image").animate({"height":page_info_height},speed*.5);
					}
					else if ( $( open_post ).children( '.info' ).hasClass( 'drieblokken' ) )
					{
						$( open_post ).children( '.background' ).animate({"top":2,"height":page_info_height,"opacity":1}, speed*.5);
						$( open_post ).children( '.background' ).delay(speed*.5).animate({"left":2,"width":688}, speed*.5);
						$( open_post ).children(".image").find(".image_1").delay(speed).animate({"opacity":0},speed*.25).delay(0).animate({"height":0},speed);
						$( open_post ).children(".image").find(".image_2").delay(speed*.25).animate({"opacity":0},speed*.25).delay(0).animate({"height":0},speed);
						$( open_post ).children(".image").find(".image_3").delay(speed*.5).animate({"opacity":0},speed*.25).delay(0).animate({"height":page_info_height},speed);
					}
					else if ( $( open_post ).children( '.info' ).hasClass( 'vierblokken' ) )
					{
						$( open_post ).children( '.background' ).animate({"top":2,"height":page_info_height,"opacity":1}, speed*.5);
						$( open_post ).children( '.background' ).delay(speed*.5).animate({"left":2,"width":688}, speed*.5);
						var current_delay = ( (speed*.25) * $( open_post ).children(".image").children('.vierblokken_image').length );
						$.each($( open_post ).children(".image").children('.vierblokken_image'), function() {
							var current_image_height = 0;
							if (current_delay == speed*.25) current_image_height = page_info_height-12;
							$( this ).delay(current_delay).animate({"opacity":0},speed).delay(speed).animate({"height":current_image_height},speed);
							current_delay -= speed*.25;
						});
					}
				}
				// Placement of the page
				if ( single_page && $( '#content' ).children( '#' + current_page ).length > 0 )
				{
					direct_url = false;
					var info_first = $( '#temp_container' ).find(".infofirst").html()+0;
					var page_info = $( '#temp_container' ).find(".page_info").html();
					var image = $( '#temp_container' ).find(".image").html();
					var image_div = "<div class='page'><div class='image dark_background' style='100%'><div class='vimeo een_image image_border' style='height:100%'></div></div></div>";
					var image_height = $( '#temp_container' ).find(".image").height();
					
					var makingof = "<div class='makingof' style='margin-top:12px;'>" + $( '#temp_container' ).find(".makingof").html() + "</div>";
					$( open_post ).children(".info").animate({"opacity":0}, speed, function() {
						$( this ).css({"width":688,"left":2,"top":2,"height":'10'}).html( page_info ).animate({"opacity":1},speed, function() {
							if ( image )
							{
								if (info_first < -1)
								{
									$( image_div ).prependTo( $( this ).parent().parent() );
								}
								else
								{
									$( image_div ).appendTo( $( this ).parent().parent() );
								}
								$( this ).parent().parent().children('.page').find('.vimeo').animate({ 'height':image_height+'px' },speed, function() {
									$( this ).parent().parent().find('.dark_background').html( image );
								});
							}
							if ( makingof )
							{
								var makingof_delay = speed;
								$( makingof ).appendTo( $( this ).parent().parent() );
								$.each( $( this ).parent().parent().children('.makingof').find('.lightbox'), function() {
									$( this ).css({ 'opacity':0 }).delay(makingof_delay).animate({ 'opacity':1 },250,function(){ activate_buttons(); });
									makingof_delay += 100;
								});
								activate_buttons();
							}
						});
					});
				}
				else if ( single_page )
				{
					direct_url = true;
					$( '#content' ).append( data );
				}
				// Scroll //
				if ( single_page )
				{
					$('html,body').animate( { 'scrollTop':0 },speed );
				}
				else if ( post_info.id )
				{
					var temp_post = $( '#temp_container' ).find( '#'+post_info.id );
					if ( $( temp_post ).length > 0 )
					{
						$( '#content' ).height( max_height );
						var top = ( $( temp_post ).offset().top - $( temp_post ).parent().offset().top );
						$('html,body').stop(false,true).animate( { 'scrollTop':top }, delay_time+speed, function() {
							$( '#content' ).height('');
						});
					}
				}
				// Empty the temporary div //
				$( '#temp_container' ).html('');
				// Activate the page //
				if ( animate_posts < 1 ) animation_finished(page);
				first_build = false;
			}
		});
	}
});

function animation_finished(page)
{
	last_page = page.replace("/", "_");			// Reset the last visited page //
	if ( animate_posts == animated_posts)
	{
		$( '#footer' ).stop(true,false).delay(250).animate({'opacity':1},240);		// Show the footer //
		activate_buttons();							// Activate the buttons //
	}
}
