$( function () {
	$("input:radio[name=geslacht]")
		.wrap('<div class="radioButtons"></div>')
		.css({
			left: '-1000px',
			position: 'absolute'
		});
		
	$("div.radioButtons")
		.click( function () {
			$("div.radioButtons").removeClass("checked");
			$(this)
				.addClass("checked")
				.find("input:radio")
				.attr('checked', true);
		});
		
	$("input.fields").bind('focus blur', function() {
		if($(this).val() == $(this)[0].defaultValue) {
			$(this).addClass("text").val('');
		} else if($(this).val() == '') {
			$value = $(this)[0].defaultValue;
			$(this).removeClass("text").val($value);
		}
	});
	
	$("div.radioButtons:eq(0)").trigger('click');
	$('select[name=land]').selectbox();
	$('select[name=maand]').selectbox({
		containerClass: 'selectbox-wrapper2',
		inputClass: 'selectboxmaand'
	});
	$('select[name=jaar]').selectbox({
		containerClass: 'selectbox-wrapper3',
		inputClass: 'selectboxjaar'
	});	
	$('select[name=dag]').selectbox({
		containerClass: 'selectbox-wrapper4',
		inputClass: 'selectboxdag'
	});		
});

$( function () {
	$("div#preview img").lazyload({
		placeholder: 'images/loading.gif'
	});

	$("div#templatesImages img").live('click', function () {
		$("div#preview").fadeIn('slow');
		$('html, body').scrollTop( 1 );
	});
	
	$("img.close").click( function () {
		$("div#preview").fadeOut('slow');
		$('html, body').scrollTop( $("div#menu").offset().top );
	});
	
	$("div.template_small").click( function () {
		$prev = $(this).prev().find('img.imgbig').attr('src');
		$next = $(this).next().find('img.imgbig').attr('src');
		
		$thisImg = $(this).find('img.imgbig').attr('src');
		
		$('html, body').scrollTop( $("div#menu").offset().top );
		
		$("div#templatesImages img:not(.next):not(.previous):not(.vink)").remove();
		$("<img />").attr({
			"src": $prev,
			'class': 'smaller'						
		}).appendTo("div#templatesImages");
		$("<img />").attr({
			"src": $thisImg,
			'class': 'big'
		}).appendTo("div#templatesImages");
		$("<img />").attr({
			"src": $next,
			'class': 'smaller'
		}).appendTo("div#templatesImages");
		
		$templateNummer = $(this).find("strong").text();
		$("input#templateNummer").val($templateNummer);
		
		$prev_templateNummer = $(this).prev().find("h3").text();
		$next_templateNummer = $(this).next().find("h3").text();
		
		$("div#templatename_big").html("<h3>" + $templateNummer + "</h3>");
		$("div#templatename_prev").html("<h5>" + $prev_templateNummer + "</h5>");
		$("div#templatename_next").html("<h5>" + $next_templateNummer + "</h5>");
		Cufon.replace('h3');
		Cufon.replace('h5');
		
		
		$("div#preview").fadeOut('slow');
	});
});