﻿$(function () {
	$("#close-client").click(function(event){
		$("#clientcontainer").slideUp();
	});

	$(".portfolio-index h3").click(function (){
	    $(this).next().slideToggle();
	    //location.hash = $(this).next().find("a[name]").attr("name");
	});
	$(".portfolio-index > div").not(location.hash).hide();
	
	$(".mini-news-list, .portfolio-sidebar").cycle({
	    fx: "cover",
	    speed: 1000, 
        timeout: 5000,
        pause: 1
    });

	$(".photo_preview a").fancybox();
	
	$(".photo_preview:nth-child(3)").css("margin-right", 0);

	var hidden;

	hidden = document.createElement("input");
	hidden.setAttribute("type", "hidden");
	hidden.setAttribute("value", "mailing-form");
	hidden.setAttribute("name", "form-type");

	if (document.getElementById("mailingform") != null)
		document.getElementById("mailingform").appendChild(hidden);

	$("#form-name").focus(function () {
		if ($(this).val() == "Naam") {
			$(this).val("");
		}
	});
	$("#form-name").blur(function () {
		if ($(this).val() == "") {
			$(this).val("Naam");
		}
	});
	$("#form-email").focus(function () {
		if ($(this).val() == "E-mail") {
			$(this).val("");
		}
	});
	$("#form-email").blur(function () {
		if ($(this).val() == "") {
			$(this).val("E-mail");
		}
	});
	
	$("#mailingform").submit(function () {
		if ($("#form-name").val() == "" || $("#form-name").val() == "Naam") {
			alert("Naam is niet ingevuld");
			return false;
		}
		if ($("#form-email").val() == "" || $("#form-email").val() == "E-mail") {
			alert("E-mail is niet ingevuld");
			return false;
		}
	});
	
	var clonedFooter, footerOffsetHeight, footerHeight, bFooterCollapsed;
	bFooterCollapsed = true;
	footerHeight = $(".footer").height();
	footerOffsetHeight = $(".footer").offset().top;
	
	clonedFooter = $(".footer").clone(true).addClass("clonedfooter").appendTo("body");
	
	$(".footer .logo").click(function () {
		if (f_scrollTop() + f_clientHeight() <= footerOffsetHeight) {
			if (bFooterCollapsed) {
				bFooterCollapsed = false;
				$(".clonedfooter").animate({ height: footerHeight + "px" }, 1000);
			} else {
				bFooterCollapsed = true;
				$(".clonedfooter").animate({ height: "35px" }, 1000);
			}
		}

		return false;
	});
	
	if (f_scrollTop() + f_clientHeight() - 35 >= footerOffsetHeight) {
		$(clonedFooter).hide();
	} else {
		$(clonedFooter).show();
	}

	$(window).scroll(function () {
		if (!bFooterCollapsed) return; // Don't hide footer when it's open.
		
		if (f_scrollTop() + f_clientHeight() - 35 >= footerOffsetHeight) {
			$(clonedFooter).hide();
		} else {
			$(clonedFooter).show();
		}
	});
});

function getemail(aid, domain, name) {
    aid.setAttribute("href", "mailto:" + name + "@" + domain);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

