/**
* Standaard functies/acties	
**/
$(document).ready(function(){
	$('#contact').validate();
});


/**
* GALLERY functionaliteiten
**/
$(document).ready(function(){
	$("#thumbsHolder img").click(function(){
		var newImgSrc = $(this).attr("src");
		var newInfo = $(this).attr("id")+"info";
		var toAppend = $("#"+newInfo).html();
		$("#bigImg, #infoToAppend").fadeOut(150,function(){
			$("#infoToAppend").html(toAppend);
			$("#bigImg").attr("src",newImgSrc);
			$("#bigImg, #infoToAppend").fadeIn(100);			
		});
	});
});

function refreshCart(){
	$.ajax({
		url:"/js/messenger.php",
		type:"GET",
		dataType:"json",
		data: 	{sAction:'refreshCart'},
		success:(function(data){
			if(data.response===0){
				alert(data.error);
			}
			else{
				$('#miniCart').html(data.sHtml);
			}
		})
	});
}

/**
* WEBSHOPFUNCTIES
**/
$(document).ready(function(){
	/**
	* Forms valideren
	**/
	$('#form1').validate();
	$('#form2').validate();
	$('#form3').validate();
	
	
	if($('#miniCart').attr('id')!==undefined){
		refreshCart();
	}
	
	/**
	* Via ajax een artikel verwijderen uit de winkelwagen
	**/
	$(".removeFromCart").click(
		function(){
			var id= $(this).parent().attr('id');
			var deleteRow = '#tr' + id;
			$.post('/shop/ajax_removeFromCart.php', { id: id },
				function(data){
					if(data.response == 1){
						$(deleteRow).fadeOut('fast');
						/*
						ALLEEN ALS JE BTW/SUBTOTAAL WILT WEERGEVEN IN DE WINKELWAGEN.
						$("#subtotaal").html(data.subtotaal);					
						$("#btw").html(data.btwbedrag);
						*/ 
						$("#totaal").html(data.totaal);
						if(data.aantal=='0'){
							$("#messageSpan").html("Er staan geen producten in uw winkelwagen.");
							$("#doorgaanKnop").fadeOut('fast');							
						}
					}else{
						alert("Er is een fout opgetreden.");
					}
				}, "json"
			);
		}
	);	
	
	/**
	* Loguitknop
	**/
	$('#loguitKnop').click(function() {
	  var url = $("#loguitKnop").attr('href');
	  window.location=url;
	  return false;
	})
	$('#loguitKnop').confirm();
	
	/**
	* Lightbox voor artikelfoto`s
	**/
	$('.imgDiv a').lightBox();
});

/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there.
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic

Optional extra classnames:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...

</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...

</ul>
...
...
</ul>

Copyright 2008 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul.current_page_item').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});
