$(document).ready(function()
{
	
	$('.afwijkend').click(function()
	{
		if($('.afwijkend:checked').val() == 'ja')
		{
			$('.afwijkend-afleveradres input[name=afwijkend_titel]').addClass('required');
			$('.afwijkend-afleveradres input[name=afwijkend_voornaam]').addClass('required');
			$('.afwijkend-afleveradres input[name=afwijkend_achternaam]').addClass('required');
			$('.afwijkend-afleveradres input[name=afwijkend_adresregel]').addClass('required');
			$('.afwijkend-afleveradres input[name=afwijkend_postcode]').addClass('required');
			$('.afwijkend-afleveradres input[name=afwijkend_plaats]').addClass('required');
			$('.afwijkend-afleveradres input[name=afwijkend_land]').addClass('required');
			$('.afwijkend-afleveradres').removeClass('hidden');	
		}else
		{
			$('.afwijkend-afleveradres .required').removeClass('required').removeClass('error');
			$('.afwijkend-afleveradres').addClass('hidden');	
		}
	});
	
	$('.btn-cart').click(function()
	{
		$('.notify').hide('slow');
		var product = $(this).attr('rel');
		var postData = { 
			'p' : product,
			'q' : 1,
			't' : 'c'
		};
		jQuery.post('/kassa/addToCart.php',postData,function(data)
		{
			$('.content').prepend('<div class="notify">'+data+'</div>');
			$('a.top-link-cart').load('/kassa/getCartLinkInfo.php');
		});	
	});
	
	$('.btn-cart-live').live('click',function()
	{
		$('.notify').hide('slow');
		$(this).hide();
		var product = $(this).attr('rel');
		var postData = { 
			'p' : product,
			'q' : 1,
			't' : 'c',
			'check'  : 'y'
		};
		
		var a = $(this);
		
		jQuery.post('/kassa/addToCart.php',postData,function(data)
		{
			$('.content').prepend('<div class="notify">'+data+'</div>');
			$('a.top-link-cart').load('/kassa/getCartLinkInfo.php');
			a.show(300);
		});	
		
	});
	
	$('.btn-combination').live('click',function()
	{
		$('.notify').hide('slow');
		var product = $(this).attr('rel');
		var postData = { 
			'c' : product,
			'q' : 1,
			't' : 'c'
		};
		jQuery.post('/kassa/addToCart.php',postData,function(data)
		{
			$('.content').prepend('<div class="notify">'+data+'</div>');
			$('a.top-link-cart').load('/kassa/getCartLinkInfo.php');
		});	
	});
	
	//$('#vraag-form input[name=verstuur]').click(function()
	//{
	//		$('#vraag-form').validate();
	//});
	$('#review-form .submit').click(function()
	{
			$('#review-form').validate();
		
	});
	
	$('.bevestigen').click(function()
	{
			$('#afrekenform').validate();
			//{
			//	$('#afrekenform').submit();
			//});	
	});
	
	$('.product-info .btn-cart').unbind('click').click(function()
	{

		var product = $(this).attr('rel');
		var postData = { 
			'p' : product,
			'q' : $('.qty[rel='+product+']').val(),
			't' : 'p'
		};
		jQuery.post('/kassa/addToCart.php',postData,function(data)
		{
			$('.content').prepend('<div class="notify">'+data+'</div>');
			$('a.top-link-cart').load('/kassa/getCartLinkInfo.php');
			
			
		});	
	});
	
	$('.notify span').live('click',function()
	{
		$(this).parent().hide('fast');
	});
	
	$('.btn-update-cart').live('click',function()
	{
		
		var p = {};
		$('.qty').each(function(e,el)
		{
			p[$(this).attr('rel')] = $(this).val();
		});
		//
		var postData = {
			'action' : 'update',
			'products' : p
		};
		
		jQuery.post('/kassa/cartActions.php',postData,function(data)
		{
			$('.content').prepend('<div class="notify">'+data+'</div>');
			$('.cart-content').load('/kassa/getCart.php');	
			$('a.top-link-cart').load('/kassa/getCartLinkInfo.php');
			$('.qty').spin({
				max: 9999,
				min: 0
			});			
		});
	});
	
	$('.delete-product').live('click',function()
	{
		var rel = $(this).attr('rel');
		var postData = {
			'p' : rel,
			'action' : 'delete' 
		};
		if(confirm('Weet u zeker dat je dit product uit de winkelwagen wilt verwijderen.'))
		{
			jQuery.post('/kassa/cartActions.php',postData,function(data)
			{
				$('.content').prepend('<div class="notify">'+data+'</div>');
				$('.cart-content').load('/kassa/getCart.php');	
				$('a.top-link-cart').load('/kassa/getCartLinkInfo.php');
			});
		}
	});
	
	  $(".product-image").fancybox(
	  {  	  
	  	'type': 'image',
	  	'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'hideOnContentClick' : true,
		'transitionOut'	: 'elastic'
	  	  
	  });
	  
	$('.flag_nl').click(function()
	{
		$('.description').hide();
		$('.description_nl').show();
	});
	$('.flag_gb').click(function()
	{
		$('.description').hide();
		$('.description_gb').show();
	});
	$('.flag_fr').click(function()
	{
		$('.description').hide();
		$('.description_fr').show();
	});
  $.tablesorter.defaults.widgets = ['zebra']; 
    $("#producten-sorter").tablesorter({ 
	// pass the headers argument and assing a object 
		headers: { 
	    // assign the secound column (we start counting zero) 
	    0: { 
		// disable it by setting the property sorter to false 
		sorter: false 
	    }, 
	    // assign the third column (we start counting zero) 
	    2: { 
		// disable it by setting the property sorter to false 
		sorter: false 
	    } ,
	    5: { 
		// disable it by setting the property sorter to false 
		sorter: false 
	    } 
	} 
    }).tablesorterPager({container: $(".pagina-nummers")}); 
 
    $('.qty').spin({
        max: 9999,
        min: 0
     });
    
    $('.lees-meer-knop').live('click',function()
    {
    	 rel = $(this).attr('rel');
    	 $('.lees-meer-hidden[rel='+rel+']').show();
    	 $(this).hide();
    	 $(this).parent('td').addClass('fat');
    });
    $('.lees-minder').live('click',function()
    {
    	 rel = $(this).attr('rel');
    	 $('.lees-meer-hidden[rel='+rel+']').hide();
    	 $('.lees-meer-knop[rel='+rel+']').show();
    	  $(this).parent().parent('td').removeClass('fat');
    });

});




