Cufon.replace('h1', { fontFamily: 'Downcome' });
Cufon.replace('h2', { fontFamily: 'Downcome' });
Cufon.replace('h3', { fontFamily: 'DINOT-Black' });
Cufon.replace('h3.euro', { fontFamily: 'DINOT-Bold' });
Cufon.replace('h4', { fontFamily: 'DINOT-Regular' });
Cufon.replace('h6', { fontFamily: 'DINOT-Black' });
Cufon.replace('h6.euro', { fontFamily: 'DINOT-Bold' });

function selectLanguages() {
	$('#language_input').addClass(sLanguage);
	$('#language_container ul li').click(function() {
		var sSelected = $(this).attr('id').replace('language_input_','');
		if(sSelected != sLanguage) {
			if(bWebkey == 'false') {
				switch(sSelected) {
					case 'nederlands':
						window.location=sDomain+sUrl+'?language=nl';
					break;
					case 'duits':
						window.location=sDomain+sUrl+'?language=de';
					break;
				}
			} else {
				var sWebkey = '&webkey=1&page='+nPage;
				switch(sSelected) {
					case 'nederlands':
						window.location='index.php?language=nl'+sWebkey;
					break;
					case 'duits':
						window.location='index.php?language=de'+sWebkey;
					break;
				}
			}
		}
	});
}

function clearInput() {
	$('input.fade').focus(function() {
	   $(this).select();
	   $(this).prev().fadeTo(150, 0);
	   $(this).keydown(function() {
		   $(this).css('background-repeat', 'repeat');                  
	   });
	});
	$('input.fade').blur(function() {
	   if($(this).val() == '' ) {
		   $(this).css('background-repeat', 'no-repeat');
		   $(this).prev().fadeTo(150, 1);
	   }
	});
	$('input.fade').each(function(){
	   if($(this).val() != '') {
		   $(this).css('background-repeat', 'repeat');
	   };
	});
}

function checkBoxes() {
	$('.input_check label').click(function() {
		if($(this).hasClass('checked')) {
			$(this).removeClass('checked').prev().attr('checked', '');
			$(this).parents('.optie').find('.selectbox').val('0');
			var nValue = 0;	
		} else {
			$(this).addClass('checked').prev().attr('checked', 'checked');
			$(this).parents('.optie').find('.selectbox').val('1');	
			var nValue = 1;	
		}
		var sService = $(this).prev('input').val();
		updateStep1(sService, nValue);					
	});
	$('#reservering .selectbox-wrapper ul li').click(function() {
		var nValue = $(this).html();
		var sService = $(this).parents('.optie').find('input.check').val();
		if(nValue != 0) {
			$(this).parents('.optie').find('input.check').attr('checked','checked').next().addClass('checked');
		} else {
			$(this).parents('.optie').find('input.check').attr('checked','').next().removeClass('checked');						
		}
		updateStep1(sService, nValue);					
	});
}

function radioButtons() {
	$('.radio').click(function() {
		if(!$(this).hasClass('checked')) {
			$('.radio').removeClass('checked').find('input').attr('checked','');
			$(this).addClass('checked').find('input').attr('checked','checked');		
		}
	});
}

function hoverPhoto() {
	$('.accommodatie-foto.validhover').hover(function() {
		$(this).find('.accommodatie-foto-overlay').addClass('roll');
	}, function() {
		$(this).find('.accommodatie-foto-overlay').removeClass('roll');
	});
}

function triggerLightbox() {
	$('a.trigger-lightbox').click(function() {
		$(this).next('.lightbox-container').find('a:first').trigger('click');									   
	});
}

function hoverItems() {
	$('.accommodatie').hover(function() {
		$(this).css('background','#f5f5f5');
	}, function() {
		$(this).css('background','');
	});
}

function changeSelectBox() {
	$('.select_overlay').click(function() {
		$(this).hide().parent('.select').find('.selectbox').trigger('click');							
	});
}

function tabs() {
	//linken van tabjes regelen
	var sHash = window.location.hash.replace('#!','');
	if(sHash != ''){
		$('#'+sHash+'_tab').show();
		$('#tabs a[href*="#!'+sHash+'"]').addClass('active');
		if(sHash == 'google-maps') {
			initializeMap(nLatitude, nLongitude);
		}
		if(sHash == 'reserveren') {
			setTimeout("loadCalendar();", 100);
		}
	} else {
		$('#tabs a:first').addClass('active');
		$('.tab_content:first').show();
	}
	
	$('#tabs a:not(.option)').click(function() {
		var sId = this.hash.replace('#!','');
		$('#tabs a').removeClass('active');
		$(this).addClass('active');
		$('.tab_content').hide();
		$('#'+sId+'_tab').show();
		if($(this).hasClass('tab_googlemaps')) {
			initializeMap(nLatitude, nLongitude);
		}
		if($(this).hasClass('tab_reserveren')) {
			setTimeout("loadCalendar();", 100);
		}
	});
	
	$('a.triggertab').click(function() {
		var sID = $(this).attr('class').replace('triggertab ', '');	
		$('#tabs a.tab_'+sID).trigger('click');
	});
}

function loadCalendar() {
	$('#multimonth').datePickerMultiMonth(
			{
				numMonths: 2,
				inline: true,
				selectMultiple: true,
				selectRange: true,
				numSelectable: 2,
				availableDates: sAvailableDates,
				blockedMondays: sBlockedMondays,
				arrivalDays: [1,5],
				nonArrivalDates: sNonArrivalDates,				
				rangeStart: sArrivalJs,
				rangeEnd: sDepartureJs
			}
		).bind(
			'dpMonthChanged',
			function(event, displayedMonth, displayedYear) { }
		).bind(
			'dateSelected',
			function(event, date, $td, status) { }
	);
}

function initializeMap(p_nLatitude, p_nLongitude) {
	var myLatlng = new google.maps.LatLng(p_nLatitude,p_nLongitude);
	var myOptions = {
	  zoom: 16,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("googlemaps"), myOptions);
	
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map
	});   
}

function tellaFriend() {
	$('#tell-a-friend').click(function() {
		if($('#tell-a-friend-content').hasClass('visible')) {
			$('#tell-a-friend-content').slideUp(500, function() {
				$(this).removeClass('visible');														 
			});
		} else {
			$('#tell-a-friend-content').slideDown(700, function() {
				$(this).addClass('visible');																		
			});
		}
	});
}

function sortAccommodations() {
	$('.sorteer-acco .selectbox-wrapper').click(function() {
		var sType = $(this).next().find('option:selected').val();
		$.ajax({
			type: 'POST',
			url: sDomain+'requests/accommodations.req.php',
			data: 'sType='+sType,
			success: function(result){
				var aResult = result.split('||');
				$('.paging').html(aResult[0]);
				$('#overzicht').html(aResult[1]);
				
				hoverItems();
				Cufon.replace('h6', { fontFamily: 'DINOT-Black' });
				Cufon.replace('h6.euro', { fontFamily: 'DINOT-Bold' });
			}
		});
	});
}

function sortKoopAccommodations() {
	$('.sorteer-acco .selectbox-wrapper').click(function() {
		var sType = $(this).next().find('option:selected').val();
		$.ajax({
			type: 'POST',
			url: sDomain+'requests/koopaccommodations.req.php',
			data: 'sType='+sType,
			success: function(result){
				var aResult = result.split('||');
				$('.paging').html(aResult[0]);
				$('#overzicht').html(aResult[1]);
				
				hoverItems();
				Cufon.replace('h6', { fontFamily: 'DINOT-Black' });
				Cufon.replace('h6.euro', { fontFamily: 'DINOT-Bold' });
			}
		});
	});
}

function filterActions() {
	$('.filter-actions .selectbox-wrapper').click(function() {
		var nOfferType = $(this).next().find('option:selected').val();
		$.ajax({
			type: 'POST',
			url: sDomain+'requests/accommodations.req.php',
			data: 'nOfferType='+nOfferType,
			success: function(result){
				var aResult = result.split('||');
				$('.paging').html(aResult[0]);
				$('#overzicht').html(aResult[1]);
				
				hoverItems();
				Cufon.replace('h6', { fontFamily: 'DINOT-Black' });
				Cufon.replace('h6.euro', { fontFamily: 'DINOT-Bold' });
			}
		});
	});
}

function filterAccommodations() {
	var sValues = '';
	$('#facilities .input_check label').click(function() {
		var nFacilitie = $(this).prev().val();
		var bChecked = false;
		if($(this).hasClass('checked')) {
			bChecked = true;
		}
		sValues = '&nFacilitie='+nFacilitie+'&bChecked='+bChecked;
		
		updateAccommodations(sValues);
	});
	$('#naamaccommodatie').blur(function() {
		var sKeywords = $(this).val();
		sValues = '&sKeywords='+sKeywords;
		
		updateAccommodations(sValues);
	});
	$('#naamaccommodatie').keydown(function(e){
		if(e.keyCode == 13) {
			var sKeywords = $(this).val();
			sValues = '&sKeywords='+sKeywords;
			
			updateAccommodations(sValues);
		}
	});
	$('#start-date').change(function() {
		var sStartDate = $(this).val();
		sValues = '&sStartDate='+sStartDate;

		updateAccommodations(sValues);	
	});
	$('#end-date').change(function() {
		var sEndDate = $(this).val();
		sValues = '&sEndDate='+sEndDate;

		updateAccommodations(sValues);	
	});
//	$('#gewenstemaand_container').click(function() {
//		var nMonth = $(this).next().find('option:selected').val();
//		sValues = '&nMonth='+nMonth;
//		
//		updateAccommodations(sValues);
//	});
//	$('#gewensteperiode_container').click(function() {
//		var nPeriod = $(this).next().find('option:selected').val();
//		sValues = '&nPeriod='+nPeriod;
//		
//		updateAccommodations(sValues);
//	});
	$('#aantalpersonen_container').click(function() {
		var nMaxPersons = $(this).next().find('option:selected').val();
		sValues = '&nMaxPersons='+nMaxPersons;
		
		updateAccommodations(sValues);
	});
	$('#maximumprijs_container').click(function() {
		var nMaxPrice = $(this).next().find('option:selected').val();
		sValues = '&nMaxPrice='+nMaxPrice;
		
		updateAccommodations(sValues);
	});
}

function updateAccommodations(p_sValues) {
	$.ajax({
		type: 'POST',
		url: sDomain+'requests/accommodations.req.php',
		data: 'bFilter=true'+p_sValues,
		success: function(result){
			var aResult = result.split('||');
			$('.paging').html(aResult[0]);
			$('#overzicht').html(aResult[1]);
			
			hoverItems();
			Cufon.replace('h6', { fontFamily: 'DINOT-Black' });
			Cufon.replace('h6.euro', { fontFamily: 'DINOT-Bold' });
		}
	});
}

var bFirst = true;
function updateReservation(p_sStartDate,p_sEndDate,p_bReset) {
	if(p_bReset) {
		bFirst = true;
	}
	if(bFirst) {
		bFirst = false;
		
		var sStartDate = '';
		var sEndDate = '';
		
		sStartDate = p_sStartDate.replace(/ /gi,'-');
		if(!p_bReset) {
			sEndDate = p_sEndDate.replace(/ /gi,'-');
		} 

		$('.input_arrival').html(sStartDate);
		$('input.arrival').val(sStartDate);
		$('.input_departure').html(sEndDate);
		$('input.departure').val(sEndDate);
		
		$.ajax({
			type: 'POST',
			url: sDomain+'requests/updateprice.req.php',
			data: 'sStartDate='+p_sStartDate+'&sEndDate='+p_sEndDate+'&nID='+nID,
			success: function(result){
				var aResult = result.split('||');
				if(aResult[0] != '') {
					$('.row.error').remove();
					$('#price_reserveren').html('&euro; '+aResult[0]);
					$('#rentalprice').val(parseInt(aResult[1]));
				} else {
					$('#price_reserveren').html('');
					$('#rentalprice').val('');
				}
			}
		});
	} else {
		bFirst = true;	
	}
}

function updateStep1(p_sService, p_nValue) {
	$.ajax({
		type: 'POST',
		url: sDomain+'requests/updatestep1.req.php',
		data: 'sService='+p_sService+'&nValue='+p_nValue,
		success: function(result){
			var aResult = result.split('||');
			if(aResult[1] == '&euro;0,-') {
				aResult[1] = '-';
			}
			$('#prijs_'+aResult[0]).html(aResult[1]);
			$('#prijs_extrakosten').html(aResult[2]);
			$('.prijs.totaal').html(aResult[3]);
			$('.prijs.annulering').html(aResult[4]);
			$('.prijs.cleaning').html(aResult[5]);
			console.log(result);
			if(aResult[6] == 'true') {
				$('.check_cleaning').addClass('hide');
				$('.kosten.cleaning').css('cursor','default');
			} else if(aResult[6] == 'false') {
				$('.check_cleaning').removeClass('hide');
				$('.kosten.cleaning').css('cursor','pointer');
			}
		}
	});
}

function cancellation() {
	$('.check_annulering, .kosten.annulering').click(function() {
		var nChecked = 1;
		if($(this).hasClass('checked')) {
			$('.check_annulering').removeClass('checked');
			$('.kosten.annulering').removeClass('checked');
			nChecked = 0;
		} else {
			$('.check_annulering').addClass('checked');
			$('.kosten.annulering').addClass('checked');
		}
		updateStep1('annuleringsverzekering', nChecked);
	});
	$('.check_cleaning, .kosten.cleaning').click(function() {
		var nChecked = 1;
		if($(this).hasClass('checked')) {
			$('.check_cleaning').removeClass('checked');
			$('.kosten.cleaning').removeClass('checked');
			nChecked = 0;
		} else {
			$('.check_cleaning').addClass('checked');
			$('.kosten.cleaning').addClass('checked');
		}
		updateStep1('schoonmaakkosten', nChecked);
	});
}

function infoStep1() {
	var nSpeed = 650;
	$('.info-icon').click(function() {
		var aClass = $(this).attr('class').split(' ');
		if($('.info-block.'+aClass[1]+'').hasClass('show')) {
			$('.info-block.'+aClass[1]).removeClass('show').slideToggle(nSpeed);
		} else {
			$('html').animate({ scrollTop: $(document).height() }, nSpeed, function() {
				$('.info-block.'+aClass[1]).addClass('show').slideToggle(nSpeed);
			});
		}
	});
	$('.info-block .close').click(function() {
		$(this).parents('.info-block').removeClass('show').slideToggle(nSpeed);
	});
}

