
	var inDesign = true;
	
	$(document).ready(function() {
		//DOM loaded, setup first screen.
		$.validator.setDefaults({
			submitHandler: function(){ 
				return;  //precaution for ie6 return errors
			}
		});
		var rand = Math.random(2000); //fix for IE caching
		$("#booking .ajaxLoaded").hide();
		$.ajax({
			type: "GET",
			url: "resources/ajax/booking.form.php?"+rand,
			success: function(result) {
				$("#booking .ajaxLoaded").html(result);
				$("#booking .ajaxLoaded").fadeIn(400);
				$('#booking select').selectbox();
			}
		});
		$("#calculator .ajaxLoaded").hide();
		
		$.ajax({
			type: "GET",
			url: "resources/ajax/calculator.ajax.php?"+rand,
			success: function(result) {
				$("#calculator .ajaxLoaded").html(result);
				$("#calculator .ajaxLoaded").fadeIn(400);
			}
		});

		//document loaded, fire!
		localUrl("#main");
		localUrl("#logo");
		var check = detectRedirect();
		if (check) loadPage(check);
		else loadPage("home.html");
	});
	
	/* select replacer */
	
	/* end select replacer */
	
	function detectRedirect()
	{
		//used in relation with detect.js
		var url = window.location.href.split("?");
		if (url[1]) return url[1];
		else return false;
	}
	
	function localUrl(div)
	{
		//capture all local links and handle with ajax
		$(div+" a").click(function() {
			var url = $(this).attr("href");
			var host = window.location.host;
			var path = window.location.pathname;
			if (!url.match(/http/) && !url.match(/mailto/)) {
				url = "http://"+host+path+url;
			}
			if (url.indexOf(host) >= 0 && url.indexOf("#") < 0) {
				loadPage(url);
				return false;
			} else {
				return;
			}
			return false;
		});
	}
	
	function loadPage(url) 
	{
		url = url;// + "?" + Math.random(99999);
		//TODO: remove me
		//loads page content from html source		
		$("#content .inner").fadeOut(400,function(){
			$.get(url, function(data){
				$("#content .inner").html(data);
				$("#content .inner").append("<imput type='hidden' value='1' id='virtualbufferupdate' name='virtualbufferupdate'/>");
				
				localUrl("#content .inner");
				subNav(url);
				$("#content .inner").fadeIn(400);
				var height = parseInt($("#content .inner").height());
				if (height > 400 && url.indexOf("home.html") < 0) {
					$("#main_image").slideUp("slow");
					$("#content").animate({height: 592}, "slow");
				} else {
					$("#main_image").slideDown("slow");
					$("#content").animate({height: 280}, "slow");
				}
				
				$("#content").get(0).tabIndex = -1;
				$("#content").get(0).focus();
			});
		});
	}
	
	function subNav(url)
	{
		//make current item bold if a subnav exists
		$(".subNavigation li:last").css("border-right","none");
		var host = window.location.host;
		var path = window.location.pathname;
		$(".subNavigation li a[@href="+url+"]").css("fontWeight","bold"); //IE
		url = url.replace(/http:\/\//,"");
		url = url.replace(host,"");
		url = url.replace(path,"");
		$(".subNavigation li a[@href="+url+"]").css("fontWeight","bold"); //MOZ
	}
	
	function submitForm(form,swi)
	{
		$(form).find("input[@type=submit]").addClass("submitting");
		var action = $(form).attr("action");
		var params = $(form).fastSerialize();
		var json = $.toJSON(params);
		var into = $(form).parents("div.ajaxLoaded");
		$.post(action,{data: json},function(result){
			$(into).fadeOut(360,function(){
				$(into).html(result);
				$(into).append("<imput type='hidden' value='1' id='virtualbufferupdate' name='virtualbufferupdate'/>");
				$(into).fadeIn(600);
				$(into).get(0).tabIndex = -1;
				$(into).get(0).focus();
				
				if (!swi) $('#booking select').selectbox();
			});
		});
		return false;
	}
	
	function buttonForm(button)
	{
		$(button).addClass("submitting");
		var action = $(button).attr("rel");
		var into = $(button).parents("div.ajaxLoaded");
		$.get(action,function(result){
			$(into).fadeOut(360,function(){
				$(into).html(result);
				$(into).append("<imput type='hidden' value='1' id='virtualbufferupdate' name='virtualbufferupdate'/>");
				$(into).fadeIn(600);
				$(into).get(0).tabIndex = -1;
				$(into).get(0).focus();
				$('#booking select').selectbox();
			});
		});
	}
	
	$.fn.fastSerialize = function() {
	    var a = [];
	    $('input,textarea,select,button', this).each(function() {
	        var n = this.name;
	        var t = this.type;
	        if ( !n || this.disabled || t == 'reset' ||
	            (t == 'checkbox' || t == 'radio') && !this.checked ||
	            (t == 'submit' || t == 'image' || t == 'button') && this.form.clicked != this ||
	            this.tagName.toLowerCase() == 'select' && this.selectedIndex == -1)
	            return;
	        if (t == 'image' && this.form.clicked_x)
	            return a.push(
	                {name: n+'_x', value: this.form.clicked_x},
	                {name: n+'_y', value: this.form.clicked_y}
	            );
	        if (t == 'select-multiple') {
	            $('option:selected', this).each( function() {
	                a.push({name: n, value: this.value});
	            });
	            return;
	        }
	        a.push({name: n, value: this.value});
	    });
	    return a;
	};
