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');
	jQuery('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 */
		jQuery('#page.property #content .more-photos').click(
			function() {
				Shadowbox.setup(jQuery('#page.property #content .photo a'));
				jQuery('#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';
	jQuery('.date').datePicker().bind(
		'change keyup',
		function() {
			
			var dateType = jQuery(this).attr('name'),
				thisDate = jQuery(this).val();
			
			jQuery('input[name=' + dateType + ']').val(thisDate);
		}
	);
	jQuery('.date').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_RIGHT);
	jQuery('.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());
			}
		}
	);
	
	jQuery('#form-selector, #form-lodging').fadeIn().has('ul.col2').addClass('active');
	
	jQuery('#travel-planner .col1, .box .col1')
		.find('input[type=radio]')
			.click(function(){
		
				var clicked = jQuery(this),
					clickedId = clicked.attr('id');
			
				if (jQuery('#form-' + clickedId).hasClass('active')) return;
			
				jQuery('form.active').removeClass('active');			
				jQuery('#form-' + clickedId).addClass('active');
							
				jQuery('#form-lodging:visible, #form-flight:visible, #form-lodging-flight:visible').fadeOut('normal', function(){
					jQuery('#form-' + clickedId).fadeIn();
			})
		});
	
	$('form.active').live('keypress', function(event) {
		if (event.keyCode == '13') {
			event.preventDefault();
			submitTravelPlanner();
		}
	});

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

	jQuery('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').not('.search-bttn').unwrap().insertAfter('.marketing-box h2');
	
});
