$(document).ready(function() {
	
	$("#group .nav li")
	.click(function() {
	    if ($(this).attr("id") == 'produktkonfigurator') return true;
	
		// Deactivate all menuitems and hide all areas
		$("#group .nav li").removeClass("active");
		$("#group .secondary .area").hide().stop();
		
		// Activate current nav item and show the area with the same ID
		$(this).addClass("active");
		var content = $("#group .secondary #section-" + $(this).attr("id"));
		content.fadeIn(250);
		$(document).scrollTop(content.offset().top);
		
	})
	.mouseover(function() {
		$(this).addClass("hover");
	})
	.mouseout(function() {
		$(this).removeClass("hover");
	});
	
	$("div.price").each(function() {
		
		var popup 			= $("#" + $(this).attr("class") + "-popup");

		$(this)
		.mouseover(function() {
			$(this).append(popup);
			popup.show();
		})
		.mouseout(function() {
			popup.hide();
		});	
	})
		
		
	// All input fields assigned with the class 'default' will
	// get their default values hidden when clicked, and reset again
	// if the user leaves the field empty or hasnt changed anything
	// The searchfields needs an accompanying hidden input with the
	// same id but suffixed "-default" that contains the default value.
	$("input.default").each(function() {
		var defaultVal = $(this).next(".defaultvalue").val();
		if (!$(this).val())
			$(this).val(defaultVal);
		$(this).focus(function() {
			if ($(this).val() == defaultVal)
				$(this).val("");
		});
		$(this).blur(function() {
			if ($(this).val() == "")
				$(this).val(defaultVal);
		});
	});

	// Hook up the searchbox
	$("#search .button a").click(function() {
		var url = $(this).attr("href");
		url += "?query=" + encodeURIComponent($("#search .searchfield").val());
		document.location = url;
		return false;
	});
	$("#search .searchfield").keydown(function(e) {
		if (e.keyCode == 13) {
			$("#search .button a").click();
			return false;
		}
	});
});
