/**
 * Jquery
 */
	$(document).ready(function() {
		
		/**
		 * Marquee
		 */
			$('div.menu marquee').marquee('pointer').mouseover(function () {
				$(this).trigger('stop');
			}).mouseout(function () {
				$(this).trigger('start');
			}).mousemove(function (event) {
				if ($(this).data('drag') == true) {
					this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
				}
			}).mousedown(function (event) {
				$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
			}).mouseup(function () {
				$(this).data('drag', false);
			});
			
		/**
		 * Prijs update
		 */
		 	$('.productPrijs').change(function() {

				$item = $(this);				
				$.ajax({
					url			: 'winkelwagen.php',
					type		: 'POST',
					dataType	: "html",
					data		: 'aantal=' + $item.val() + '&naam=' + $item.attr("name") + '&prijs=' + $item.attr("title") + '',
					async		: false,
					success		: function(data) {
						$('.totaalPrijs').text(data);
					}
				});
				
			});
		
		/**
		 * Bestelling afhalen / ophalen update
		 */
			$('.bestelling').change(function() {

				$item = $(this);
				$.ajax({
					url			: 'winkelwagen.php',
					type		: 'POST',
					dataType	: "html",
					data		: 'bestelling=' + $item.val() + '',
					async		: false,
					success		: function(data) {
						$('.totaalPrijs').text(data);
					}
				});
				
			});
			
		/**
		 * Docking bar
		 * Scroll the message box to the bottom offset of browser's scrool bar
		 *
			$(window).scroll(function()
			{
				$('#dock').animate({bottom: -$(window).scrollTop()+"px" },{queue: false, duration: 350});
			});
			*/
			
		/**
		 * Omschrijving
		 */
			// Onzichtbaar maken
			$menu = $(".productHome div span.groot");
			$menu.hide();
			
			// Klik 
			$(".productHome div").click(function () {
			
				$klein = $("span.klein", this) 
				$groot = $("span.groot", this) 
				
				if ($klein.is(":hidden")) 
				{
					$klein.show();
					$groot.hide();
				} 
				
				else 
				{
					$klein.hide();
					$groot.show();				
				}
				
				$(".column").css("height", "");
				equalHeight($(".column"));
				
				/*
				$(".productHome .groot").hide();
				$(".productHome .klein").show();
				$("span.klein", this).hide();
				$("span.groot", this).show();				
				*/
				
			});
			
		/**
		 * Facnybox
		 */
			$("a.overlay").fancybox({
				'height'			: 600,
				'width'				: 750,
				'autoDimensions' 	: false
			});
			
			$("#overlay").fancybox({
				'height'			: 600,
				'width'				: 750,
				'autoDimensions' 	: false
			});
			
		/**
		 * Column hoogte
		 */
			 function equalHeight(group) {
				hoogste = 0;
				group.each(function() {
					thisHeight = $(this).height();
						if(thisHeight > hoogste) {
							hoogste = thisHeight;
							col = $(this).attr("id");
						}
					});
				group.height(hoogste);
				$("#" + col  + " li:last-child").removeClass().addClass("noBorderBottom");
			}
			if($('.column').length) equalHeight($(".column"));
		
		/**
		 * Fix voor Chrome
		 */
			setTimeout(function() { 
				$("#col1 li.first .productHome div").trigger('click');
				$("#col1 li.first .productHome div").trigger('click');
				equalHeight($(".column"));
			}, 3000);
	
	});