		var current="";
		var currentImg="";
		var maxImg="";
		var galActivated = 0;
		var theImage = 2;
		var newsnr = "";
		var currentnews = 0;
		var projectnr = "";
		var currentproject = 0;
		var canactivate = 1;
		
		var hash2 = location.hash;
	
		var splot = hash2.split("-");
	
		// Page function
		function getPage(pagename){
 
 			if(pagename=="home") {
 		
 				$("#boxing").animate({"height": "0px"},1000,"swing");
 				$(".allround").fadeOut(0);
 		
 			} else {
 
 				if(current != pagename) { 
 			
 					$.ajax({
						url: "pages/handler.php?page="+pagename+"&serial="+splot[1],
 						async: false,
 						dataType: 'text',
 						success: function(data) {
 							$("#heightcalculator").delay(200).html(data);
							var contentHeight = $("#heightcalculator").height();
				
							$('#boxing').animate({"opacity":"0.0"},200,function(){
								$("#boxing").animate({"height": contentHeight+"px"},700,"swing",function(){
									$("#boxing").html(data);
									$('.explain p').scrollbar();
									$('.press').scrollbar();
									$('.guestbook').scrollbar();
									$('.portrait').scrollbar();
									$('.projects .item').scrollbar();
									$('.music').scrollbar();
									$('.gallery-scroll').scrollbar();
									$('.shop-scroll').scrollbar();
									$('.item .bericht').scrollbar();
									$('.tourlist .listing').scrollbar();
								}).animate({"opacity":"1.0"},500);
								
							});
							
 						}
					});
				}
			}
			
		}
		
		//enableGallery
		
		function enableGallery(pageID){
			if(pageID != "presspictures") {
				$('.gallery-btn').fadeOut(1000);
				var galActivated = 0;
				currentImg = 0;
				$('#normalloop').fadeIn(500);
				$('#gallery .back').html("");
				$('#gallery .front').html("");
				
			}
		
			if(pageID == "presspictures") {
			
							
				var pic = [];
				currentImg = 0;
				
				$('.pictures .thumb img').each(function(index) {
					pic.push($(this).attr('rel'));
				});
				makeBackground(pic[currentImg]);
				maxImg = pic.length-1;
				
				galActivated = 1;
				
				$('.pictures .thumb img').live('click',function(){
					var showPicture = $(this).attr('rel');
					currentImg = $(this).attr('sort');
					totheBackground(showPicture);
					
				});
				
				
				$('.gallery-prev').click(function() {
					if(currentImg == 0) {
						currentImg=maxImg;
					} else {
						currentImg--;
					}
					
					totheBackground(pic[currentImg]);
				});
				
				$('.gallery-next').click(function() {
					if(currentImg == maxImg) {
						currentImg=0;
					} else {
						currentImg++;
					}
					
					totheBackground(pic[currentImg]);
				});
				
			}
		}
		
		function totheBackground(bigPicture) {
					$('#loading').fadeIn(10);
					var thisPicture = "<img src='http://webapp.new-art.nl/content/img/gallery/"+bigPicture+".jpg' width='100%' />";
					$('#gallery .back').html(thisPicture).load();
					$('#gallery .front').delay(500).fadeOut(1000, function() {
						$('#gallery .front').html(thisPicture);
						$('#gallery .front').fadeIn(10);
						$('#loading').fadeOut(100);
					});
		}
		
		function makeBackground(bigPicture) {
			$('#background').html('<div id="gallery"><div class="front"><img src="http://webapp.new-art.nl/content/img/gallery/'+bigPicture+'.jpg" width="100%"/></div><div class="back"></div></div>');
			$('#normalloop').fadeOut(500);
			makeButtons();
		}
		
		function makeButtons() {
		
			$('.gallery-btn').html('<div class="gallery-prev"></div><div class="gallery-next"></div>');
			$('.gallery-btn').fadeIn(1000);
		
		}
		
		function normalBackground() {
		
			var backgrounds = [];
			backgrounds[1]="img/background1.jpg";
			backgrounds[2]="img/background2.jpg";
			backgrounds[3]="img/background3.jpg";
			backgrounds[4]="img/background4.jpg";
		
			$('#normalloop .second').html('<img src="'+backgrounds[theImage]+'">');
			$('#normalloop .first').fadeOut(1000,function() {
			
				theImage++;
				if(theImage==5){
					theImage=1;
				}
				$('#normalloop .first').html('<img src="'+backgrounds[theImage]+'">');
				$('#normalloop .first').delay(1000).fadeIn(2000);
			
			});
		}
	
	
		$(window).ready(function(){
		
		
        var theWindow        = $(window),
            $bg              = $("#normalloop"),
            aspectRatio      = $bg.width() / $bg.height();



        function resizeBg() {

                if ( theWindow.width() < theWindow.height()+300) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }

        }

        theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");

		
		
		
			
			$('#boxing').animate({"opacity":"0.0"});
			
			var timmeh = setInterval('normalBackground()', 8000);
			
			 	$('.videoprev .video-overlay').live('click',function(){
					var thisVideoId = $(this).attr('rel');
					
					$('.overlay-box .videoplace').html('<iframe width="560" height="349" src="http://www.youtube.com/embed/'+thisVideoId+'?autoplay=1" frameborder="0" allowfullscreen></iframe>');
					
					$('.overlay').fadeIn(1000, function() {
						$('.overlay-box').animate({"margin-top":"15%","top":"-170px"},1000,"swing");
					});
				});
				
				$('.close').live('click',function(){
					
					$('.overlay-box').fadeOut(1000);
					
					$('.overlay').fadeOut(1000, function() {
						$('.overlay-box').animate({"margin-top":"-389px"},10);
						$('.overlay-box').fadeIn(10);
						$('.overlay-box .videoplace').html("");
					});
					
					
				});
			
			
//			$('#wrapper').delay(200).animate({
//				"margin-bottom":"50px"
//			},1000,"swing");
			
			
			// Get the page (old)
//			$('#menu li a').click(function() {
//			
//				var pageID = $(this).attr("id");
//				
//				$('#menu li a.selected').removeClass("selected");
//				$(this).addClass('selected');
//				getPage(pageID);	
//				current = pageID;
//				enableGallery(pageID);
//				
//			});
			
		});
		
		
$(function(){
	$(window).hashchange( function() {
	var hash = location.hash;
	
	var splat = hash.split("-");

	//reset news and project when leaving page
	currentnews = 1;
	currentproject = 1;
	
	var pageName = splat[0].replace("#","");
	
	if(pageName == "") {
			$('#menu').css({"display":"none"});
			$('.intro').css({"display":"block"});
			
			$('.enter').click(function() {
				$('.intro').fadeOut(1000);
				activateMenu();
			});
			//alert('loadintro');
	
			//$('#wrapper').delay(200).animate({
			//	"margin-bottom":"50px"
			//},1000,"swing");

	} else {
		getPage(pageName);
		enableGallery(pageName);
		enableNews();
		enableProject();
		
		if(canactivate = 1) {
			//soundManager.unmute('Kim');
		}
	
		$('#menu li a.selected').removeClass("selected");
		
		if(pageName == "presspictures") {
			$('#menu li a#pictures').addClass("selected");
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"20px"
			},1000,"swing");
			
		} else if(pageName == "pictures") {
		
			$('#menu li a#pictures').addClass("selected");
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"20px"
			},1000,"swing");
			
		} else if(pageName == "picturearchive") {
		
			pictureArchive();
		
			$('#menu li a#pictures').addClass("selected");
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"20px"
			},1000,"swing");
		
		} else if(pageName == "live") {
		
			pictureArchive();
		
			$('#menu li a#pictures').addClass("selected");
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"20px"
			},1000,"swing");
		
		}else if(pageName == "video") {
			
			soundManager.mute('Kim');
			getFirstVid();
			
			$('#menu li a#'+hash).addClass("selected");	
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"50px"
			},1000,"swing");
		
		}else if(pageName == "tour") {
		
			tourActivate();
			
			$('#menu li a#'+hash).addClass("selected");	
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"50px"
			},1000,"swing");
		
		}
		
		else if(pageName == "music") {
		
			soundManager.mute('Kim');
			
			$('#menu li a#'+hash).addClass("selected");	
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"50px"
			},1000,"swing");
		
		}else if(pageName == "news") {
		
			soundManager.mute('Kim');
			
			$('#menu li a#'+hash).addClass("selected");	
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"50px"
			},1000,"swing");
		
		}else {
			$('#menu li a#'+hash).addClass("selected");	
			
			$('#wrapper').delay(200).animate({
				"margin-bottom":"50px"
			},1000,"swing");
			
		}
		
	}

});

	$(window).hashchange();

});

function enableNews() {

var newsHash = location.hash
var hak = newsHash.split("-");
	

currentnews=0;


	$('.shownews').live('click', function() {
	
		newsnr = $(this).attr('rel');
		
		if(currentnews==newsnr) {
		
		} else {
		
			$('.news-0, .news-1, .news-2, .news-3, .news-4').fadeOut(0, function() {
				$('.news-'+newsnr).fadeIn(1000);
				currentnews = newsnr;
				
				$('.item .bericht').scrollbar();
			});
		
		}
		
	
	});
	

}

function enableProject() {

currentproject=0;
			
	$('.showproject').live('click', function() {
	
		projectnr = $(this).attr('rel');
		
		if(currentproject==projectnr) {
		
		} else {
		
			$('.project-'+currentproject).fadeOut(0, function() {
				$('.project-'+projectnr).fadeIn(1000);
				currentproject = projectnr;
				$('.projects .item').scrollbar();
				
			});
		
		}
		
	
	});
	

}

function pictureArchive() {
	var afb = [];
	currentAfb = 0;
				
				$('.normal-gallery .thumb img').each(function(index) {
					afb.push($(this).attr('rel'));
				});
				
				$('.normal-gallery .thumb img').live('click',function(){
					var pushImg = $(this).attr('rel');
						$('.normal-gallery .thumb img.selected').removeClass('selected');
						$(this).addClass('selected');
						$('.pictureplace').html("<img src='http://webapp.new-art.nl/content/img/gallery/"+pushImg+".jpg' width='100%' />");
				});
				
				
}


	function totheBox(id) {	
	}
	
function openVideo(id) {

				placeVid(id);

}

function getFirstVid() {
				var vid = [];
				$('.videos .thumb').each(function(index) {
					vid.push($(this).attr('vidid'));
				});
		}
		
function placeVid(id) {
					$.ajax({
						url: "pages/getVideo.php?videoid="+id+"",
 						async: false,
 						dataType: 'text',
 						success: function(data) {
 						
 							$('.top-video').html(data);
 							
 						}
 						
 						});
 						
 						$('.explain p').scrollbar();
 										
	}

var currentTour = 1;

function tourActivate() {
currentTour = 1;
}

function nextTour() {
//	if(currentTour == 2) {
//		currentTour=1;
//		$('.tourlist').animate({"margin-left":"0px"});
//	} else {
//		$('.tourlist').animate({"margin-left":"+=-400px"});
//	}

	if(currentTour == 1) {
	
	} else {
		$('.tourlist').animate({"margin-left":"0px"});
		currentTour = 1;
	}

}

function previousTour() {
//	if(currentTour == 1) {
//		currentTour=2;
//		//$('.tourlist').animate({"margin-left":"-400px"});
//	} else {
//		$('.tourlist').animate({"margin-left":"-400px"});
//	}
	if(currentTour == 1) {
		$('.tourlist').animate({"margin-left":"-400px"});
		currentTour = 2;
	} else {
		
	}
}

function seeDetail(serial) {
					$.ajax({
						url: "pages/tourdetail.php?serial="+serial+"",
 						async: false,
 						dataType: 'text',
 						success: function(data) {
 						
 							$('.overlay-box .videoplace').html(data);
 							$('.overlay').fadeIn(1000, function() {
								$('.overlay-box').animate({"margin-top":"15%","top":"-170px"},1000,"swing");
							});
 							
 						}
 						
 					});
}

function addGuestbook() {
 						
 							$('.overlay-box .videoplace').html("<iframe src='http://www.kimhoorweg.com/pages/handler.php?page=addmessage' width='560px' height='265px' frameborder='0'></iframe>");
 							$('.overlay').fadeIn(1000, function() {
								$('.overlay-box').animate({"margin-top":"15%","top":"-170px"},1000,"swing");
							});
}

function activateMenu() {
		$('#menu').fadeIn(1000, function () {});
			$('#wrapper').delay(200).animate({
				"margin-bottom":"50px"
			},1000,"swing");
		
			
			
}
