$(window).load(function() {
	if($("#refs").length > 0) {
		$("#loading").hide();
		$("#refs").show();
		aa = $("#refs").find("div");
		$(aa).css("opacity", "0.4");
		aa.hover(function() {
			$(this).css("opacity", "1");
		}, function() {
			$(this).css("opacity", "0.4");
		});
		$("#refs").movediv();
	}
	
});
$(document).ready(function() {
	$(":range").rangeinput();
	$("#accordion").accordion({
		event: "mouseover"
	});
	
	/*
	$("#rangeprod").onchange(function() {
		slider();
	});
	*/
	function fadeOut(what) {
		$(document.body).children("div").each(function(i) {
			if(i > 3) {
				idname = $(this).attr("id");
				if(idname != "overlay" && idname != "lightbox") {
					$(this).animate({"opacity": what}, 1000);
				}
			}
		});
	}
	$("#icon-menu a").click(function() {
		h = $(this).attr("href") +"?ajax=1";
		$("#subtplcontainer").slideUp(1000, function() {
			$.get(h, function(d) {
				//$("#subtpl").html($("#datainfo", d).html());
				$("#subtpl").html(d);
				$("#subtplcontainer").slideDown(1000);
				fadeOut(".2");
			});
		});
		
		return false;
	});
	$("#closesubtpl").click(function() {
		$("#subtplcontainer").slideUp(1000);
		fadeOut(1);
	});
	
	
	$("#contactclose").click(function() {
		$("#contactin").fadeOut(500, function() {
			$("#contactform").animate({"width":"0px"}, 500);
			$("#contactin").html("");
		});
		
	});
	$(".contactform").click(function() {
		$("#contactform").css("height", $(document.body).outerHeight());
		w = $(document).width();
		l = ((w - 990) / 2) + 250;
		var u = this.href;
		
		$("#contactform").animate({"width":l+"px"}, 800, function() {
			$.get(u, function(d) {
				$("#contactin").hide();
				$("#contactin").html($("#formform", d));
				$("#contactin").fadeIn(500);
				initForm();
			});
		});
		return false;
	});
	$("ul.menu li").hover(function() {
		$(this).children("ul").show();
		$(this).children("ul").css("zIndex", 10000);
	}, function() {
		$(this).children("ul").hide();
	});
	function initForm() {
		
		var options = { 
	        //target: $(this)
	          beforeSubmit:  initRequest
	        , success:       showResponse  // post-submit callback 
	    }; 
	    
	    $("form.mainform").ajaxForm(options); 
	    //$("form.mainform").each(function() {
		//	f = this;
		//	f.onsubmit = function() {
		//		postForm(f)
		//		return false;
		//	}
		//});
	}
	initForm();
	
	if($("#xiframe").length > 0) {
		
	}
	
	function initRequest(formData, jqForm, options) { 
		$(jqForm).animate({"opacity":0.5});
	}
	function showResponse(responseText, statusText, xhr, $form)  { 
		if($("#error", responseText).length > 0) {
        	$("#forminfo").html($("#error", responseText));
        	$("form.mainform").animate({"opacity":1});
        } else {
        	$("#forminfo").html($("#afsluiting", responseText));
        	$("form.mainform").hide();
        }
        
	}
	
	function postForm(f) {
		var fform = f;
		$(fform).animate({"opacity":.5}, function() {
			$(fform).ajaxSubmit({
			    // success identifies the function to invoke when the server response
		        // has been received; here we apply a fade-in effect to the new content
		        success: function(d) {
		        	
		            if($("#error", d).length > 0) {
		            	$("#forminfo").html($("#error", d));
		            	$(fform).animate({"opacity":1});
		            } else {
		            	$("#forminfo").html($("#afsluiting", d));
		            	$(fform).hide();
		            }
		            document.location.hash = "#topoftheform";
		        }
			});
		})	;
	}
	
});


function activeTab(w) {
	p = $(w).parent("ul");
	pli=  p.find("li");
	pli.removeClass("halfactive");
	pli.removeClass("active");
	$(w).addClass("active");
	
	i = $(w).index();
	if(i > 0) {
		pli.eq(i-1).addClass("halfactive");
	}
	
	if(i < pli.length) {
		pli.eq(i+1).addClass("halfactive");
	}
}
