$(window).hashchange(function()
{
	var cancel = false;
	if (window.location.hash.length > 1)
	{
		if (window.location.hash.substr(1,window.location.hash.length).indexOf("/client/") > -1)
		{
			if (inanimate || direct)
			{
				window.location = "http://wouw.com/clients/";
			}
			else
			{
				window.location = "http://wouw.com/#/clients/";
			}
			cancel = true;
		}
	}
	if (!cancel)
	{
		if (window.location.hash && window.location.hash.length > 1)
		{
			var pageTracker = _gat._getTracker('UA-23349942-1');
			pageTracker._trackPageview(window.location.hash.substr(1,window.location.hash.length));
		}
		retrieve_que = new Array();
		retrieving = false;
		siteUpdate(window.location.hash);
	}
});

$(document).ready(function() 
{
	$(".bodyMac").css({"font-style":"normal"});
	if (navigator.userAgent.indexOf("Firefox") > -1) firefox = true;
	if (navigator.appName.indexOf("Microsoft") > -1) ie = true;
	$("#blog").css({"display":"block"});
	$("#javadisabled").css({"display":"none"});
	$( "#header" ).children(".btn").unbind().mouseover(function() {
		$(this).addClass("hover");
	}).mouseout(function() {
		$(this).removeClass("hover");
	}).mouseup(function() {
		previous = path;
		window.location = create_link($(this).attr("id").substr(1));	
	});
	$( ".logo" ).unbind().mouseup(function() {
		previous = path;
		window.location = create_link(first_menu_item);
	});
	
	var cancel = false;
	if (window.location.hash.length > 1)
	{
		if (window.location.hash.substr(1,window.location.hash.length).indexOf("/client/") > -1)
		{
			if (inanimate || direct)
			{
				window.location = "http://wouw.com/clients/";
			}
			else
			{
				window.location = "http://wouw.com/#/clients/";
			}
			cancel = true;
		}
	}
	if (!cancel)
	{
		if (inanimate || direct)
		{
			setCenter();
			setTimeout(siteReady,200+Math.ceil($("#content").html().length/100));
		}
		else
		{
			siteUpdate(window.location.hash);
		}
	}
});

function setCenter()
{
	if (firefox || ie)
	{
		var size = reportSize();
		$( "#pagewidth" ).css({"margin-left":Math.round((size[0]-828)*.5)+"px"});
		if ($.browser.msie){ document.getElementById("pageWidth").style.removeAttribute('filter');}
	}
}

function reportSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		return new Array(window.innerWidth, window.innerHeight);
	} else {
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			return new Array(document.documentElement.clientWidth, document.documentElement.clientHeight);
		} else {
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			return new Array(document.body.clientWidth, document.body.clientHeight);
			}
		}
	}
}

function siteUpdate(p)
{
	setLoadingState(true);
	path = p;
	if (!path) path = "#/"+first_menu_item+"/";
	$( "#header" ).children(".btn").removeClass("selected");
	if ($( "#header" ).children("#_"+path.replace("/","").substring(1)).length)
	{
		$( "#header" ).children("#_"+path.replace("/","").substring(1)).addClass("selected");
	}
	else if (path.replace("/","").substring(1,7) == "client")
	{
		$( "#header" ).children("#_clients").addClass("selected");
	}
	else if (previous)
	{
		$( "#header" ).children("#_"+previous.replace("/","").substring(1)).addClass("selected"); 
	}
	if ($( ".share" ).css("opacity") == "1")
	{
		var pos = $( ".share" ).parent().children(".info").offset();
		var parent_pos = $( ".share" ).parent().offset();
		$( ".share" ).parent().children(".info").animate({"left":pos.left-parent_pos.left+90}, 190);
		$( ".share" ).parent().children(".background").animate({"left":pos.left-parent_pos.left+90}, 190);
		$( ".share" ).animate({"left":692,"opacity":0}, 190);
	}
	
	// CLOSE THE ABOUT PAGE PARTS;
	for (var i=0; i<3; i++)
	{
		if ($("#about_"+i).children().length)
		{
			var pos = $("#about_"+i).offset();
			if (pos)
			{
				if (pos.top < ($(window).scrollTop()+$(window).height()))
				{
					$("#about_"+i).stop(true,false).slideUp("fast",function(){ $(this).remove(); });
				}
				else
				{
					$("#about_"+i).stop(true,false).remove();
				}
			}
			$("#about_"+i).addClass("disactive");
		}
	}
	// CLOSE AND REMOVE THE CLIENT PART;
	$.each($(".clientpost_item"),function() {
		var pos = $(this).offset();
		if (pos)
		{
			if (pos.top < ($(window).scrollTop()+$(window).height()))
			{
				$(this).stop(true,false).slideUp("fast",function(){ $(this).remove(); });
			}
			else
			{
				$(this).stop(true,false).remove();
			}
		}
		$(this).addClass("disactive");
	});
	
	var request = "path="+path;
	$.ajax({
		url: root+"/php/function/get_path.php",
		data: request,
		type: "POST",
		success: function(html) 
		{
			if (html.substr(0,5) == "list:")
			{
				// CLOSE EVERYTHING IF NOT IN LIST;
				html = html.substr(5,html.length);
				var insertAfter = false;
				var showBlogs = html.split("*");
				var showBlog_ids = html.split("/").join("_").split("+").join("-").split("*");
				var countAnimated = 0;
				$.each($("#blog").children(),function() {
					if (!in_array($(this).attr("id"),showBlog_ids))
					{
						var pos = $(this).offset();
						if (pos.top < ($(window).scrollTop()+$(window).height()))
						{
							$(this).stop(true,false).slideUp("fast");
						}
						else
						{
							$(this).stop(true,false).css({"display":"none"});
						}
						$(this).addClass("disactive");
						if ($(this).html() == "") $(this).remove();
						countAnimated++;
					}
				});
				
				var timeOut = 250;
				if (countAnimated == 0) timeOut = 0;
				setTimeout(function() {
					// REORDER //
					var post;
					var cls = "";
					if (!inanimate) cls = "class=\"animate\"";
					for (var i=0; i<showBlogs.length; i++)
					{
						if (showBlog_ids[i])
						{
							if ($("#blog").children("#"+showBlog_ids[i]).length)
							{
								post = $("#blog").children("#"+showBlog_ids[i]);
								$("#blog").remove("#"+showBlog_ids[i]);
							}
							else
							{
								post = '<div id="'+showBlog_ids[i]+'" '+cls+'></div>';
							}
							$(post).appendTo('#blog');
							quePost(showBlogs[i],showBlog_ids[i]);
						}
					}
					// RETRIEVE AND OPEN POSTS //
					retrievePost();
				}, timeOut);
			}
			else
			{
				if (!inanimate) $("#footer").addClass("hidden");
				var send_path = html.substr(5,html.length);
				var request = "path="+send_path;
				$.ajax({
					url: root+"/php/function/get_page.php",
					data: request,
					type: "POST",
					success: function(html) 
					{
						var replace = false;
						$.each($("#blog").children(),function() {
							if ($(this).attr("id") != send_path.split("/").join("_").split("+").join("-"))
							{
								var pos = $(this).offset();
								if (pos.top < ($(window).scrollTop()+$(window).height()))
								{
									$(this).delay(200).stop(true,false).slideUp("fast");
								}
								else
								{
									$(this).stop(true,false).css({"display":"none"});
								}
								$(this).addClass("disactive");
								if ($(this).html() == "") $(this).remove();
							} else {
								replace = true;
							}
						});
						if (send_path == "/about/" || send_path.substr(0,7) == "/client")
						{
							$( "#content" ).append(html);
							if (!inanimate)
							{
								$.each($("#content .about"),function() {
									$(this).addClass("animate");
								});
								$.each($("#content .clientpost_item"),function() {
									$(this).addClass("animate");
								});
							}	
						}
						else
						{
							$( "#content" ).prepend(html);
							background_height = $(".page").children(".info").height(); 
							if (replace)
							{
								$(".page").addClass("hidden");
								$(".page").children(".image").children(".een_image").css({"opacity":0,"height":0});
								$(".page").children(".image").children(".een_image").delay(200).animate({"height":387,"opacity":1},"fast");
								if ($(".page").children(".infofirst").html() == "1")
								{
									var detached = $(".page").children(".image").detach();
									detached.appendTo($(".page"));
									if ($(".page").children(".makingof").children().length)
									{
										detached = $(".page").children(".makingof").detach();
										detached.appendTo($(".page"));
									}
								}
							}
						}
						setTimeout(function() { setLoadingState(false); }, 600);
						setTimeout(siteReady, 320);
					}
				});
			}
		}
	});
}

var retrieving = false;
var retrieve_que = new Array();
function quePost(p,id)
{
	var retrieve_arr = new Array(p,id);
	retrieve_que.push(retrieve_arr);
}
function retrievePost(recursive)
{
	if (!retrieving && retrieve_que.length > 0 || recursive && retrieve_que.length > 0)
	{
		retrieving = true;
		var retrieve_arr = retrieve_que.shift();
		if (!$("#"+retrieve_arr[1]).html())
		{
			var request = "path="+retrieve_arr[0];
			$.ajax({
				url: root+"/php/function/get_preview_post.php",
				data: request,
				type: "POST",
				success: function(html) 
				{
					if (retrieving)
					{
						$("#"+retrieve_arr[1]).html(html);
						$("#"+retrieve_arr[1]+" .blogpost .image .een_image img, #"+retrieve_arr[1]+" .blogpost .image .image_3 img").load(function() {
							if (previous)
							{
								var height = $("#"+retrieve_arr[1]).height()+12  ;
								$("#"+retrieve_arr[1]).css({"height":0});
								$("#"+retrieve_arr[1]).animate({"height":height},"fast");
							}
							$("#"+retrieve_arr[1]).removeClass("disactive");
							// SET THE WITH AND HEIGHT OF THE BACKGROUND
							// setTimeout(function() {
								if ($("#"+retrieve_arr[1]).children(".blogpost").children(".background").width() < 10)
								{
									var pos = $("#"+retrieve_arr[1]).children(".blogpost").children(".info").offset();
									var parent_pos = $("#"+retrieve_arr[1]).children(".blogpost").offset();
									if (pos)
									{
										if (pos.left)
										{
											$("#"+retrieve_arr[1]).children(".blogpost").children(".background").height($("#"+retrieve_arr[1]).children(".blogpost").children(".info").height());
											$("#"+retrieve_arr[1]).children(".blogpost").children(".background").width($("#"+retrieve_arr[1]).children(".blogpost").children(".info").width());
											$("#"+retrieve_arr[1]).children(".blogpost").children(".background").css({"left":pos.left-parent_pos.left,"top":pos.top-parent_pos.top});
											if ($("#"+retrieve_arr[1]).children(".blogpost").children(".info").hasClass("drieblokken")) $("#"+retrieve_arr[1]).children(".blogpost").children(".background").css({"opacity":0});
										}
									}
									siteReady();
								}
							//},800);
							retrievePost(true);
						});
					}
				}
			});
		}
		else
		{
			$("#"+retrieve_arr[1]).removeClass("disactive");
			retrievePost(true);
		}
	}
	else if (retrieve_que.length == 0)
	{
		setTimeout(function() {
			retrieving = false;
			setTimeout(function() { setLoadingState(false); }, 600);
			siteReady();
		}, 100);
	}
}

function siteReady()
{
	var delay_time = 50;
	var speed = 280;
	var placed = false;
	if ($(".page").children().length)
	{
		var id = document.location.hash.substr(1).split("+").join("-").split("/").join("_");
		if ($(".page").hasClass("hidden") && $("#"+id).length)
		{
			// PLACEMENT OF A SINGLE PAGE
			var parent_pos = $("#"+id).children(".blogpost").offset();
			last_opened_blog = new Array();
			last_opened_blog[0] = id;
			last_opened_blog[1] = $("#"+id).children(".blogpost").children(".info").offset();
			last_opened_blog[1].left = last_opened_blog[1].left-parent_pos.left;
			last_opened_blog[1].top = last_opened_blog[1].top-parent_pos.top;
			last_opened_blog[1].width = $("#"+id).children(".blogpost").children(".info").width();
			last_opened_blog[1].height = $("#"+id).children(".blogpost").children(".info").height();
			last_opened_blog[2] = parent_pos.top;
			placed = true;
			$('html,body').animate({scrollTop: 0}, speed);
			if ($("#"+id).children(".blogpost").children(".info").hasClass("tekstrechts"))
			{
				$("#"+id).children(".blogpost").children(".background").animate({"left":2,"width":688,"top":2,"height":background_height}, speed*.5);
				$("#"+id).children(".blogpost").children(".image").children(".een_image").animate({"height":background_height},speed*.5);
				$("#"+id).children(".blogpost").children(".info").animate({"opacity":0}, speed*.5);
				$(".page").delay(0+(speed*.5)).append("<div class=\"hidden post_info\">"+$("#"+id).children(".blogpost").children(".info").html()+"</div>");
				$("#"+id).children(".blogpost").children(".info").delay(0+(speed*.5)).css({"width":688,"left":2,"top":2}).html($(".page").children(".info").html());
				
				$("#"+id).delay(0+(speed*.5)).children(".blogpost").children(".info").animate({"opacity":1},speed*.5,function() {
					// setLoadingState(false);
					btnReady();	
				}); 
				delay_time = 0;
			}
			else if ($("#"+id).children(".blogpost").children(".info").hasClass("drieblokken"))
			{
				$("#"+id).children(".blogpost").children(".background").animate({"left":2,"width":688,"top":2,"height":background_height,"opacity":1}, speed*.5);
				$("#"+id).children(".blogpost").children(".image").children(".een_image").animate({"height":background_height},speed*.5);
				$("#"+id).children(".blogpost").children(".info").animate({"opacity":0}, speed*.5);
				$(".page").delay(0+(speed*.5)).append("<div class=\"hidden post_info\">"+$("#"+id).children(".blogpost").children(".info").html()+"</div>");
				$("#"+id).children(".blogpost").children(".info").delay(0+(speed*.5)).css({"width":688,"left":2,"top":2}).html($(".page").children(".info").html());
				
				$("#"+id).children(".blogpost").children(".image").children(".left").children(".image_1").delay(delay_time+200).animate({"opacity":0},speed*.2).delay(0).animate({"height":0},speed*.2);
				$("#"+id).children(".blogpost").children(".image").children(".left").children(".image_2").delay(delay_time+100).animate({"opacity":0},speed*.2).delay(0).animate({"height":0},speed*.2);
				$("#"+id).children(".blogpost").children(".image").children(".image_3").delay(delay_time).animate({"opacity":0},speed*.2).delay(100).animate({"height":background_height},speed*.2);
				$("#"+id).delay(0+(speed*.5)).children(".blogpost").children(".info").animate({"opacity":1},speed*.5,function() {
					// setLoadingState(false);
					btnReady();	
				}); 
				delay_time = 0;
			}	
			else if ($("#"+id).children(".blogpost").children(".info").hasClass("vierblokken"))
			{
				$("#"+id).children(".blogpost").children(".info").delay(delay_time).animate({"opacity":0}, speed, function() {
					$(".page").append("<div class=\"hidden post_info\">"+$(this).html()+"</div>");
					$(this).css({"width":688,"left":2,"top":2}).html($(".page").children(".info").html());
					$(this).delay(delay_time+200).animate({"opacity":1}, speed, function() {
						//setLoadingState(false);
						btnReady();
					});
				});
				$("#"+id).children(".blogpost").children(".image").children(".left").children(".image_1").delay(delay_time).animate({"opacity":0},speed*.2).delay(speed*.2).animate({"height":0},speed);
				$("#"+id).children(".blogpost").children(".image").children(".left").children(".image_2").delay(delay_time+100).animate({"opacity":0},speed*.2).delay(speed*.2).animate({"height":0},speed);
				$("#"+id).children(".blogpost").children(".image").children(".left").children(".image_3").delay(delay_time+200).animate({"opacity":0},speed*.2).delay(speed*.2).animate({"height":0},speed);
				$("#"+id).children(".blogpost").children(".image").children(".left").children(".image_4").delay(delay_time+300).animate({"opacity":0},speed*.2).delay(speed*.2).animate({"height":background_height-14},speed);
				$("#"+id).children(".blogpost").children(".background").delay(delay_time).animate({"left":-1,"width":1}, speed*.4).delay((speed*.4)).animate({"height":background_height,"opacity":1},10).animate({"left":2,"width":688}, speed);
				delay_time = 0;
			}
			$.each($(".page").children(),function() {
				if ($(this).hasClass("image"))
				{
					if ($(this).children(".een_image").html())
					{
						if ($(".page").children(".infofirst").html() == "1")
						{
							$("#blog").css({"position":"absolute","top":83});
							$(".page").children(".image").css({"position":"absolute","top":background_height+12});
							ypos = background_height+12+parseInt($(".page").children(".image").children(".height").html())+12;
							$(".page").children(".makingof").css({"top":ypos});
							$(".page").height(ypos+$(".page").children(".makingof").height());
						}
						var width = $(this).children(".width").html();
						var height = $(this).children(".height").html();
						var img_div = this;
						$(this).children(".een_image").animate({"height":height}, speed, function()
						{
							if ($(img_div).children(".vimeo").html().substr(0,7) == "http://")
							{
								var vimeo = "<iframe src=\""+$(img_div).children(".een_image").html()+"\" width=\""+width+"\" height=\""+height+"\" frameborder=\"0\"></iframe>";
								$(img_div).children(".een_image").html(vimeo);
							}
						});
					}
				} 
				else if ($(this).hasClass("makingof"))
				{
					$("#content").append("<div class=\"makingof\">"+$(this).html()+"</div>");
					$(this).remove();
					var loaded=0;
					$.each($(".load_image"),function() {
						if ($(this).parent().children(".src").html())
						{
							var _url = $(this).parent().children(".src").html();
							if (_url.substr(0,7) == "http://")
							{
								var _image = $("<img>");
								_image.load(function() {
									$(this).parent().css({"opacity":0}).delay(450+(loaded*100)).animate({"opacity":1},250);
									$(this).parent().height(_image.height());
									$(".page").height(ypos+$(".page").children(".makingof").height());
									loaded++;
								});
								$(this).html(_image);
								_image.attr('src',_url);
							} 
							else
							{
								$(this).parent().css({"opacity":0}).delay(250+(loaded*100)).animate({"opacity":1},250);
							}
						}
					});
				}
				else
				{
					$(this).addClass("hidden");
				}
			});
			$(".page").removeClass("hidden");
		}
		else if (direct || inanimate || $(".page").children(".path").html() == document.location.hash.substr(1))
		{
			if ($(".page").children(".infofirst").html() == "1")
			{
				var detached = $(".page").children(".image").detach();
				detached.appendTo($(".page"));
				if ($(".page").children(".makingof").children().length)
				{
					detached = $(".page").children(".makingof").detach();
					detached.appendTo($(".page"));
				}
			}
			if ($(".page").children(".image").children(".vimeo").html().substr(0,7) == "http://")
			{
				var vimeo = "<iframe src=\""+$(".page").children(".image").children(".vimeo").html()+"\" width=\""+$(".page").children(".image").children(".width").html()+"\" height=\""+$(".page").children(".image").children(".height").html()+"\" frameborder=\"0\"></iframe>";
				$(".page").children(".image").children(".vimeo").css({"opacity":0,"height":$(".page").children(".image").children(".height").html()}).delay(240).css({"opacity":1});
				$(".page").children(".image").children(".vimeo").html(vimeo);
			}
			var pos = $(".page").children(".info").offset();
			var parent_pos = $(".page").offset();
			if (pos && parent_pos)
			{
				$(".page").children(".background").css({"left":pos.left-parent_pos.left+1,"top":pos.top-parent_pos.top+1});
				$(".page").children(".background").height($(".page").children(".info").height());
				$(".page").children(".background").width($(".page").children(".info").width());
				var ypos = pos.top-parent_pos.top+1+$(".page").children(".info").height()+12;
				if ($(".page").children(".infofirst").html() == "1")
				{
					$(".page").children(".image").css({"position":"absolute","top":ypos});
					ypos += parseInt($(".page").children(".image").children(".height").html())+12;
					$(".page").children(".makingof").css({"top":ypos});
					$(".page").height(ypos+$(".page").children(".makingof").height());
				}
				else
				{
					$(".page").children(".makingof").css({"top":ypos});
					$(".page").height(ypos+$(".page").children(".makingof").height());
				}
			}
			loaded = 0;
			$.each($(".load_image"),function() {
				var _url = $(this).parent().children(".src").html();
				if (_url.substr(0,7) == "http://")
				{
					var _image = $("<img>");
					_image.load(function() {
						$(this).parent().css({"opacity":1});
						$(this).parent().height(_image.height());
						$(".page").height(ypos+$(".page").children(".makingof").height());
						loaded++;
					});
					$(this).html(_image);
					_image.attr('src',_url);
				} else
				{
					$(this).parent().css({"opacity":1});
				}
			});
			// setLoadingState(false);
			placed = true;
		}
		else 
		{
			// REMOVEMENT OF THE SINGLE PAGE
			if (firefox) 
			{
				$(".page").children(".image").children(".vimeo").html("&nbsp;");
			}
			
			$("#blog").css({"top":0,"position":"relative"});
			$(".page").delay(speed*.4).animate({"height":0},speed,function() {
				$(".page").each(function() { $(this).remove(); });
				$(".makingof").each(function() { $(this).remove(); });
				if ($("#"+last_opened_blog[0]).hasClass("disactive"))
				{
					$("#"+last_opened_blog[0]).children(".blogpost").children(".info").animate({"opacity":0},"fast",function(){ $(this).parent().parent().remove(); });
				}
			});
			if ($("#"+last_opened_blog[0]).children().length)
			{
				var pos = $("#"+last_opened_blog[0]).children(".blogpost").children(".info").offset();
				if (path == "#/about/")
				{
					$('html,body').animate({scrollTop: 0}, 600);
				} else 
				{
					$('html,body').animate({scrollTop: last_opened_blog[2]-120}, 600);
				}
				if (pos) 
				{
					var height = $("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".een_image").children("img").height();
					$("#"+last_opened_blog[0]).children(".blogpost").children(".info").html($(".page").children(".post_info").html());
					if ($("#"+last_opened_blog[0]).children(".blogpost").children(".info").hasClass("tekstrechts"))
					{
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".een_image").animate({"height":height},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".background").animate({"top":last_opened_blog[1].top,"height":last_opened_blog[1].height},speed, function()
						{
							$("#"+last_opened_blog[0]).children(".blogpost").children(".info").css({"top":last_opened_blog[1].top,"width":last_opened_blog[1].width,"left":last_opened_blog[1].left});
							$("#"+last_opened_blog[0]).children(".blogpost").children(".background").animate({
								"top":last_opened_blog[1].top,"height":last_opened_blog[1].height,"width":last_opened_blog[1].width,"left":last_opened_blog[1].left
							}, speed);
							$("#"+last_opened_blog[0]).children(".blogpost").children(".info").animate({"opacity":1},speed);
							btnReady();
						});
					}
					else if ($("#"+last_opened_blog[0]).children(".blogpost").children(".info").hasClass("drieblokken"))
					{
						var height = 124;
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".left").children(".image_1").delay(delay_time).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".left").children(".image_2").delay(delay_time+100).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".image_3").delay(delay_time+200).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".background").animate({"top":last_opened_blog[1].top,"height":last_opened_blog[1].height},speed, function()
						{
							$("#"+last_opened_blog[0]).children(".blogpost").children(".info").css({"top":last_opened_blog[1].top,"width":last_opened_blog[1].width,"left":last_opened_blog[1].left});
							$("#"+last_opened_blog[0]).children(".blogpost").children(".background").animate({ "opacity":.0,
								"top":last_opened_blog[1].top,"height":last_opened_blog[1].height,"width":last_opened_blog[1].width,"left":last_opened_blog[1].left
							}, speed*.5);
							$("#"+last_opened_blog[0]).children(".blogpost").children(".info").animate({"opacity":1},speed);
							btnReady();
						});
					}
					else if ($("#"+last_opened_blog[0]).children(".blogpost").children(".info").hasClass("vierblokken"))
					{
						var height = 190;
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".left").children(".image_1").delay(delay_time).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".left").children(".image_2").delay(delay_time+100).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".left").children(".image_3").delay(delay_time+200).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".image").children(".left").children(".image_4").delay(delay_time+300).animate({"height":height},speed*.2).delay(speed*.2).animate({"opacity":1},speed);
						//$("#"+last_opened_blog[0]).children(".blogpost").children(".background").delay(delay_time).animate({"left":-1,"width":1}, speed*.4).delay((speed*.4)).animate({"height":height},10).animate({"left":2,"width":688}, speed);
						$("#"+last_opened_blog[0]).children(".blogpost").children(".background").animate({"top":last_opened_blog[1].top,"height":last_opened_blog[1].height},speed, function()
						{
							$("#"+last_opened_blog[0]).children(".blogpost").children(".info").css({"top":last_opened_blog[1].top,"width":last_opened_blog[1].width,"left":last_opened_blog[1].left});
							$("#"+last_opened_blog[0]).children(".blogpost").children(".background").animate({ "opacity":.9,
								"top":last_opened_blog[1].top,"height":last_opened_blog[1].height,"width":last_opened_blog[1].width,"left":last_opened_blog[1].left
							}, speed);
							$("#"+last_opened_blog[0]).children(".blogpost").children(".info").animate({"opacity":1},speed);
							btnReady();
						});
					}
				}
				
			}
		}		
	}	
	$("#footer").removeClass("hidden");
	var speed = 220;
	if (!placed)
	{
		$.each($(".blogpost"),function() {
			var pos = $(this).children(".info").offset();
			var parent_pos = $(this).offset();
			if (pos)
			{
				if (pos.left)
				{
					if ($(this).parent().attr("id").indexOf("about") > -1 || $(this).parent().attr("id").indexOf("about") > -1 || direct || inanimate)
					{
						if ($(this).children(".info").hasClass("tekstlinks"))
						{
							$(this).children(".info").css({"height":$(this).height()-4});
							$(this).children(".info").children(".margin").children(".address").css({"bottom":18,"left":12});
						}
						if (!ie)
						{
							if ($(this).children(".background").width() < 10)
							{
							
								$(this).children(".background").height($(this).children(".info").height());
								$(this).children(".background").width($(this).children(".info").width());
								$(this).children(".background").css({"left":pos.left-parent_pos.left,"top":pos.top-parent_pos.top});
								if ($(this).children(".info").hasClass("drieblokken")) $(this).children(".background").css({"opacity":0});
							}
						}
						if (!inanimate) $(this).parent().hide();
					}
				}
			}
			
			if ($(this).parent().attr("id") == "about_2")
			{
				loaded = 0;
				$.each($(".load_image"),function() {
					if ($(this))
					{
						var _url = $(this).parent().parent().children(".src").html();
						if (_url)
						{
							if (_url.substr(0,7) == "http://")
							{
								var _image = $("<img>");
								_image.load(function() {
									$(this).parent().css({"opacity":0}).delay(450+(loaded*100)).animate({"opacity":1},250);
									loaded++;
								});
								$(this).html(_image);
								_image.attr('src',_url);
							} 
							else
							{
								$(this).parent().parent().css({"opacity":0}).delay(250+(loaded*100)).animate({"opacity":1},250);
							}
						}
					}
				});
			}
			if (!$(this).parent().hasClass("disactive"))
			{
				if ($(this).parent().hasClass("animate"))
				{
					$(this).parent().removeClass('animate');

					// ANIMATE DIFFERENT BLOG POSTS
					var left = pos.left-parent_pos.left;
					var height = $(this).children(".image").height();
					if ($(this).children(".info").hasClass("tekstrechts"))
					{
						$(this).children(".info").css({"left":left+250}).delay(delay_time+speed*.5).animate({"left":left}, speed); 
						$(this).children(".background").css({"left":left+250}).delay(delay_time).animate({"left":left}, speed);
						$(this).children(".image").css({"opacity":.0}).delay(delay_time).animate({"opacity":1},speed*.5);
						delay_time+=200;
					}
					else if ($(this).children(".info").hasClass("drieblokken"))
					{
						$(this).children(".info").css({"left":left-250}).delay(delay_time+speed*.5+180).animate({"left":left}, speed); 
						$(this).children(".background").css({"left":left-250}).delay(delay_time+180).animate({"left":left,"opacity":0}, speed);
						$(this).children(".image").css({"opacity":.0}).delay(delay_time).animate({"opacity":1},speed*.5);
						$(this).children(".image").children(".left").children(".image_1").css({"opacity":.0}).delay(delay_time).animate({"opacity":1},speed*2);
						$(this).children(".image").children(".left").children(".image_2").css({"opacity":.0}).delay(delay_time+80).animate({"opacity":1},speed*2);
						$(this).children(".image").children(".image_3").css({"opacity":0}).delay(delay_time+160).animate({"opacity":1},speed*.8);
						delay_time+=400;
					}	
					else if ($(this).children(".info").hasClass("vierblokken"))
					{
						$(this).children(".info").css({"left":left-350}).delay(delay_time+speed*.5+240).animate({"left":left}, speed); 
						$(this).children(".background").css({"left":left-350}).delay(delay_time+240).animate({"left":left}, speed);
						$(this).children(".image").children(".left").children(".image_1").css({"opacity":0}).delay(delay_time).animate({"opacity":1},speed*2);
						$(this).children(".image").children(".left").children(".image_2").css({"opacity":0}).delay(delay_time+80).animate({"opacity":1},speed*2);
						$(this).children(".image").children(".left").children(".image_3").css({"opacity":0}).delay(delay_time+160).animate({"opacity":1},speed*2);
						$(this).children(".image").children(".left").children(".image_4").css({"opacity":0}).delay(delay_time+240).animate({"opacity":1},speed*2);
						delay_time+=400;
					}
					else if ($(this).children(".info").hasClass("tekstlinks"))
					{
						$(this).children(".info").css({"left":left-250}).delay(delay_time+speed*.5).animate({"left":left}, speed); 
						$(this).children(".background").css({"left":left-250}).delay(delay_time).animate({"left":left}, speed);
						$(this).children(".image").css({"opacity":.0}).delay(delay_time).animate({"opacity":1},speed*.5);
						delay_time+=200;
					}
					$(this).parent().slideDown("fast").css({"opacity":1});
				}
				else
				{
					$(this).parent().slideDown("fast").css({"opacity":1});
				}
			}
		});
		$.each($(".clientpost_item"),function() {
			$(this).css({"display":"none"});
			$(this).slideDown("fast").css({"opacity":1});
			
			if ($(this).children(".image").children().length > 0)
			{
				var width = $(this).children(".image").children(".width").html();
				var height = $(this).children(".image").children(".height").html();
				var img_div = $(this).children(".image");
				$(this).children(".image").animate({"height":height}, speed, function()
				{
					if ($(img_div).children(".vimeo").html().substr(0,7) == "http://")
					{
						var vimeo = "<iframe src=\""+$(img_div).children(".vimeo").html()+"\" width=\""+width+"\" height=\""+height+"\" frameborder=\"0\"></iframe>";
						$(img_div).html(vimeo);
					}
				});
			}
		});
	}	
	btnReady();
}
function btnReady() 
{
	$("#content").height("auto");
	
	$('.makingof a').lightBox();
	$('.lightbox_image a').lightBox();
	$.each($(".blogpost"),function() {
		$(this).children(".share").height($(this).children(".info").height()-24);
	});
	$( ".single_image_btn" ).unbind().mouseover(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseout(function() {
		$(this).css({"background-position":"top"});
	}).mouseup(function() {
		previous = path;
		var id = $(this).attr("id").substr(1).split("-").join("+").split("_").join("/");
		window.location = create_link(id);
	});
	$( ".share_btn,.share_btn_post" ).unbind().mouseover(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseout(function() {
		$(this).css({"background-position":"top"});
	}).mouseup(function() {
		// SHARE SLIDER ----------------
		var blog = $(this).parent().parent().parent();
		$(this).css({"background-position":"bottom"});
		if ($(blog).children(".info").hasClass("tekstrechts") && $(this).hasClass("share_btn"))
		{
			var pos = $(blog).children(".info").offset();
			var parent_pos = $(blog).offset();
			$(blog).children(".share").css({"top":pos.top-parent_pos.top});
			if ($(blog).children(".share").css("left") == "598px")
			{
				$(blog).children(".background").animate({"left":pos.left-parent_pos.left+90,"width":$(blog).children(".info").width()},250);
				$(blog).children(".info").animate({"left":pos.left-parent_pos.left+90},250);
				$(blog).children(".share").animate({"left":692,"opacity":0},250);
			}
			else if ($(blog).children(".share").css("left") == "0px" || $(blog).children(".share").css("left") == "692px")
			{
				$(blog).children(".background").animate({"left":pos.left-parent_pos.left-90,"width":$(blog).children(".info").width()+90},250);
				$(blog).children(".info").animate({"left":pos.left-parent_pos.left-90},250);
				$(blog).children(".share").css({"left":692,"opacity":0,"display":"block"}).animate({"left":598,"opacity":1},250);
			}
		}
		else
		{
			if ($(blog).children(".info").children(".margin").children("a").children(".twitter_btn").css("display") == "none" || $(blog).children(".info").children(".margin").children("a").children(".twitter_btn").css("opacity") == 0)
			{
				$(blog).children(".info").children(".margin").children("a").children(".twitter_btn").css({"width":0,"display":"block"}).animate({"width":22,"opacity":1},80);
				$(blog).children(".info").children(".margin").children("a").children(".facebook_btn").css({"width":0,"display":"block"}).delay(60).animate({"width":22,"opacity":1},80);
			}
			else
			{
				$(blog).children(".info").children(".margin").children("a").children(".twitter_btn").animate({"width":0,"opacity":0},80);
				$(blog).children(".info").children(".margin").children("a").children(".facebook_btn").delay(60).animate({"width":0,"opacity":0},80);
			}
		}
		// -----------------------------
	});
	$( ".facebook_btn" ).unbind().mouseover(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseout(function() {
		$(this).css({"background-position":"top"});
	});
	
	$( ".twitter_btn" ).unbind().mouseover(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseout(function() {
		$(this).css({"background-position":"top"});
	});
	$( ".back_btn" ).unbind().mouseover(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseout(function() {
		$(this).css({"background-position":"top"});
	}).mouseup(function() {
		if (!loading)
		{
			if (previous)
			{
				history.go(-1);	
			}
			else
			{
				previous = path;
				window.location = create_link("everything");
			}
		}
	});
	$( ".client #form" ).children(".input").unbind().mouseup(function(){
		document.getElementById("input_"+$(this).attr("id")).focus();
	});
	$.each($("#blog").children(),function() {
		if ($.browser.msie){this.style.removeAttribute('filter');}
	});
	
}

function loginClient()
{
	var request = "client="+$( "#input_client").attr("value")+"&&hash="+md5("!$3fix12395,43" + $( "#input_password").attr("value") + "ssa12_fafie");
	$.ajax({
		url: root+"/php/function/login.php",
		data: request,
		type: "POST",
		success: function(html) 
		{
			siteUpdate(html);
		}
	});
}

function updateValue(field)
{
	var name = $(field).attr("id");
	name = name.substr(6,name.length);
	var str = field.value;
	if (name == "password")
	{
		str = "";
		for (var i=0; i<field.value.length; i++) str += "*";
	}
	$( ".client" ).children( "#form" ).children( "#"+name ).children(".text").html(str);
}

function setLoadingState(state)
{
	
	if (state) {
		loading = true;
		$("#content").height(($("#content").height()+100)+"px");
		//$(".logo").children("img").attr("src","/core/files/images/wouw_logo_loading.gif");
	} else {
		loading = false;
		if (next)
		{
			if (next != path) siteUpdate(next);
			next = false;
		}
		//$(".logo").children("img").attr("src","/core/files/images/wouw_logo.png");		
	}
}

function create_link(p)
{
	if (inanimate) return root_path+p+"/";
	return root_path+"#/"+p+"/";
}

function in_array( what, where )
{
	var a=false;
	for(var i=0;i<where.length;i++){
	  if(what == where[i]){
	    a=true;
        break;
	  }
	}
	return a;
}
