var root_url = "/#";
var basis_url = root_url + "/";
	
$(document).ready(function() {
	
	// ############
	// HOME CYCLE
	// ############
	
	$('.home-groot-cycle').cycle({
		fx:     'fade', //blindX
		speed: '1500',
		timeout: '4000',
		random: 0,
		pager:  '#homenav',
			pagerAnchorBuilder: function(idx, slide) { 
			return '<a href="#"></a>'
	   		
		}
	   });		

	// ############
	// HOME TWEETS CYCLE
	// ############
	
	$('.tweets ul').cycle({
		fx:     'fade', //blindX
		speed: '500',
		timeout: '8000',
		random: 0,
		pager:  '#tweetnav',
			pagerAnchorBuilder: function(idx, slide) { 
			return '<a href="#"></a>'
	   		
		}
	});
	
	
	// ############
	// TYPO
	// ############
	
	Cufon.replace('h1', {textShadow: '#fff 1px 1px'});
	Cufon.replace('.menu li a, .categorie span, .filterbullet span, .winkelwagentje a, .home-blok h2, .mailstage-open, .month_select span, .filtertitle, .month_select_kies', {hover: true});
	
	
	// ############
	// HOME
	// ############
	
	$(".home-blok").hover(function() {
			$(this).find(".introtop").stop().animate({ height: "0px", marginTop: "10px"  }, 200 );	
			$(this).find(".intro").stop().animate({ bottom: "0px"  }, 500 );

		} , function() {
			$(this).find(".introtop").stop().animate({ height: "10px", marginTop: "0px"   }, 200 );		
			$(this).find(".intro").stop().animate({ bottom: "-100px"  }, 500 );
	});	
	$("#home-groot .home-groot-cycle").hover(function() {
			$(this).find(".groot-title").stop().css({ backgroundPosition: "center right", color: "#666"  }, 200 );	
			
			$(".home-text, #homenav").stop().animate({ opacity: "0"  }, 500 );
		} , function() {
			$(this).find(".groot-title").stop().css({ backgroundPosition: "-1000px -1000px", color: "#1b4279"  }, 200 );	
			$(".home-text, #homenav").stop().animate({ opacity: "1"  }, 500 );
	});	 
	
	/* org */
	$(".home-blok-instelling").hover(function() {
			$(this).find(".introtop").stop().animate({ height: "0px", marginTop: "10px"  }, 200 );	
			$(this).find(".intro").stop().animate({ bottom: "30px"  }, 500 );

		} , function() {
			$(this).find(".introtop").stop().animate({ height: "10px", marginTop: "0px"   }, 200 );		
			$(this).find(".intro").stop().animate({ bottom: "-100px"  }, 500 );
	});		
	
	/* $("#over-de-weijer, .menu2").hover(function() {
			$(".menu2").show();
		} , function() {
			$(".menu2").hide();
	}); */	
	
	// ############
	// FOOTER MAILSTAGE
	// ############
	
	$(".mailstage .mailstage-open").click(function() {
			$(".mailstage_form").fadeIn();
	});	
	
	$(".close-mailstage").click(function() {
			$(".mailstage_form").fadeOut();
	});		
	
	// ############
	// AGENDA ITEMS
	// ############
	
	$(".agenda-item").hover(function() {
			
	} , function() { 
			
	})		
	
	// ############
	// AGENDA MONTH SELECT
	// ############
	
	$(".month_select, .month_options").click(function() {
			$(".month_options").toggle();
		});		
	
	// HASH
	// OPEN AGENDA ITEM MET HASH
	var ding = window.location.hash;
	$(ding).stop().animate({ height: "467px"  }, 500 );
	$(ding).find(".itemfoto").delay(1000).fadeIn(2000, "easeInOutQuint");
	$(ding).find(".expanded").stop().delay(500).fadeIn(0);
	$(ding).find(".zap").hide();
	
	//$(window).scrollTo( ding, 300, {});
	
	// KLIK
	// OPEN AGENDA ITEM MET KLIK
	$(".agenda-item .zap a").click(function() {
	
		$(".agenda-item").animate({ height: "57px"  }, 500);
		$(".itemfoto").hide();
		$(".expanded").hide();
		$(".zap").show();
		
		$(this).parent().parent().stop().delay(750).animate({ height: "467px" }, 500, function() {

			var myClass = $(this).attr("id");
			$(window).stop().delay(1000).scrollTo( $("#agenda #" + myClass), 500, {offset:-210, margin: true, easing:'easeOutQuint'}); //467   668
			$("#" + myClass + " .itemfoto").delay(1000).fadeIn(2000, "easeInOutQuint");
		
			$(this).find(".expanded").stop().delay(500).fadeIn(1000);
		});
		
	});	
	
	
    $("#pagina-filter .btn").toggle(function(){
        var ul = $(this).next("ul");
        ul.toggle();
    }, function() {
        var ul = $(this).next("ul");
        ul.toggle();
    });

    
    /*
    $(".categorie").toggle(function() {
        var subHeight = $('.pagina',this).sandbox(function(){ return this.height(); });
        var newHeight = subHeight * 3;
        $(this).css({ height: newHeight });
        $(".pagina",this).slideDown('slow');
    }, function() {
        $(this).css({ height: "27" });
        $(".pagina",this).slideUp('slow');
        
    });
    */
    /*
    $(".categorie").toggle(function() {
        var subHeight = $('.pagina',this).sandbox(function(){ return this.height(); });
        var newHeight = subHeight * 3;
        $(this).stop().animate({ height: newHeight }, 500 );
        $(".pagina",this).toggle();
	}, function(){
	    $(this).stop().animate({ height: "27" }, 500 );
        $(".pagina",this).stop().toggle();
    });
	*/

	
	// ############
	// AGENDA - CAT - FILTER
	// ############

	// to make!
	
	// ############
	// FANCYBOX
	// ############	

		
	$("a.photolink").fancybox({
		'opacity'		: true,
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'none',
		'overlayShow'	: true,
		'overlayColor'  : '#fff',		
		'titlePosition'	: 'outside'
	});	
	
	
 

	$("a.photolink").hover(function() {
			$(this).find(".zoom").toggle();
		} , function() {
			$(this).find(".zoom").toggle();
	});	
	$("a.videolink").hover(function() {
			$(this).find(".zoom-video").css({ backgroundImage: "url('/images/zoom-video.png')"});
		} , function() {
			$(this).find(".zoom-video").css({ backgroundImage: "url('/images/zoom-video-off.png')"});
	});	
	
    $("a.iframe").fancybox({
        'width':740,
        'height':620
        
        });
	
	
	$("a.videolink").click(function() {
		$.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'overlayShow'	: true,
				'overlayColor'  : '#fff',
				'transitionOut'	: 'none',
				'titleShow'		: false,
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
					
				}
			});

		return false;
	});	
	
});


$.fn.sandbox = function(fn) {
    var element = $(this).clone(), result;
    // make the element take space in the page but invisible
    element.css({visibility: 'hidden', display: 'block'}).insertAfter(this);
    // to override any display: none !important you may have been using
    element.attr('style', element.attr('style').replace('block', 'block !important'));
    result = fn.apply(element);
    element.remove();
    return result;
};





// klooien met knopjes

$(document).keydown(function(e){
    if (e.keyCode == 37 || e.keyCode == 38) { 
       //alert( "left or up pressed" );
	   $('#agenda').prev().css({ background: "#ff0"  }, 200 );
       return false;
    }
	
    if (e.keyCode == 39 || e.keyCode == 40) { 
       //alert( "right pressed" );
	   $('#agenda').next().css({ background: "blue"  }, 200 );
       return false;
    }	
});

//Contactformulier AJAX
$(function() {
    $("#contactformsubmit").click(function() {
        
        //Valideren
        $("#contactform").validate({
            rules: {
              naam: "required",    // simple rule, converted to {required: true}
              email: {             // compound rule
              required: true,
              email: true
              },
              vraag: {
                required: true
              }
            },
            messages: {
              naam: "Vul uw naam in.",
              email: "Vul een geldig e-mailadres in.",
              vraag: "Vul een vraag of opmerking in."
            }
          });
        
        if($("#contactform").valid()){
            
          var naam = $('#contactnaam').val();
          var email = $('#contactemail').val();
          var telefoon = $('#contacttel').val();
          var vraag = $('#contactvraag').val();
          var dataString = 'naam='+ naam + '&email=' + email + '&telefoon=' + telefoon + '&vraag=' + vraag ;
          //alert(dataString); return false;
            $.ajax({
              type: "POST",
              url: "/includes/contactform_ajax.php",
              data: dataString,
              success: function() {
                $('#contactform').html("<p>Uw bericht is verzonden. Indien gewenst zal er zo spoedig mogelijk contact met u opgenomen worden.</p>")
                .hide()
                .fadeIn(1500);
                }
            });
            return false;
        };
    });
  });

//Nieuwsbrief aanmelden AJAX
$(function() {
    $("#mailstagesubmit").click(function() {
        
        //Valideren
        $("#mailstageform").validate({
            rules: {
              name: "required",
              email: {
              required: true,
              email: true
              }
            },
            messages: {
              name: "Vul uw naam in.",
              email: "Vul een geldig e-mailadres in."
            }
        });
        
        if($("#mailstageform").valid()){
            
          var name = $('#mailstagename').val();
          var email = $('#mailstageemail').val();
          var dataString = 'name='+ name + '&email=' + email;
            $.ajax({
              type: "POST",
              url: "/includes/mailstage_ajax.php",
              data: dataString,
              success: function() {
                $('.mailstage_form').html("<p>U bent succesvol aangemeld voor onze nieuwsbrief.</p>")
                .hide()
                .fadeIn(1500);
                }
            });
            return false;
        };
    });
  });
  
