var totalSlideshowProducts = 0;
var currentActiveSlideshowProduct = 0;

function startProductSlideshow() {
	// How many are there in total?
	totalSlideshowProducts = $('#product_img img').size();

	// Fade out current one
	$('#product_img img#img_'+currentActiveSlideshowProduct).fadeOut(500,function() {
	    // Which is the next image?
		currentActiveSlideshowProduct++;
		if(currentActiveSlideshowProduct > (totalSlideshowProducts-1)) {
			currentActiveSlideshowProduct = 0;
		}
		
		// Fade in next one
		$('#product_img img#img_'+currentActiveSlideshowProduct).fadeIn(500);	
	  });

	// Restart timer
	setTimeout("startProductSlideshow();", 5000);
}

$(document).ready(function(){
	$('#showMyProducts').click(function(){
		if($('#productSelectorHomeAge').val() =='') {
			alert('Vul je leeftijd en geslacht in.');
			return false;
		}
		$('#productSelectorHomeForm').submit();
	});
	
	var searchFieldText = 'Voer een zoekterm in';
	resetValue('#frm_search', searchFieldText);
	
	$('#frm_search').bind('focus', function(event) {
		emptyValue('#frm_search', searchFieldText);
	});
	$('#frm_search').bind('blur', function(event) {
		resetValue('#frm_search', searchFieldText);
	});
	$('#zoek_form').bind('submit', function(event) {
		emptyValue('#frm_search', searchFieldText);
	});
	
});

function changeWistjedat(){
	if(cur_wjd>0){ 
		document.getElementById('wjd_'+cur_wjd).style.display = 'none';
	}
	cur_wjd++;
	if(cur_wjd>aantal_wjd){ cur_wjd = 1; }
	try{
		document.getElementById('wjd_'+cur_wjd).style.display = 'block';
	}catch(e){}
	setTimeout("changeWistjedat()", 7000);
}

/**
 * Empty the value string of an inputfield, but only if the value equals a certain (standard) text
 */
function emptyValue(elm, text){
	if($(elm).val()==text)
		$(elm).val('');	
}

/**
 * Set the value string of an inputfield to a certain (standard) text, but only if the value is empty
 */
function resetValue(elm, text){
	if($(elm).val()=='')
		$(elm).val(text);
}

