function init() {
	var fadeInInterval = 500;
	var pagelink;

    if($("#jquery_jplayer_1").length) {
        $("#jquery_jplayer_1").jPlayer({
            ready: function () {
                $(this).jPlayer("setMedia", {
                    mp3:"/js/music.mp3"
                }).jPlayer('play');
            },
            swfPath: "/js",
            supplied: "mp3",
            wmode: "window"
        });
    }

	$("#intro_con").hide();
	$('#center_right').slideDown(fadeInInterval*2);

	// select all internal links which do not link to an image
	$('a[href^=http://kamerbeek.kuun.nl]:not([rel=lightbox])').not('.thickbox,.nolink').click(function(e){
		e.preventDefault();

		// Wanneer er naar een detailpagina wordt geklikt, stop de verdere verwerking
		if($(this).parent().is('.artikellist_item_details, .artikellist_item_top,#article_close')){
			return false;
		} else {
			//linkLocation = this.href;
			$("body:not(.page-id-5) #center_right").slideUp(fadeInInterval);

			pagelink = this.href;
			//window.setTimeout( function(){window.location = pagelink;},fadeInInterval/2);
			window.setTimeout(function(){redirect(pagelink);},fadeInInterval/2);
		}
	});

	$('a[href^=http://www.kamerbeekjuweliers.nl]:not([rel=lightbox])').not('.thickbox, .nolink').click(function(e){
		e.preventDefault();

		// Wanneer er naar een detailpagina wordt geklikt, stop de verdere verwerking
		if($(this).parent().is('.artikellist_item_details,.artikellist_item_top,#article_close')){
			return false;

		} else {
			//linkLocation = this.href;
			$("body:not(.page-id-5) #center_right").slideUp(fadeInInterval);

			pagelink = this.href;
			//window.setTimeout( function(){window.location = pagelink;},fadeInInterval/2);
			window.setTimeout(function(){redirect(pagelink);},fadeInInterval/2);
		}
	});

	$('.menu-main-menu > li.current_page_item > ul, .menu-main-menu > li.current_page_item li.current_page_item > ul, .menu-main-menu li.current-menu-parent > ul').slideDown(500);


	$('.menu-main-menu li a').click(function(e){
		// prevent linking to page. this disrupts menu animation
		e.preventDefault();
		$('.menu-main-menu ul').slideUp(500);
	});

	if($('.header_img').length) {
		$('.header_img').cycle({fx:'fade',timeout: 6000});
	}

	$('.callme').click(function(){
		$('#popup_content').load('/wp-content/themes/twentyten/inc/form.php');
		$('#popup_con').fadeIn();
	});

	$('#sendmail').live('click', function() {

		var contact_persoon = $('#contact_persoon').val();
		var telefoonnummer_callback = $('#telefoonnummer_callback').val();
		var datum = $('#datum').val();
		var tijd = $('#tijd').val();
		var email_callback = $('#email_callback').val();
		var nieuws = $('#nieuws').val();
		var isr = 'Verplicht';
		var errors = 0;

		$('#contact_persoon_error').html('');
		$('#email_callback_error').html('');
		$('#telefoonnummer_callback_error').html('');
		$('#nieuws_callback_error').html('');

		if (contact_persoon.length<1) {
			$('#contact_persoon_error').html(''+isr);
			errors = 1;
		}
		if (nieuws.length<1) {
			$('#nieuws_callback_error').html(''+isr);
			errors = 1;
		}
		if (!email_callback.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			$('#email_callback_error').html('Ongeldig');
			errors = 1;
		}
		if (!telefoonnummer_callback.match(/^([0-9 -]{10,15}$)/i)) {
			$('#telefoonnummer_callback_error').html('Ongeldig');
			errors = 1;
		}

		if(errors) {
			$('#response').html('Het formulier bevat foutieve invoer.');
			return false;
		}

		$('#response').html('Bezig met verzenden...');

		$.ajax({
		    type: "POST",
		    url: "/wp-content/themes/twentyten/inc/mail.php",
		    data: "contact_persoon="+contact_persoon+"&telefoonnummer_callback="+telefoonnummer_callback+"&datum="+datum+"&tijd="+tijd+"&email_callback="+email_callback+"&nieuws="+nieuws,
		    success: function(msg){
				$('#response').html(msg);
				$('#popup_con').delay(2000).fadeOut();
		    }
		});
	});

	$('#myaccount-login-form > div:first').click(function(){
		$('#myaccount-login-form-foldout').toggle('slow');
	});

	$('.wpsc_buy_button').live('click',function(){
		$('#popup_content').html('Het artikel is toegevoegd aan uw winkelmand.');
		$('#popup_con').fadeIn().delay(1500).fadeOut();
	});

	// heeeeeeeeeeere we go.
	if($('#artikelen').length > 0) {
		$("#artikelen").scrollable({speed: 1000}).navigator({
			navi: ".navi",
			activeClass: '',
            indexed: true,
			history: true
		});
	}

	$("#articles_content .navi a").not(':last-child').append(' ■');

	/*
	 * There is a bug in scrollable wich causes the second navigator to set an empty active class
	 * Thats why we do this manually after the scrollable has scrolled to the active page.
	*/
	var api = $("#artikelen").data("scrollable");
	if(api){
		api.onSeek(function() {
			var index = this.getIndex();
			$("#articles_content .navi a").removeClass('current');
			$("#articles_content .navi a:nth-child("+(index+1)+")").addClass('current');
		});
	}

	// Check email on form submit
	$('.wpcf7-form').bind('submit',function(){
		var email = $('input[name=your-email]').val();
		$('#email_error').html('');

		if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			$('#email_error').show();
			$('#email_error').html('Ongeldige e-mail');
			return false;
		}
	});

	// Hide email error on hover
	$('input[name=your-email]').hover(function(){
		$('#email_error').fadeOut();
	});
	$('#email_error').hover(function(){
		$('#email_error').fadeOut();
	});

	$('#article_close a,#article_close a img').live('click',function(e) {
		$('#article_details_con').fadeOut();
		return false;
	});

    $('#article_close a,#article_close a img').click(function(e) {
		$('.articles_content').slideUp(fadeInInterval);
        var link = $('#article_close a').attr('href');
        window.setTimeout(function(){redirect(link);},fadeInInterval/2);
	});

    if($('#snowwrapper').length) {
        $('#snowwrapper').snowfall({
            flakeCount : 100,
            flakeColor : '#ffffff',
            flakeIndex: 99,
            minSize : 2,
            maxSize : 4,
            minSpeed : 2,
            maxSpeed : 5
        });
    }
}

$(document).ready(function() {
	init();
});

closePopup = function() {
	$('#popup_con').fadeOut();
}

// Display intro when visitor comes from other site
loadIntro = function(){
	// Check if previous page was withing the kamerbeek domain/
	// If not, show intro
	if ( document.referrer.indexOf(window.location.hostname) < 0 ) {

		$('body > div').hide();
		$.ajax({
		    type: "GET",
		    url: "/wp-content/themes/twentyten/inc/intro.php",
		    success: function(msg){
					$('#intro_con').html(msg);
					$('body > div').not('#popup_con, #article_details_con').show();

                    if($('#snowwrapper').length) {
                        $('.flake-rounded').css('z-index',10000);
                        $('#intro_con').show().delay(30000).slideUp(500);
                    }
                    else {
                        $('#intro_con').show().delay(12000).slideUp(500);
                    }
		    }
		});
	}
}

redirect = function(url) {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
                var referLink = document.createElement('a');
                referLink.href = url;
                document.body.appendChild(referLink);
                referLink.click();
        } else {
                location.href = url;
        }
}

closeIntro = function() {
	$('body > div').not('#popup_con, #article_details_con').show();
	$('#intro_flash').hide();
	// JOchem - slideup werkt hier niet omdat delay functie is aangeroepen op intro_flash selector.
	// alle effecten worden nu dus vertraagd. Omdat hide functie geen gebruik maakt van effecten werkt deze wel
	$('#intro_con').hide();
    $('.flake-rounded').css('z-index',99);
}
