(function($){

	$.fn.zoeker = function(){
		return $(this).each(function(){
			var $obj = $(this);
			$obj.css("color","#a4a4a4");
			$obj.focus(function(){
				$obj.css("color","#5e5e5e");
				if($obj.val() == "zoeken")
				{
					$obj.val("");
				}
			}).blur(function(){
				
				$obj.css("color","#a4a4a4");
				if($obj.val() == "")
				{
					$obj.val("zoeken");
				}
				
			});
			var $form = $("#search_form");
			$form.submit(function(e){
				if(($obj.val() == "") || ($obj.val() == "zoeken"))
				{
					return false;
				}
			})
		});

	}
		
})(jQuery);

function getHash() {
	var hash = window.location.hash;
	if(hash.length < 2){
		return "";
	}
	return hash.substring(1);
}


function open_quoteform()
{
	$("#quote_form").slideDown(500);
}

function close_quoteform()
{
	$("#quote_form").slideUp(500);
}

$("document").ready(function(){
	$("#quote_form").hide();
	if($(".tour_page").length > 0){
		$("#content p").first().addClass("first_child");
	}
	if($(".sidebar_info").length > 0){
		$("#sidebar p").first().addClass("first_child");
	}
	$("#search_field").zoeker();
	$("#logo").click(function(){
		window.location = webRoot;
	});
	$("#offerte").click(function(e){
		e.preventDefault();
		open_quoteform();
	});
	
	if(getHash() == "offerte"){
		open_quoteform();
	}
	$(".page_block, .extra_block").last().addClass("last");
	$("#close_quoteform").click(function(){close_quoteform();});
	
	$("a").each(function(){
	
		var href = $(this).attr("href");
		href.substr()
		//alert(href.substr(0,webRoot.length));
		if((href.substr(0,webRoot.length) != webRoot) && (href.substr(0,7) == "http://"))
		{
			$(this).attr("target","_blank");
		}
	
	});
	
	if($("#the_quote_form").length > 0)
	{
		$("#the_quote_form").submit(function(){
			return submit_quote();
		});
		quote_form_actions();
	}
	
});

function submit_quote(){
	var name = $("#cust_name").val();
	var email = $("#cust_email").val();
	var message = $("#cust_message").val();
	var people = $("#cust_people").val();
	var extras = new Array();
	$(".extra_option:checked").each(function(){
		if(($(this).attr("disabled") != "disabled") && ($(this).attr("disabled") != true)){
			extras.push($(this).val());
		}
	});
	extras = extras.join(",");
	
	var error = false;
	
	if((name == "naam") || (name == "")){
		error = true;
		$("#cust_name").attr("style","color:#b60000");
	}
	if((email == "email") || (email == "")){
		error = true;
		$("#cust_email").attr("style","color:#b60000");
	}
	if((message == "Uw bericht en/of contact informatie.") || (message == "")){
		error = true;
		$("#cust_message").attr("style","color:#b60000");
	}
	
	if(error == true) return false;
	return true;
}

function quote_form_actions(){
	$("#cust_name").focus(function(){
		$(this).removeAttr("style");
		if($(this).val() == "naam"){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).removeAttr("style");
			$(this).val("naam");
		}else{
			$(this).attr("style","color:#575757;");
		}
	});
	
	$("#cust_email").focus(function(){
		$(this).removeAttr("style");
		if($(this).val() == "email"){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).removeAttr("style");
			$(this).val("email");
		}else{
			$(this).attr("style","color:#575757;");
		}
	});
	
	$("#cust_message").focus(function(){
		$(this).removeAttr("style");
		if($(this).val() == "Uw bericht en/of contact informatie."){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val() == ""){
			$(this).removeAttr("style");
			$(this).val("Uw bericht en/of contact informatie.");
		}else{
			$(this).attr("style","color:#575757;");
		}
	});
	
}




