/* Author: 
Riko Loos 
Verdel ICT & Media
*/

$(document).ready(function(){	
		

		$('a:not(.no-external)').filter(function() {
			//Compare the anchor tag's host name with location's host name
			return this.hostname && this.hostname !== location.hostname;
		}).attr("target", "_blank");

		//Validater script for the contact form
		//$("#contactform").validate();
		
		/* Begin Validator */
		jQuery.validator.messages.required = "";
		$("#contactform").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'Er is 1 veld niet ingevuld. Het is hieronder gemarkeerd'
					: 'Er zijn ' + errors + ' velden niet ingevuld.  Ze zijn hieronder gemarkeerd';
				$("div.error span").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
		});
		$("#stallingform").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'Er is 1 veld niet ingevuld. Het is hieronder gemarkeerd'
					: 'Er zijn ' + errors + ' velden niet ingevuld.  Ze zijn hieronder gemarkeerd';
				$("div.error span").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
		});
		/* End Validator */
		
		
		/* Begin Slider */
		$(function(){
			$('#slides').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				play: 5000,
				pause: 2500,
				hoverPause: true
			});
		});
		/* End Slider */
		
		$(".fancybox").fancybox();
		
		$('#photos').slides({
				preload: true,
				preloadImage: '/img/loading.gif',
				effect: 'slide, fade',
				crossfade: true,
				slideSpeed: 350,
				fadeSpeed: 500,
				generateNextPrev: false,
				generatePagination: false
			});
		
});

//background image fullpage
$(function() {   
		
			var theWindow			= $(window),
			    $bg					= $("#bg"),
			    aspectRatio		= $bg.width() / $bg.height();
			   
			  
			    			    		
			function resizeBg() {
			
			    contentHeight		=  $('#main').height(),
			    mainHeight			=  theWindow.height() - 338;  //270 + 68
			
				if(!(contentHeight > mainHeight)) {
					$('.page #main').height(mainHeight);

				}
				
				
				if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
				    $bg
				    	.removeClass()
				    	.addClass('bgheight');
				} else {
				    $bg
				    	.removeClass()
				    	.addClass('bgwidth');
				}
							
			}
			                   			
			theWindow.resize(function() {
				resizeBg();
			}).trigger("resize");
			
		});
		//datepicker
		
			$(function() {

	            // get today's date
	            var myDate = new Date();
	            // check if the time is later dan 16:30 if so than disable the next day.
	            if (myDate.getHours() >= 17 && myDate.getMinutes() >= 30) {
	                        myDate.setDate(myDate.getDate()+1);
	            } else {
	                myDate.setDate(myDate.getDate()+0);
	
	            };
	            // vairables to calculate the dates
	            var currentTime = new Date()
				var month = currentTime.getMonth() + 1
				var day_1 = currentTime.getDate() +1
				var day = currentTime.getDate()
				var year = currentTime.getFullYear()
	            var date_1 = (day_1 + "-" + month + "-" + year)
	            var date = (day + "-" + month + "-" + year)	            
	            var today = currentTime.getDay()
	            
	            //Dates that cannot be selected
	            var unavailableDates = ["22-1-2012", "29-1-2012","5-2-2012" ];

	            if (month >= "1" && month >="3"){
	            //alert("jahoor");
	            
		         }   



	            // If its saturday you cannot select sunday

	            if (today == 6){
				unavailableDates.push(date_1);			
				}
				
				
				// check the array to disable certain dates
				function unavailable(date) {
				    dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
				    if ($.inArray(dmy, unavailableDates) == -1) {
				        return [true, ""];
				    } else {
				        return [false,"","Unavailable"];
				    }
				}


					// the datepicker function itself
		           $("#datepicker").datepicker({
		            dateFormat: 'dd-mm-yy',
		            minDate: myDate,
					beforeShowDay: unavailable
		            });
            });	
            
            
	

