$.fn.supersized.options = {
	startwidth: 1280,
	startheight: 800,
	slideshow: 0,
	vertical_center: 1,
	transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
	slide_interval: 0
};
$('#supersize').supersized();

$(document).ready(function () {
	$('.thumbnail').click(function() {
		var img = $(this).attr('src').substr($(this).attr('src').lastIndexOf('__')+2);
		$('#mainimage').attr('src','imageresize/286w__212h__'+img).attr('alt', $(this).attr('alt'));
		$('#imagesubscription').html($(this).attr('alt'));
	});
	
	$('#sdate').datepicker({ dateFormat: 'd.mm.yy', maxDate: '+18m', minDate: new Date(), firstDay: 1, onClose: setDateToForm, defaultDate: new Date() });
	$('#strigger').click(function(){$('#sdate').trigger('focus');});
	$('#sd_D,#sd_M').focus(function(){$('#sdate').trigger('focus');});
	
	$('#edate').datepicker({ dateFormat: 'd.mm.yy', maxDate: '+18m', minDate: '+1d', firstDay: 1, onClose: setDateToForm, defaultDate: '+3d' });
	$('#etrigger').click(function(){$('#edate').trigger('focus');});
	$('#ed_D,#ed_M').focus(function(){$('#edate').trigger('focus');});
	
	$('#scout').submit(function(){
		var cimonthyear = $('#sd_M', this).attr('value').split('_');
		var comonthyear = $('#ed_M', this).attr('value').split('_');
	
		var checkin = new Date(cimonthyear[1], cimonthyear[0], $('#sd_D', this).attr('value'));
		var checkout = new Date(comonthyear[1], comonthyear[0], $('#ed_D', this).attr('value'));
		var days = (checkout.getTime()-checkin.getTime())/86400000;
		if(days > 50){ alert("Bitte Urlaubsdauer < 50 Tagen eingeben"); return false;}
		if(days < 1){ alert("Abreisedatum liegt vor dem Ankuftsdatum"); return false;}
		
		var today = new Date();
		if(checkin.getTime()- today.getTime() < 0){ alert("Das angegebene Anreisedatum liegt in der Vergangenheit."); return false;}
		var persons = parseInt($('#a0', this).attr('value'));
		var rooms = parseInt($('#r0', this).attr('value'));
		if(persons == 'NaN' || rooms == 'NaN'){ alert('Bitte geben sie nur Zahlen ein'); return false;}
		
	}); 
	
	$('.angebot a').click(function(){
		$('#angebot-inhalt').load($(this).attr('href') + ' #angebot-inhalt', setMapsonEvent);
		$('.angebot a.active').removeClass('active');
		$(this).addClass('active');
		return false;
	});
	
});

var setDateToForm = function(datestring, datepicker) {
	var datestrings =  datestring.split('.');
	
	var ident = 's';
	if($(this).is('#edate')) ident = 'e';
	
	var $day = $('#' + ident + 'd_D');
	var $month = $('#' + ident + 'd_M');
	
	$day[0].selectedIndex = $('option', $day).index($('option[value*="' + datestrings[0] + '"]', $day));
	$month[0].selectedIndex = $('option', $month).index($('option[value*="' + (datestrings[1]-1) + '_' + datestrings[2] + '"]', $month));
	
}