$(document).ready(function()
{
	// Load equal widths for the main nav
	$('ul#navigation').equalWidths();
	
	// Animate the homepage slideouts
	$(".section").hover(function()
	{
		$(this).children("h3").filter(':not(:animated)').animate({paddingTop:'15px',paddingBottom:'15px'}, 500);
		$(this).children(".description").filter(':not(:animated)').animate({position:'absolute', bottom:'0px', left:'0px'}, 500);
	},
	function()
	{
		$(this).children("h3").animate({paddingTop:'10px',paddingBottom:'10px'}, 300);
		$(this).children(".description").animate({position:'absolute', bottom:'-141px', left:'0px'}, 300);
	});
	
	// Duplicate the href and project it over the full div
	$(".section").click(function()
	{
		window.location=$(this).children('h3').children('a').attr("href");
		return false;
	});
	
	////////////////////////////////////////////////////////////////////////////////////////////////////
	// Gallery viewer - Custom for VanCappellenhuis.nl ////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////////////////////////////////////////
	
	// Set thumbnail opacity
	$("#gallery_selection img").css({ opacity: 0.5 });
	
	// Set thumbnail opacity on hover
	$("#gallery_selection img").hover(function(){
		$(this).fadeTo('fast', 1.0);
	},
	function() {
		$(this).not('.current').fadeTo('fast', 0.5);
	});
	
	// Gallery viewer
	$("#gallery_selection a").click(function()
	{
		if (!$(this).children('img').is('.current'))
		{
			// Get clicked image data (photo + alt)
			var currentimage 	= $(this).attr('href');
			var currenttitle 		= $(this).children().attr('alt');
			
			//Remove class from currently selected photo (if any)
			$('#gallery_selection .current').fadeTo('fast', 0.5, function(){ }).removeClass('current');;
			
			//Set current class to thumbnail
			$(this).children().addClass('current').css({ opacity: 1.0 });;
			
			// Fade out image + description
			$("#gallery #gallery_view_port,#gallery #gallery_description").fadeTo('fast', 0.0, function()
			{
				// Replace current image with new data (photo, alt + description)
				$("#gallery #gallery_view_port").attr({src: currentimage, alt: currenttitle});
				$("#gallery #gallery_description").html(currenttitle);
				
				// Fade in image + description
				$("#gallery #gallery_view_port,#gallery #gallery_description").fadeTo('fast', 1.0);
			});
		} 
		return false;
	});
	// jQuery for "Trouwen->offerteaanvraag"
	$('#trouwen_form,#zaalhuur').validate();
    
	// Set table colors
	$('.trouwtarief tbody tr:nth-child(1) td, .trouwtarief tbody tr:nth-child(3) td').css('background-color','#FCF8EC');
	$('.zaaltarief tbody tr:nth-child(1) td').css('background-color','#FCF8EC');

	// Set style agenda list
	$('.agenda li:nth-child(7n+1)').addClass('datum');
	$('.agenda li:nth-child(7n+2)').addClass('activiteit');	
	$('.agenda li:nth-child(7n+3)').addClass('entree');	
	$('.agenda li:nth-child(7n+4)').addClass('aantal');
	$('.agenda li:nth-child(7n+5)').addClass('info');
	$('.agenda li:nth-child(7n+6)').addClass('reserveren');	
    
	// Load datepicker
	$('#datepicker').datepicker({
			changeMonth: true,
			changeYear: true
	});
	
	// Set dialog
		$( "#cultuur" ).dialog({
			width: 425,
			autoOpen: false,
			show: "blind",
			modal: true
			//hide: "explode",
		});

	// load dialog
		$( ".reserveren" ).click(function() {
			$( "#cultuur" ).dialog( "open");
			return false;
			$(".ui-dialog-titlebar-close", ui).hide();

		});
////////////////////////////////////////////////////////////////////////////////////////////////////
// Agenda module ///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////		

$("#cappellenzaal_tuin").click(function(){
    $(".hider").hide("fast");
    $("#ja").check();
});
$("#cappellenzaal,#regentenkamer").click(function(){
   $(".hider").hide("fast"); 
});



  if (window.location.hash) {
    agenda_direct("direct",window.location.hash.replace( /#post=/,''));
  }
  else {
    agenda(0,0,"load");
  }
  $('.agenda').each(function(){
    $(this).data( 'agenda', {
      cache: {

      }
    });
  });
  $('.agenda a[href^=#]').live( 'click', function(e){
    var state = {},
      id ="post",
      url = $(this).attr( 'href' ).replace( /^#/, '' );
    state[ id ] = url;
    $.bbq.pushState( state );
    return false;
  });

  $(window).bind( 'hashchange', function(e) {

    $('.agenda').each(function(){
      var that = $(this),

        data = that.data( 'agenda' ),
        url = $.bbq.getState( that.attr( 'id' ) ) || '';
    });
  })
  $(window).trigger( 'hashchange' );
  
	
		
});//end ready function
function agenda_direct(actie,id){
        $("#agenda_load").load('/ajax/agenda.php', {
        action:actie,
        post_id:id} 
        );
        $(".agenda_item").load('/ajax/agenda.php', {
        post_id:id,
        action:"more"}
    );    
};
function agenda(maand,jaar,actie){
    $("#agenda_load").load('/ajax/agenda.php', {
        month: maand,
        year:jaar,
        action:actie}
    );
    $('.agenda_item').empty();
    
};
function agenda_detail(id,actie){
    $(".agenda_item").load('/ajax/agenda.php', {
        post_id:id,
        action:actie}
    );    
};
function reserveren(id,sid){
    $('<div>').dialog({
        modal: true,
        open: function ()
        {
            $(this).load('/ajax/reserveren.php',{post_id:id,check_id:sid},function(){$('#reserveren').validate({
                rules: {
                    aanhef: {
                        required: true
                    },
                    achternaam: { 
                        minlength:1,
                        required: true
                    },
                    email: {
                        email:true,
                        required: true
                    
                    },
                    telefoonnummer: {
                        maxlength:11,
                        required: true
                    },
                    aantal_normaal: {
                        required: true,
                        remote: {
                            url: "/ajax/reserveren.php", data:{
                                action:"check",
                                id:$("input[name=checkid]").val(),
                                ssid:$("input[name=sid]").val(),
                                aantal_speciaal: 
                                    function(){
                                        return $("select[name=aantal_speciaal]").val();
                                    }
                                }
                            }
                    },
                    aantal_speciaal: {
                        required: true,
                        remote: {
                            url: "/ajax/reserveren.php", data:{
                                action:"check",
                                id:$("input[name=checkid]").val(),
                                ssid:$("input[name=sid]").val(),
                                aantal_normaal: 
                                    function(){
                                        return $("select[name=aantal_normaal]").val();
                                    }
                                }
                            }
                    }
                }
                // etc
            })});
        },         
        height: 500,
        width: 600,
        resizable: false,
        title: 'Bestellen'
    });   
};
/*!
 * equalWidths jQuery Plugin
 * Examples and documentation at: hhttp://aloestudios.com/tools/jquery/equalwidths/
 * Copyright (c) 2010 Andy Ford
 * Version: 0.1 (2010-04-13)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: jQuery v1.2.6+
 */
 
(function($){
	$.fn.equalWidths = function(options) {
		var opts = $.extend({
			stripPadding: 'none' // options: 'child', 'grand-child', 'both'
		},options);
		return this.each(function(){
			var child_count = $(this).children().size();
			if (child_count > 0) { // only proceed if we've found any children
				var w_parent = $(this).width();
				var w_child = Math.floor(w_parent / child_count);
				var w_child_last = w_parent - ( w_child * (child_count -1) );
				$(this).children().css({ 'width' : w_child + 'px' });
				$(this).children(':last-child').css({ 'width' : w_child_last + 'px' });
				if((opts.stripPadding == 'child') || (opts.stripPadding == 'both')){
					$(this).children().css({
						'padding-right': '0',
						'padding-left': '0'
					});
				}
				if((opts.stripPadding == 'grand-child') || (opts.stripPadding == 'both')){
					$(this).children().children().css({
						'padding-right': '0',
						'padding-left': '0'
					});
				}
			}
		});
	};
})(jQuery);


/* Google Maps settings
function initialize() 
{
    var latlng = new google.maps.LatLng(51.926153, 4.597113);
    var myOptions = {
	zoom: 15,
	center: latlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP,
	mapTypeControl: false,
	streetViewControl: false,
	zoomControl: true,
	zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
	//var image = '/images/icon-gmaps-marker.png';
	var image = new google.maps.MarkerImage('/images/icon-gmaps-marker.png', 
			new google.maps.Size(47, 55), 
			new google.maps.Point(0,0), 
			new google.maps.Point(26, 55));
	
	var shadow = new google.maps.MarkerImage('images/icon-gmaps-shadow.png',
		      new google.maps.Size(75, 55),
		      new google.maps.Point(0,0),
		      new google.maps.Point(26, 55));

	var myLatLng = new google.maps.LatLng(51.926153, 4.597113);
	
	var beachMarker = new google.maps.Marker({
	position: myLatLng,
	map: map,
	shadow: shadow,
	icon: image
  });
}
*/	
