var ImageSlider = {
	active:0,
	total: 0,
	timeoutTime: 5000,
	fadeTime: 3000,
	init:function(){
		if($('#image').length>0){
			$('#image img').each(function(index){
				img = index;
				if(index == 0){
					$(this).addClass('active');	
				}else{
					$(this).css('display','none');	
				}
				ImageSlider.total = index;
			});
			if(ImageSlider.total){
				setTimeout("ImageSlider.rotate()",ImageSlider.timeoutTime);
			}
		}
	},
	rotate:function(){
		d = $('#image img').get(ImageSlider.active);
		$(d).fadeOut(ImageSlider.fadeTime);
		
		if(ImageSlider.active == ImageSlider.total){
			d = $('#image img').get(0);
			ImageSlider.active = 0;
		}else{
			d = $('#image img').get(ImageSlider.active + 1);
			ImageSlider.active = ImageSlider.active + 1;
		}
		$(d).fadeIn(ImageSlider.fadeTime);
		setTimeout("ImageSlider.rotate()",ImageSlider.timeoutTime);
	}
}
$(document).ready(function() {
	//lightbox
	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme:'facebook',
		allow_resize: false
	});
	$( "#datepicker" ).datepicker({
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true
	});
	var dates = $( "#checkin, #checkout" ).datepicker({
		showOn: "button",
		buttonImage: "fileadmin/gifs/cal.gif",
		buttonImageOnly: true,
		defaultDate: "+1w",
		dateFormat: 'dd.mm.yy', 
		changeMonth: false,
		numberOfMonths: 1,
		firstDay: 1,
		onSelect: function( selectedDate ) {
			/*var option = this.id == "from" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
			*/
		}
	});
	
	
	if($('#online_booking').length>0){
		$('#online_booking').click(function(){
			var checkin = $('#checkin').val();
			var checkout = $('#checkout').val();
			if(checkin == '' || checkout == ''){
				checkin = '';	
				checkout = '';	
			}
			$.prettyPhoto.open('http://hotels.stc.ch/hoteldirect.aspx?idhotel=14026&bs=875&language=de&adults=2&children=0&cribs=0&css=http://www.davcan53.myhostpoint.ch/fileadmin/css/onlinebooking&numrooms=1&checkin='+checkin+'&checkout='+checkout+'&iframe=true&width=780&height=600','Online booking', 'Hotel Restaurant Corvatsch online booking');		
		});
	}
	
	ImageSlider.init();
	
	
});
