jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img />").attr("src", arguments[i]);
  }
}

/* jQuery Delay - A delay function * Copyright (c) 2009 Clint Helfers - chelfers(at)gmail(dot)com | http://blindsignals.com * Dual licensed under MIT and GPL. * Date: 7/01/2009 * @author Clint Helfers * @version 1.0.0 * http://blindsignals.com/index.php/2009/07/jquery-delay/ */

$.fn.delay = function( time, name ) {
    return this.queue( ( name || "fx" ), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time );
    } );
};

function showlayer(id) {
    $('.layerplaatje').hide();
    $('.content').hide();
    $('#layercontainer').show();
    $('#plaatje'+id).show();
    $('#'+id+'content').show();
    $('#kopje').attr('src','/img/kopje-'+id+'.png');
    $.ga.trackPageview('/popup/'+id);
}

function sendform() {
    if ($('#voornaam').val()!=''&&$('#achternaam').val()!=''&&$('#emailadres').val()!='') {
        $('#formresult').load('formulier.php',$('#form1').serializeArray());
        $.ga.trackPageview('formulierverzonden');
    }
}

var animatietijd = 800;
var factor = 900;

function pageload(hash) {
	// alert("pageload: " + hash);
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state
		if($.browser.msie) {
			// jquery's $.load() function does't work when hash include special characters like aao.
			hash = encodeURIComponent(hash);
		}
		//$("#load").load(hash + ".html");
        if (hash!='home') {
            hash = hash.replace(/%20/gi, ' ');
            switch(hash) {
                case 'Programma open dag':
                    id = 'whiteboard';
                    break;
                case 'Maak contact':
                    id = 'prikboard';
                    break;
                case 'Paraveterinair':
                    id = 'doktersjas';
                    break;
                case 'Een opleiding om trots op te zijn':
                    id = 'pauw';
                    break;
                case 'Op kamers':
                    id = 'hondenhok';
                    break;
                case 'Inhoud opleiding':
                    id = 'laptop';
                    break;
                case 'Routebeschrijving':
                    id = 'landkaart';
                    break;
                case 'Leren in de praktijk':
                    id = 'raam';
                    break;
            }
            showlayer(id);
        } else
            $('#layercontainer').hide();
	} else {
        $('#layercontainer').hide();
	}
}

$(function(){
    $.ga.load('UA-12261834-1'); 
	
	$("area").click(function(){
        if ($(this).attr('id')!='konijnenarea') {
    		var hash = this.href;
    		hash = hash.replace(/^.*#/, '');
    		// moves to a new page. 
    		// pageload is called at once. 
    		// hash don't contain "#", "?"
    		$.historyLoad(hash);
        }
		return false;
	});
    
    
    $.preloadImages('/img/Item-doktersjas-2.png','/img/Item-hondenhok-2.png','/img/Item-konijnen-2.png','/img/Item-landkaart-2.png','/img/Item-Laptop-2.png','/img/Item-pauw-2.png','/img/Item-prikboard-2.png','/img/Item-raam-2.png','/img/Item-whiteboard-2.png','/img/Groenhorst-site-detail.jpg','img/detail-shadow.png');
});

 $(window).load(function(){
    $('#ajaxloader').hide();
    
    $('#konijnen').delay(Math.random() * factor).animate({
        top:'630px'
    },animatietijd);
    $('#laptop').delay(Math.random() * factor).animate({
        top:'460px'
    },animatietijd);
    $('#pauw').delay(Math.random() * factor).animate({
        top:'337px'
    },animatietijd);
    $('#bureaus').delay(Math.random() * factor).animate({
        top:'490px'
    },animatietijd);
    $('#bureau').delay(Math.random() * factor).animate({
        top:'500px'
    },animatietijd);
    $('#doktersjas').delay(Math.random() * factor).animate({
        top:'380px'
    },animatietijd);
    $('#hondenhok').delay(Math.random() * factor).animate({
        top:'480px'
    },animatietijd);
    $('#landkaart').delay(Math.random() * factor).animate({
        top:'255px'
    },animatietijd);
    $('#prikboard').delay(Math.random() * factor).animate({
        top:'225px'
    },animatietijd);
    $('#raam').delay(Math.random() * factor).animate({
        top:'260px'
    },animatietijd);
    $('#poster').delay(Math.random() * factor).animate({
        top:'220px'
    },animatietijd);
    $('#whiteboard').delay(Math.random() * factor).animate({
        top:'175px'
    },animatietijd);
    $('#logo').delay(factor+600).animate({
        top:'-20px'
    },500);
   
    $('#konijnenarea').hover(function(){
        $('#konijnen').attr('src','/img/Item-konijnen-2.png');
        },function(){
        $('#konijnen').attr('src','/img/Item-konijnen-1.png');
    });
    $('#doktersjasarea').hover(function(){
        $('#doktersjas').attr('src','/img/Item-doktersjas-2.png');
    },function(){
        $('#doktersjas').attr('src','/img/Item-doktersjas-1.png');
    });
    $('#pauwarea').hover(function(){
        $('#pauw').attr('src','/img/Item-pauw-2.png');
        },function(){
        $('#pauw').attr('src','/img/Item-pauw-1.png');
    });
    $('#hondenhokarea1,#hondenhokarea2').hover(function(){
        $('#hondenhok').attr('src','/img/Item-hondenhok-2.png');
        },function(){
        $('#hondenhok').attr('src','/img/Item-hondenhok-1.png');
    });
    $('#landkaartarea').hover(function(){
        $('#landkaart').attr('src','/img/Item-landkaart-2.png');
        },function(){
        $('#landkaart').attr('src','/img/Item-landkaart-1.png');
    });
    $('#laptoparea').hover(function(){
        $('#laptop').attr('src','/img/Item-Laptop-2.png');
        },function(){
        $('#laptop').attr('src','/img/Item-Laptop-1.png');
    });
    $('#prikboardarea1,#prikboardarea2').hover(function(){
        $('#prikboard').attr('src','/img/Item-prikboard-2.png');
        },function(){
        $('#prikboard').attr('src','/img/Item-prikboard-1.png');
    });
    $('#raamarea1,#raamarea2').hover(function(){
        $('#raam').attr('src','/img/Item-raam-2.png');
        },function(){
        $('#raam').attr('src','/img/Item-raam-1.png');
    });
    $('#whiteboardarea').hover(function(){
        $('#whiteboard').attr('src','/img/Item-whiteboard-2.png');
        },function(){
        $('#whiteboard').attr('src','/img/Item-whiteboard-1.png');
    });
    $('#gaterug').click(function(){
        $.historyLoad('home');
    });
    $(document).keyup(function(event){
        if (event.keyCode == 27) {
            $('#layercontainer').hide();
        }
    });
    //$('area').click(showlayer);
    
    $('a[href^=http]:not("[href*=://' + document.domain + ']")').click(function() {
        $.ga.trackPageview('/out/'+$(this).attr("href"));
    });
    // Initialize history plugin.
	// The callback is called at once by present location.hash. 
	$.historyInit(pageload, "index.php");
 })