$(document).ready(function(){
	tables();
});
function fillHomeField(){
	$('#woning-3').val(sWoning);
}

function initSelectboxes(){
	$('div.select select').selectbox();
	var zIndex = 9999;
	$('div.form div.entry').each(function(){
		$(this).css('z-index',zIndex);
		zIndex--;
	});
}

function googlemaps(){
	var myCenter = new google.maps.LatLng(51.81834, 3.97744);
	var myOptions = {
	  zoom: 17,
	  center: myCenter,
	  mapTypeId: google.maps.MapTypeId.ROADMAP,	  
	  mapTypeControl: false,
	  scrollwheel: false
	}
	var myLatlng = new google.maps.LatLng(51.81834, 3.97744);
	var map = new google.maps.Map(document.getElementById("map"), myOptions);
	var image = new google.maps.MarkerImage('images/template/marker_beterwonen.png',
		new google.maps.Size(134, 62),
		// The origin for this image is 0,0.
		new google.maps.Point(0,0),
		// The anchor for this image is the base of the flagpole at 0,32.
		new google.maps.Point(50, 50)
	);
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map,
		icon: image
	});
}

function radioButtons() {
	$('.radio').click(function() {
		$('label.radio').removeClass('checked');	
		$('label.radio').find('input').attr('checked','');
		$(this).addClass('checked');
		$(this).find('input').attr('checked','checked');
	});
	$('.radio2').click(function() {
		$('label.radio2').removeClass('checked');	
		$('label.radio2').find('input').attr('checked','');
		$(this).addClass('checked');
		$(this).find('input').attr('checked','checked');
	});
	$('.checkbox').toggle(
		function() {
			$(this).prev().attr('checked','checked');
			$(this).addClass('checked');
			$(this).children('input').val('Ja');
		},
		function(){
			$(this).prev().attr('checked','');
			$(this).removeClass('checked');
			$(this).children('input').val('');
		}	
	);
}

var bNext = true;
var bPrev = true;
function fotoslider(p_nVisible, p_nDefaultSlides) {
	
	var nVisible = p_nVisible; // Aantal zichtbare items
	var nDefaultSlides = p_nDefaultSlides; // Aantal items per keer sliden
	var obj = $('.wrapper'); // Naam van de items 
	var nSlides = nDefaultSlides;
	var nWidth = parseInt(obj.width()) + parseInt(obj.css('margin-right')) + parseInt(obj.css('margin-left'));
	var nTotal = parseInt($('.wrapper').size());
	var nActive = nVisible;
	
	if(nTotal < nVisible) {
		$('#prev').hide();
		$('#next').hide();
	}
	
	$('#next').click(function(){
		if(bNext == true) {
			var nRemaining = nTotal - nActive;
			if(nRemaining < nSlides) {
				nSlides = nRemaining;
			} else {
				nSlides = nDefaultSlides;	
			}
			if(nActive == 1) {
				nActive = nDefaultSlides;	
			}
			var nLeft = parseInt($('.foto_container').css('left')) - (nWidth * nSlides);
			nActive = nActive + nSlides;
			if(nTotal == nActive) {
				$('#next').hide();
			} else {
				$('#next').show();
			}
			bNext = false;			
			$('.foto_container').animate({
				'left':nLeft
			},
			250,
			"linear", 
			function(){ 
				bNext = true;
			});
		}
		$('#prev').css('display','block');
	});
	$('#prev').click(function(){
		if(bPrev == true) {
			var nRemaining = nActive - nVisible;
			if(nRemaining < nSlides) {
				nSlides = nRemaining;
			} else {
				nSlides = nDefaultSlides;	
			}
			var nLeft = parseInt($('.foto_container').css('left')) + (nWidth * nSlides);
			if(nLeft == 0) {
				$('#prev').css('display','none');
			}
			bPrev = false;			
			$('.foto_container').animate({
				'left':nLeft
			},
			250,
			"linear", 
			function(){ 
				bPrev = true; 
			});
			nActive = nActive - nSlides;
			if(nTotal > nActive) {
				$('#next').show();
			} else {
				$('#next').hide();
			}
		}
	});
}
function tables(){
	$('table').each(function(){
		$(this).find('tr:first').children('td').addClass('tabletop');
	});
}

