/*
 * JavaScript Pretty Date
 * Copyright (c) 2008 John Resig (jquery.com)
 * Licensed under the MIT license.
 */

// Takes an ISO time and returns a string representing how
// long ago the date represents.
function prettyDate(time){
	var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
		diff = (( date.getTime() - (new Date()).getTime()) / 1000),
		day_diff = Math.floor(diff / 86400);

	if ( isNaN(day_diff) || day_diff >= 7 )
		return;

	if (day_diff < 0) { return 'Gesloten'; }
			
	return day_diff == 0 && (
			diff < 60 && "Sluit in minder dan een minuut" ||
			diff < 120 && "Sluit in 1 minuut" ||
			diff < 3600 && "Sluit over " + Math.floor( diff / 60 ) + " minuten" ||
			diff < 7200 && "Sluit in ruim 1 uur" ||
			diff < 86400 && "Sluit over " + Math.floor( diff / 3600 ) + " uren") ||
			day_diff == 1 && "Sluit binnen 1 dag" ||
			day_diff < 7 && "Sluit over " + day_diff + " dagen";
}

// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery != "undefined" )
	jQuery.fn.prettyDate = function(){
		return this.each(function(){
			var date = prettyDate(this.title);
			if ( date )
				jQuery(this).text(date );
		});
	};




$(".auction-date").prettyDate();
setInterval(function(){ $(".auction-date").prettyDate(); }, 60000);

$('#bod').keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 || 
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        });


// MAAK HEEL OBJECT KLIKBAAR
$('body').delegate('.click','click', function(){
	// get the href of the first button in the black: not only used on landing pages but also on subhome
	var e = $(this).find("a.btn").attr("href");
	if (e == undefined) { e = $(this).find("a:first").attr("href"); }
	// go to that location...
	window.location=e;
});

$("body").delegate(".click", "hover", function(e){
	$(this).toggleClass("hover");
});
