function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) {
		return false;
	}
	return true;
}

function currencyFormatted(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s.replace(".",",");
}

function magnifier() {
	if (!$("img#magnifier").attr('src')) {
		$("#preview").append('<img id="magnifier" src="media/images/magnifier.gif" alt="" height="30" width="30">');
	}
}

$(document).ready(function() {					   
						   
	var images = new Array();
	var counter = 0;
	$(".button-small").each(function () {
		images[counter] = new Image();
		images[counter].src = ($(this).attr('rel'));
		counter++;
	});
	
	var linkfound = false;
	$("#nav").find('a').each(function(){
		if( location.href.indexOf(this.href) != -1) {
			$(this).parent().addClass('current');
			linkfound = true;
		}
	});
	
	if (!linkfound) {
		$("li a[href='producten.php']").parent().addClass('current');
	}
	
	$("#nav").lavaLamp({
		fx: "backout", 
		speed: 700
	});
	
	$("#submit").hover(function() { 
			$(this).addClass("hover"); 
		}, function() { 
			$(this).removeClass("hover"); 
	});
	
	$("div.inner-link-container a.button-small").hover(function() {
	   $("#voorbeeld").attr('src', $(this).attr('rel')).attr('alt', 'producten');
	   var largeimg = $(this).attr('rel');
	   $("#voorbeeld").attr('alt',largeimg.replace("/normal/","/large/"));
	   magnifier();
	   $("#pricing-label h3").html("&euro; " + currencyFormatted($(this).attr('name')));
	});
	
	$("#voorbeeld").click(function () {
		var large = $("#voorbeeld").attr('alt');
		var title = $("a[rel='"+$("#voorbeeld").attr('src')+"']").html();
		$("body").append('<div id="dialog"><img src="'+large+'"></div>');
		$("#dialog img").load(function () {
		  var dWidth = ($(this).width());
		  var dHeight = ($(this).height());
		  $('#dialog').dialog({
				width: dWidth+20,
				height: dHeight+50,
				modal: true,
				title: title,
				position: 'center',
				close: function(event, ui) { 
					$('#dialog').dialog('destroy');
					$("#dialog").remove();
				}
			});
		});
	});
	
	$('.inner-link-container').jScrollPane({
		showArrows: true,
		scrollbarWidth: 14
	});
	
	$(".lng_switch").click(function () {
		$.post("lng.php",{lng:$(this).attr('id')},function () {
			document.location.reload();
		});
	});
});
