﻿$(document).ready(function() {


	/*Custom select boxes*/
	$('form#resForm select, form#contact_form select')
	.styledSelect({
	}).parents('form').show();
	
	/**********   Datepicker for booking widget **********/
	$(function() {
		$('#linkedDatepicker')
			.datepicker({
				dateFormat: 'dd/mm/yy',
				beforeShow: readLinked,
				onSelect: updateLinked,
				showOtherMonths:false,
				selectOtherMonths:false,
				mandatory: true,
				changeMonth: false,
				changeYear: false, 
				minDate: '+0D',
				maxDate: '+1Y',
				showOn: 'both', buttonImageOnly: true, buttonImage: location.protocol + '//' + location.host + '/images/img_gfx/icon_calendar.gif'}); 
		 
		// Prepare to show a date picker linked to three select controls  
		function readLinked() {

			$('#linkedDatepicker').val( $('#checkin_day').val() + '/' + $('#checkin_month_year').val()  );
			
			/*extra stuff for custom select*/
			$('#datepicker1 li').attr({ rel : $('#arrival2 li').attr('rel') + '/' + $('#arrival1 li').attr('rel') });
			
			return {};  
		}  
	  
		// Update three select controls to match a date picker selection  
		function updateLinked(date) { 
			$('#checkin_month_year').val(	date.substring(3, 11) );  
			$('#checkin_day').val(	date.substring(0, 2)	);			
			
			/*extra stuff for custom select*/
			$('#arrival2 li').html( $('#checkin_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
			$('#arrival1 li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	}); 
		}
		
		$('#linkedDatepicker2')
			.datepicker({
				dateFormat: 'dd/mm/yy',
				beforeShow: readLinked2,
				onSelect: updateLinked2,
				showOtherMonths:false,
				selectOtherMonths:false,
				mandatory: true,
				changeMonth: false,
				changeCurrent:false,
				changeYear: false,
				minDate: '+1D',
				maxDate: '+1D +1Y', 
				showOn: 'both', buttonImageOnly: true, buttonImage: location.protocol + '//' + location.host + '/images/img_gfx/icon_calendar.gif'}); 
		
		 
		// Prepare to show a date picker linked to three select controls  
		function readLinked2(input, inst) {
			var minday = $('#checkin_day').val();
			var minmonth = ( $('#checkin_month_year').val() ).substring(0,2);
			var minyear = ( $('#checkin_month_year').val() ).substring(3,8);			

			$('#linkedDatepicker2').val( $('#checkout_day').val() + '/' + $('#checkout_month_year').val()  );
			
			/*extra stuff for custom select*/
			$('#datepicker2 li').attr({ rel : $('#departure2 li').attr('rel') + '/' + $('#departure1 li').attr('rel') });
			
			return {minDate:new Date(minyear, minmonth-1, minday)};			
		}  
	  
		// Update three select controls to match a date picker selection  
		function updateLinked2(date) { 
			$('#checkout_month_year').val(	date.substring(3, 11) );  
			$('#checkout_day').val(	date.substring(0, 2)	); 
			
			/*extra stuff for custom select*/
			$('#departure2 li').html( $('#checkout_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
			$('#departure1 li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	}); 			
		}
	});

});


/*
 * jQuery Styled Select Boxes
 * version: 1.1 (2009/03/24)
 * @requires jQuery v1.2.6 or later
 *
 * Examples and documentation at: http://code.google.com/p/lnet/wiki/jQueryStyledSelectOverview
 *
 * Copyright (c) 2008 Lasar Liepins, liepins.org, liepins@gmail.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
jQuery.fn.styledSelect=function(settings){settings=jQuery.extend({selectClass:'styledSelect',openSelectClass:'open',optionClass:'option',selectedOptionClass:'selected',closedOptionClass:'closed',firstOptionClass:'first',lastOptionClass:'last',zIndexApply:false,zIndexStart:250,deactiveOnBackgroundClick:true},settings);var currentZIndex=settings.zIndexStart;this.each(function(){var s=jQuery(this);var cs=jQuery('<div></div>').attr('class',settings.selectClass);if(settings.zIndexApply){cs.css('z-index',currentZIndex-2);};var csl=jQuery('<ul></li>');if(settings.zIndexApply){csl.css('z-index',currentZIndex-1);};cs.append(csl);s.hide(0).after(cs);cs=s.next();jQuery('option',s).each(function(){if(jQuery(this).attr('value')==undefined){jQuery(this).attr('value',jQuery(this).text());}});var closedSelect=function(){jQuery('ul',cs).html('');addOption(s.val(),jQuery(':selected',s).text(),clickSelect);cs.removeClass(settings.openSelectClass);jQuery('ul li',cs).removeClass(settings.selectedOptionClass).removeClass(settings.optionClass).addClass(settings.closedOptionClass);if(settings.deactiveOnBackgroundClick){$(document).unbind('mousedown',closedSelect);cs.unbind('mousedown');}};var clickSelect=function(){jQuery('ul',cs).empty();jQuery('option',s).each(function(i){addOption(jQuery(this).val(),jQuery(this).text(),clickOption);});cs.addClass(settings.openSelectClass);jQuery('ul li:first-child',cs).addClass(settings.firstOptionClass);jQuery('ul li:last-child',cs).addClass(settings.lastOptionClass);if(settings.deactiveOnBackgroundClick){$(document).bind('mousedown',closedSelect);cs.bind('mousedown',function(){return false;});}};var clickOption=function(){var val=jQuery(this).attr('rel');s.val(val);closedSelect();};var addOption=function(optVal,optName,callBack){var cso=jQuery('<li></li>').attr('rel',optVal).text(optName).click(callBack).addClass(settings.optionClass);if(settings.zIndexApply){cso.css('z-index',currentZIndex);};if(s.val()==optVal){cso.addClass(settings.selectedOptionClass);};jQuery('ul',cs).append(cso);};closedSelect();s.change(closedSelect);currentZIndex-=3;});return this;};
