;(function($){
    
    // easing
    $.easing.drop = function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
    };

    $.easing.easeInQuad = function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	};
	
	// loading animation
    $.tools.overlay.addEffect("drop", function(css, done) { 

        var conf    = this.getConf(),
            overlay = this.getOverlay(),
            overlayHeight = overlay.height();
            
        css.opacity = 0;
        
        if (conf.fixed)  {
            css.position = 'fixed';
            css.top = 0 - overlayHeight;
        } else {
            css.top = $(window).scrollTop() - overlayHeight;
            css.left = $(window).scrollLeft();
            css.position = 'absolute';
        }

        overlay.css(css).show();
        var top = $(window).scrollTop();

        overlay.animate({
            top: 20,
            opacity: 1 
        }, 400, 'easeInQuad', function(){
            done.call();
        });


    }, function(done) {

        var overlay = this.getOverlay();

        this.getOverlay().animate({
            top: -500,
            opacity:1
        }, 200, 'drop', function() {
            done.call();      
        });
    });
    
	$(document).ready(function(){
	    
	    // IE fox
	    $('li, input, textarea, select, dl, dd').hover(function(){
	        $(this).addClass('hover');
	    }, function(){
	        $(this).removeClass('hover');
	    });
	    
	    // Contact forms behaviour
	    $('input,textarea').blur(function(){
	        $(this).parents('li:first').removeClass('focus');
	    }).focus(function(){
	        $(this).parents('li:first').addClass('focus');
	    });
	    
	    // Bind the overlay animation to the newsletter signup link
	    $('#newsletter').overlay({
	        mask: {
                color: '#fff',
                loadSpeed: 200,
                opacity: 0.3
	        },
	        effect: 'drop'
	    });
	    
	    // Clear the search form on focus
	    $('#search-form input')
	       .focus(function(){
	           if ($(this).val() == 'Zoeken') {
	               $(this).val('');
	           }
           }).blur(function(){
               if ($(this).val() == '') {
                   $(this).val('Zoeken');
               }
           });
	    
        // Date picker field
        $('.cf_date')
            .focus(function(){
                $(this).next('.dp-choose-date').trigger('click');
            }).keydown(function(e){
                if (e.keyCode != 9) {
                    e.preventDefault();
                    return false;
                }
            });
	    
	});
})(jQuery);
