Shadowbox.init({
    modal: true,
    continuous: true,
    displayCounter: false,
    onOpen: function() {
        $('#sb-nav-close').appendTo('#sb-title');
    }
});

function formatText(index, panel) {
  return index + "";
};

function submitTravelPlanner() {
	window.open('','search','width=1000,height=800,menubar=No,toolbars=No,scrollbars=yes,resizable=yes,top=0,left=0');
	$('form.active').submit();
}
function check_cdfs(form) {
	return true;
}
function doSubmit() {
	if (check_cdfs(document.survey)) {
		window.open('','signup','resizable=1,scrollbars=0,width=300,height=150');
		return true;
	}
	else { return false; }
}

$(document).ready(function(){
		/* photo gallery */
		$('#page.property #content .more-photos').click(
			function() {
				Shadowbox.setup($('#page.property #content .photo a'));
				$('#page.property #content .photo a').trigger('click');
				return false;
			}
		);
	
	$('.nav li').hover(
		function () {
			$(this).addClass('hover');
		},
		function () {
			$(this).removeClass('hover');
		}
	);
	
	Date.firstDayOfWeek = 0;
	Date.format = 'mm/dd/yyyy';
	$('.date').datePicker().bind(
		'change keyup',
		function() {
			
			var dateType = $(this).attr('name'),
				thisDate = $(this).val();
			
			$('input[name=' + dateType + ']').val(thisDate);
		}
	);
	$('.date').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_RIGHT);
	$('.date').dpSetOffset(-20, 0);
	
	
	$('.date[name=date1]').bind(
		'dpClosed',
		function(e, selectedDates) {
			
			var d = selectedDates[0];
			
			if (d) {
				d = new Date(d);
				$(this).parents('li').next().find('.date[name=date2]').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	
	$('.date[name=start-date]').bind(
		'dpClosed',
		function(e, selectedDates) {
			
			var d = selectedDates[0];
			
			if (d) {
				d = new Date(d);
				$(this).parents('div').next().find('.date[name=end-date]').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	
	$('#form-selector, #form-lodging').fadeIn().has('ul.col2').addClass('active');
	
	$('#travel-planner .col1, .box .col1')
		.find('input[type=radio]')
			.click(function(){
		
				var clicked = $(this),
					clickedId = clicked.attr('id');
			
				if ($('#form-' + clickedId).hasClass('active')) return;
			
				$('form.active').removeClass('active');			
				$('#form-' + clickedId).addClass('active');
							
				$('#form-lodging:visible, #form-flight:visible, #form-lodging-flight:visible').fadeOut('normal', function(){
					$('#form-' + clickedId).fadeIn();
			})
		});
	
	$('form.active').live('keypress', function(event) {
		if (event.keyCode == '13') {
			event.preventDefault();
			submitTravelPlanner();
		}
	});

	$('#travel-planner-submit a').live('click', function(){
		submitTravelPlanner();
		return false;
	});

	$('a.airport-codes').click(function(){
		window.open(URI_SITE + '/airport-codes.html','airports','width=600,height=725,menubar=No,toolbars=No,scrollbars=Yes,resizable=yes,top=0,left=0');
		return false;
	});
	
	var searchInput = $('#search input.search-input'),
		defaultSearchText = searchInput.val();
		
	searchInput.bind('focusin focusout', function(e){
		var eventType = e.type;
		if (eventType == 'focusin') {
			if (searchInput.val() == defaultSearchText) {
				searchInput.val('');
			}
		} else {
			if (searchInput.val() == '') {
				searchInput.val(defaultSearchText);
			}
		}
	});
	
	jQuery('.marketing-box img').unwrap().prependTo(jQuery('.marketing-box'));
	
});
