/* Global Javascript File */

jQuery(document).ready(

	function($)
	{
		if ( ! Modernizr.input.placeholder )
		{
			$('#form-booking input, #form-email-gather input').each(

				function()
				{
					$this = $(this);

					$this.val( $this.attr( 'placeholder' ) );
				}

			);

			$('#form-booking input, #form-email-gather input').bind(

				{
					focus: function()
					{
						$this = $(this);

						if ( $this.val == $this.attr( 'placeholder' ) )
						{
							$this.val('');
						}
					},

					blur: function()
					{
						$this = $(this);

						if ( '' == $this.val() )
						{
							$this.val( $this.attr( 'placeholder' ) );
						}
					}
				}

			);
		}
		
		if ( $('#form-booking').length )
		{
			
			$('#form-booking').bind(

				'submit',

				function()
				{
					var check_in = $('input#check_in').val();
					var check_out = $('input#check_out').val();

					var error = false;
					var msg = '';
					var def = 'yyyy/mm/dd';

					if ( '' == check_in || def == check_in )
					{
						error = true;
						msg += 'Check In Date is not valid.' + "\n";
					}

					if ( '' == check_out || def == check_out )
					{
						error = true;
						msg += 'Check Out Date is not valid.' + "\n";
					}

					if ( error )
					{
						alert( 'The following errors were found:' + "\n\n" + msg );

						return false;
					}
					else
					{						
						$('input#full_dates').val( $('input#check_in').val() + ' - ' + $('input#check_out').val() );
						
						return true;
					}
				}

			);
		}
		
		$('input.date').datepicker({ dateFormat: 'yy/mm/dd' });
		
		$('#slideshow').cycle({
			timeout : 5500
		});
	}
	
);
