
	// jquery scripts
	$(document).ready(function () {

		$('div#shopMenu').hover(function() {
			
           	$('ul:first',this).css('visibility', 'visible').fadeIn('fast');

			$('div#shopMenu').mouseleave(function() {
           		$('ul:first',this).css('visibility', 'visible').fadeOut('fast');
			});
		});

		$(function(){

            $("ul.dropdown li").hover(function(){
            
                $(this).addClass("hover");
                $('ul:first',this).css('visibility', 'visible');
            
            }, function(){
            
                $(this).removeClass("hover");
                $('ul:first',this).css('visibility', 'hidden');
            
            });
            
            $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ")
			
        });	
		
		$('.kwicks').kwicks({
			max : 380,
			spacing : 0
		}).css({ borderRight: "5px solid #fff" });

		// lightbox laten werken
		$('a.lightbox').lightBox();
		
		// slideshow
		$('#slideshow').cycle({ 
		    fx:    'fade',
		    speed:  3000,
		    pause: 	1 
		});		
		
		// twitter
		$("#twitter").tweet({
			avatar_size: 0,
			count: 3,
			username: ["Rijles_DenHaag"],
			loading_text: "Tweets worden geladen...",
			template: "{text}{time}"
		});
		
		// shopmenu
		$('div#shopMenu ul').superfish({
			autoArrows:  false,
			dropShadows: false
		});
		
		/*$('div#shopMenu ul').hide();
		$('div#shopMenu').mouseenter(function() {
			$('div#shopMenu ul').show();
		});
	
		$('div#shopMenu').mouseleave(function() {
			$('div#shopMenu ul').hide();
		});*/
		
		// form valideren
		$("#id_buybutton").click(function(){

			// check fields
			var checkfields 			= true;
			var errorMsg 				= '';

			var voornaam 				= $('input#id_naam_voornaam').val();
			//var achternamen 			= $('input#id_naam_achternaam').val();
			var adres_straatnaam 		= $('input#id_adres_straatnaam').val();
			var adres_huisnummer 		= $('input#id_adres_huisnummer').val();
			var adres_postcode 			= $('input#id_adres_postcode').val();
			var adres_woonplaats 		= $('input#id_adres_woonplaats').val();
			var emailadres 				= $('input#id_emailadres').val();
			var emailadres_confirm		= $('input#id_emailadres_confirm').val();

			var algemeneVoorwaarden		= $('input#id_voorwaarden').attr('checked'); 
			
			if(!notEmpty(voornaam)){ outlineInput('id_naam_voornaam', true); checkfields = false; errorMsg += "Voornaam is een verplicht veld \n"; } else { outlineInput('id_naam_voornaam', false);  }
			//if(!notEmpty(achternamen)){ outlineInput('id_naam_achternaam', true); checkfields = false; errorMsg += "Achternaam is een verplicht veld \n";} else { outlineInput('id_naam_voornaam', false);  }
			if(!notEmpty(adres_straatnaam)){ outlineInput('id_adres_straatnaam', true); checkfields = false; errorMsg += "Straatnaam is een verplicht veld \n";} else { outlineInput('id_adres_straatnaam', false);  }
			if(!notEmpty(adres_huisnummer)){ outlineInput('id_adres_huisnummer', true); checkfields = false; errorMsg += "Huisnummer is een verplicht veld \n";} else { outlineInput('id_adres_huisnummer', false);  }
			if(!notEmpty(adres_postcode)){ outlineInput('id_adres_postcode', true); checkfields = false; errorMsg += "Postcode is een verplicht veld \n";} else { outlineInput('id_adres_postcode', false);  }
			if(!notEmpty(adres_woonplaats)){ outlineInput('id_adres_woonplaats', true); checkfields = false; errorMsg += "Woonplaats is een verplicht veld \n";} else { outlineInput('id_adres_woonplaats', false);  }
			if(!emailCheck(emailadres)){ outlineInput('id_emailadres', true); checkfields = false; errorMsg += "Een geldig emailadres is een verplicht veld\n"; } else { outlineInput('id_emailadres', false);  }
			if(!emailCheck(emailadres_confirm)){ outlineInput('id_emailadres_confirm', true); checkfields = false;  errorMsg += "Een bevestiging van uw emailadres is  verplicht \n"; } else { outlineInput('id_emailadres_confirm', false); }

			if(emailadres != emailadres_confirm){  
				outlineInput('id_emailadres', true); 
				outlineInput('id_emailadres_confirm', true);
				checkfields = false; 
				errorMsg += "De emailadressen komen niet overeen, controleer de emailadressen \n";
			} else { 
				outlineInput('id_emailadres', false);
				outlineInput('id_emailadres_confirm', false);
			}


			if(!algemeneVoorwaarden){ outlineInput('borderThis', true); checkfields = false; errorMsg += "U moet akkoord gaan met de algemene voorwaarden \n"; } else { outlineInput('borderThis', false);  }

			if(checkfields){
				$('form#formkopen').submit();
				return false;
			} else {
				alert(errorMsg);
				return false;
			}
			
		});
		
		
		$("a#keep-me-posted-link").toggle(
			function () {
				$("div#tell-a-friend").slideUp();
				$("div#keep-me-posted").slideDown();
				return false;
			},
			function () {
				$("div#keep-me-posted").slideUp();
				return false;
			}
		);
		
		$("#images-large").carouFredSel({
			auto 	: false,
			items	: 1,
			scroll 	: {
				items			: 1,
				duration		: 1000,
				pauseOnHover	: true
			},
			prev 	: {   
				button  : "#prev_large",
				key     : "left"
			},
			next 	: {
				button  : "#next_large",
				key     : "right"
			}			
		});
		
		$("#id_bezorgadres_check").click(function(){
			var check_status = $('#id_bezorgadres_check').is(':checked');
			if(check_status) {
				var pageLongHeight = $("#pageLong").height();
				var newheight = pageLongHeight + 175;
				$("div#pageLong").animate({
					height:newheight
				}, 250, "linear");
				$('div#cart-personalia-bezorgadres').slideDown();
			} else {
				$("div#pageLong").css('height','');
				$('div#cart-personalia-bezorgadres').slideUp();

			}
		
			
		});	
		
	});	
	
	// validatie functies
	function postcodeCheck(postcode) {
		var result 	= false;
		var filter  = /^[0-9]{4}[ A-Za-z]{2,3}$/;
		
		if ((postcode.length) > 0) {
			if (filter.test(postcode)) {
				result = true;
			}
		}
		return result
	}	

	function emailCheck(addres) {
		
		var result 	= false;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		if ((addres.length) > 0) {
			if (filter.test(addres)) {
				result = true;
			}
		}
		return result;
	}
	
	function notEmpty(str) {
		
		var result 	= false;
		//var filter  = /^[a-zA-Z0-9_\-,\.\'']{255}$/;
		
		if ((str.length) > 0) {
			//if (filter.test(str)) {
				result = true;
			//}
		}
		return result;
	}	
	
	function isDate(date) {
		
		var result 	= false;
		var filter  = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
		
		if ((date.length) > 0) {
			if (filter.test(date)) {
				result = true;
			}
		}
		return result;
	}	

	// velden aanduiden of ze verplicht zijn
	function outlineInput(id, status){
		if(status){
			$('#'+id).addClass('outline');
			$('#'+id).focus();
		} else {
			$('#'+id).removeClass('outline');
		}
	}	

	// show of hide poster
	function showPoster (){
		$('#hidecontent').css('visibility', 'visible');
		$('#poster').fadeIn('slow');
	}

	function hidePoster (){
		$('#hidecontent').css('visibility', 'hidden');
		$('#poster').fadeOut('fast');
	}
	

