// JavaScript Document
//Slide Show
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');
 
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
 
    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
 
    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
 
 
    $active.addClass('last-active');
 
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
 
$(function() {
    setInterval( "slideSwitch()", 5000 );
});


//Availability Form
var reserveForm = null;
function setDates() {
reserveForm = document.getElementById('reservations');
day = new Date();
	var todayDate = day.getDate();
	var todayMonth = day.getMonth();
	todayMonth = todayMonth+1;
	var todayYear = day.getFullYear();
 
	var time = day.getTime(); //get time in millis
	var oneDay = 1000*60*60*24; //determine number of millis in one day
	time = time+oneDay; // add one days worth of millis to the time
 
	day.setTime(time); //set the time 
	var tomorrowDate = day.getDate();
	var tomorrowMonth = day.getMonth();
	tomorrowMonth=tomorrowMonth+1;
	var tomorrowYear = day.getFullYear();
 
	if(todayDate<10)
		todayDate = '0'+todayDate;
	if(tomorrowDate<10)
		tomorrowDate = '0'+tomorrowDate;
 
	reserveForm.arrivalDay.value=todayDate;
	reserveForm.arrivalMonth.value=todayMonth;
	reserveForm.arrivalYear.value = todayYear;
 
	reserveForm.departureDay.value=tomorrowDate;
	reserveForm.departureMonth.value=tomorrowMonth;
	reserveForm.departureYear.value = tomorrowYear;
}
 
function refreshDates()
{
	//get arrrival Date and increment
	var arDay = reserveForm.arrivalDay.value;
	var arMonth = reserveForm.arrivalMonth.value;
	var arYear = reserveForm.arrivalYear.value;
	
 
	day = new Date(arYear, arMonth, arDay);
	var time = day.getTime(); //get time in millis
	var oneDay = 1000*60*60*24; //determine number of millis in one day
	time = time+oneDay; // add one days worth of millis to the time
 
	day.setTime(time); //set the time 
 
	var nextDate = day.getDate();
	var nextMonth = day.getMonth();
	var nextYear = day.getFullYear();
 
	if(nextDate<10)
		nextDate = '0'+nextDate;
 
	if(nextMonth==0)
	{
		nextMonth=12;
		nextYear = nextYear-1;
	}
 
	reserveForm.departureDay.value=nextDate;
	reserveForm.departureMonth.value=nextMonth;
	reserveForm.departureYear.value = nextYear;
}
addLoadEvent(setDates);

