$(function() {
	    var newHash      = "",
        $mainContent = $("#text-content"),
        $pageWrap    = $("#wrapper"),
        baseHeight   = 0,
        $el;

	$(document).ready(function() {
		baseHeight = $pageWrap.height() - $mainContent.height();
	    
	    $("a[href^='/']").click( function() {
	        window.location.hash = $(this).attr("href");
	        $("a.active").removeClass("active");
	        $(this).addClass("active");
	        Cufon.refresh();
	        return false;
	        
	    });
	    /*
	    $("#nav, #content, #subnav").delegate("a[href^='/']", "click", function() {
	        window.location.hash = $(this).attr("href");
	        $("a.active").removeClass("active");
	        $(this).addClass("active");
	        Cufon.refresh();
	        return false;
	        
	    });
	    */
    });
    function bindA(){
	    $("#text-content a[href^='/']").click(function() {
	        window.location.hash = $(this).attr("href");
	        $("a.active").removeClass("active");
	        $(this).addClass("active");
	        Cufon.refresh();
	        return false;
	    });
    }
    
    $(window).bind('hashchange', function(){
    
        newHash = window.location.hash.substring(1);
        if (newHash) {
        	$("#nav .active").removeClass("active");
        	$("#nav a[href='"+newHash+"']").parent().addClass("active");

	        	$mainContent.load(newHash + " #inner-content ", function() {
	        		$("#content-wrapper").show();
					$('#text-content').animate({marginTop:0}, 1000);
					
					$('.close').click(function(){
						$('#text-content').animate({marginTop:306}, 1000,function(){
							$("#content-wrapper").hide();	
						});
						
					});
        			bindA();	
	                Cufon.refresh();
					
					if(newHash=="/contact.html"){
						$("#contactform").validate()	
					}
					
					$('.fancybox').fancybox();
						$('a[rel="fancybox"]').fancybox();
					
					$(".video").click(function() {
						$.fancybox({
								'padding'		: 0,
								'autoScale'		: false,
								'transitionIn'	: 'none',
								'transitionOut'	: 'none',
								'title'			: this.title,
								'width'		: 680,
								'height'		: 495,
								'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
								'type'			: 'swf',
								'swf'			: {
									 'wmode'		: 'transparent',
									'allowfullscreen'	: 'true'
								}
							});
					
						return false;
					});

					
					if(newHash=="/vanaf-utrecht.html" || newHash=="/vanaf-den-haag.html" || newHash=="/vanaf-rotterdam.html"){
						load();
					}
					
		        });

        };
        
    });
    
    $(window).trigger('hashchange');

});
