$(document).ready(function() {
	showSub();
});

function showBanken(){
	$('#sIdeal').click(function(){
		$('#bankkeuze').css('display', 'block');
	});
	$('#sOverschrijving').click(function(){
		$('#bankkeuze').css('display', 'none');
	});
}


function showSub(){
	$('#menu ul li').hover(function(){
		$(this).children('.sub').show();
		$(this).children('a').addClass('active');
	}, function(){
		$(this).children('.sub').hide();
		$(this).children('a').removeClass('active');
	});
};

function initPhotoslide(){
	$('#foto').cycle({ 
		fx:     'fade', 
		speed:  'normal', 
		timeout: 0, 
		next:   '.volgende', 
		prev:   '.vorige',
		after: function(curr,next,opts) {
			$("#foto_aantal").html('Foto ' + (opts.currSlide + 1) + ' van ' + opts.slideCount);
		}
	});
};
function loadFunctions(){
	$('#sorteren,#weergeven').selectbox();
	getAmountProducts();
	getSortValue();
}

// Ophalen aantal producten per pagina
function getAmountProducts(){
	$('div#weergeven_container ul li').click(function(){
		var nValue = $(this).attr('id');
		var sData = 'weergeven='+nValue;
		updateAmount(sData);
	});	
}
// Updaten aantal producten per pagina.
function updateAmount(p_sData){
	//alert(p_sData);
	$.ajax({
		type: 'POST',
		url: sDomain+'inc/producten.inc.php',
		data: p_sData,
		success: function(result){
			$('#wrapper_producten').html(result);	
			loadFunctions();
		}
	});
}
// Ophalen sorteren waarde
function getSortValue(){
	$('div#sorteren_container ul li').click(function(){
		var nValue = $(this).attr('id');
		//alert(nValue);
		var sData = 'sort='+nValue;
		updateSort(sData);
	});	
}
function updateSort(p_sData){
	//alert(p_sData);
	$.ajax({
		type: 'POST',
		url: sDomain+'inc/producten.inc.php',
		data: p_sData,
		success: function(result){
			$('#wrapper_producten').html(result);	
			loadFunctions();
		}
	});
}

function winkelmand() {
	$('.aantal input').change(function(){
		var nArtikelnummer = $(this).parents('.winkelwagen-item').attr('id');
		var nAantal = $(this).val();
		// alert (nAantal);
		loadWinkelmand('artikelnummer=' + nArtikelnummer + '&updateaantal=' + nAantal);
	});
	$('.verwijderen').click(function(){
		var nArtikelnummer = $(this).parents('.winkelwagen-item').attr('id');
		var nAantal = 0;
		loadWinkelmand('artikelnummer=' + nArtikelnummer + '&updateaantal=' + nAantal);
	});
}

function loadWinkelmand(p_sData) {
	$.ajax({
		type: 'POST',
		url: sDomain+'inc/winkelmand.inc.php',
		data: p_sData,
		success: function(result){
			$('#winkelmand_update').html(result);
			winkelmand();
			voorwaardenAkkoord();
		}
	});
}
function voorwaardenAkkoord() {
	$('#sVoorwaarden').click(function(){
		if($('#akkoord').is(':checked')){
			$('#nietakkoord').hide();
			return true;
		} else {
			$('#nietakkoord').show();
			return false;
		}
	});
}


