$(document).ready(function() {

	$('#selSearch').val('none');
	$("#selSearch").change(function() {
		var nOac = $('#selSearch').val();
		if(window.location.hostname.toLowerCase().indexOf("deals2cancun") !== -1){
			var nLocation =  "/vacations/specials.php?oac=" + nOac
		}else{
			var nLocation =  "/vacations/funjet/hotdeals/specials.php?oac=" + nOac
		}
		window.location = nLocation;
	});

	$("div.oneResort").hover( function() {
		$(this).css("background-color", "#E7E7E7");
	}, function() {
		$(this).css("background-color", "#F7F7F7");
	});

	$(".colorbox").colorbox({width:"550px"},function(){
		afterModal();	
	});

	$(".directSearch").change(function(){
		$.fn.colorbox({href:$(this).val(), open:true, width:"550px"},function(){
			afterModal();	
		}); 
	});

	function afterModal(){
		$("#tblAges").hide();
		$("#kids").change(function() {
			if ($("#kids").val() != 0) {
				$("#tblAges").show();
				var sels = $("#kids").val();
				for (i=0;i<4;i++) {
					if(i<sels) {
						$("#agesSecond"+i).show();
					} else {
						$("#agesSecond"+i).hide();
					}
				}
			} else {
				$("#tblAges").hide();
			}
		});
		$('#selNights').change(function() {
			var str = $(this).attr('title').split(':');
			
			$.getJSON('fjsprocNW.php', {
				details: true,
				nightsPrice: $(this).val(),
				hpc: str[0],
				oac: str[1]
			}, function(json) {
				$('#selDates').html(json['selDates']);
				$('#divDesc3').html(json['divDesc3']);
				$('#divDesc4').html(json['divDesc4']);
				$('#ddates').html(json['ddates']);
				$('#dow').html(json['dow']);
			});
		});
		$('#selDates').change(function() {
			var datestr = $('#selDates').val().split('-');
			$('#hdnDeptdate1').val(datestr[0]);
			$('#hdnDestdate1').val(datestr[1]);		
			$('#deptdate1').val(datestr[0]);
			$('#destdate1').val(datestr[1]);
		});
		$("#frmVacInject").submit(function() {
      if ($("#selDates").val() == "none") {
				alert('Please select a date');
				return false;
      }
			return true;
    });
	}
});
