function overlayShowForm( n ) {
	$('#overlay1').find(".prefaction").hide();
	$('#overlay1').find("#form"+n).show();
}

$(window).load(function() {
	$('#slider').nivoSlider({
		controlNavThumbs: true,
		controlNavThumbsReplace: '.jpg',
		pauseTime:9000
	});

	// Submenu
	if ( $('#header .submenu ul li').length > 0 ) {
		if ( $.browser.msie ) {
			$('#header .submenu ul li').each(function(){
				$(this).replaceWith($('<dt>'+this.innerHTML+'</dt>'));
			})
			$('#header .submenu ul').replaceWith($('<dl>'+$('#header .submenu ul').html()+'</dl>'));
			$('#header').addClass("submenu");
			var width = 0;
			$('#header .submenu').show();
			$('#header .submenu dl dt').each(function(){
				width += $(this).outerWidth();
			});
			if ( width > $('#header .submenu').width() ) {
				$('#header').addClass("tworows");
			}
		} else {
			$('#header').addClass("submenu");
			var width = 0;
			$('#header .submenu').show();
			$('#header .submenu ul li').each(function(){
				width += $(this).outerWidth();
			});
			if ( width > $('#header .submenu').width() ) {
				$('#header').addClass("tworows");
			}
		}
	}
	
	$('.blimedlem').overlay({
		fixed: false,
		mask: {
			color: '#ebecff',
			loadSpeed: 200,
			opacity: 0.7
		},		
		//top: "2%",
		closeOnEsc: false,
		closeOnClick: false,
		onBeforeLoad: function() {
			var $overlay = this.getOverlay();
			$overlay.find("input[type=text],select,textarea").val("");
			$overlay.find("input[type=radio]:first").attr("checked",true);
			$overlay.find(".error").removeClass("error");
			$overlay.find(".form").hide();
			$overlay.find(".sending").hide();
			$overlay.find(".sent").hide();
			$overlay.find(".close").show().attr("title","Lukk");
			$overlay.find(".prefaction").show();
		},
		onLoad: function() {
			var $overlay = this.getOverlay();
			this.getOverlay().find(":input:first").focus();
		},
		onClose: function() {
		}
	});
	
	$('#overlay1 .closeform').click(function(){
		$('.blimedlem').data("overlay").close();
	});
	
	$('#overlay1 form').submit(function(){
		$(this).find("input,textarea,select").each(function(){
			if ( !$(this).hasClass("required") )
				return;
			if ( $(this).is(":button,:submit") )
				return;
			if ( $(this).val() == "" ) {
				$(this).addClass("error");
			} else {
				$(this).removeClass("error");
			}
		});
		if ( $(this).find(".error").length > 0 ) {
			return false;
		}
		
		$("#overlay1 .close").hide();
		$("#overlay1 .form").hide();
		$("#overlay1 .sending").show();
		$.post("formsubmit.php",$(this).serialize(),function(result){
			$("#overlay1 .sending").hide();
			if ( result ) {
				$("#overlay1 .sent").show();
			}
			else {
				$("#overlay1 .senderror").show();
			}
			setTimeout( function() { $('.blimedlem').data("overlay").close() }, 3500 );
		});		
		return false;
	});
	
});
