$(document).ready(function(){

	$(".button1").hover(function() {
		$(this).attr("src","images/r2_c4.gif");
			}, function() {
		$(this).attr("src","images/r2_c2.gif");
	});
	
	$(".button2").hover(function() {
		$(this).attr("src","images/r4_c4.gif");
			}, function() {
		$(this).attr("src","images/r4_c2.gif");
	});

	$(".button3").hover(function() {
		$(this).attr("src","images/r6_c4.gif");
			}, function() {
		$(this).attr("src","images/r6_c2.gif");
	});

	$(".button4").hover(function() {
		$(this).attr("src","images/r8_c4.gif");
			}, function() {
		$(this).attr("src","images/r8_c2.gif");
	});

	$(".button5").hover(function() {
		$(this).attr("src","images/r10_c4.gif");
			}, function() {
		$(this).attr("src","images/r10_c2.gif");
	});

	$(".button6").hover(function() {
		$(this).attr("src","images/r12_c4.gif");
			}, function() {
		$(this).attr("src","images/r12_c2.gif");
	});
	$(".button7").hover(function() {
		$(this).attr("src","images/r14_c4.gif");
			}, function() {
		$(this).attr("src","images/r14_c2.gif");
	});
	$(".price-btn").hover(function() {
		$(this).attr("src","images/r12_c5.gif");
			}, function() {
		$(this).attr("src","images/r12_c3.gif");
	});
	
	$(".button8").hover(function() {
		$(this).attr("src","images/h_r4_c6.gif");
			}, function() {
		$(this).attr("src","images/h_r2_c6.gif");
	});

	$(".button9").hover(function() {
		$(this).attr("src","images/h_r4_c8.gif");
			}, function() {
		$(this).attr("src","images/h_r2_c8.gif");
	});

	$(".button10").hover(function() {
		$(this).attr("src","images/h_r4_c10.gif");
			}, function() {
		$(this).attr("src","images/h_r2_c10.gif");
	});

	$(".button11").hover(function() {
		$(this).attr("src","images/h_r4_c12.gif");
			}, function() {
		$(this).attr("src","images/h_r2_c12.gif");
	});

	$(".crab").hover(function() {
		$(this).attr("src","images/h_r6_c16.gif");
			}, function() {
		$(this).attr("src","images/h_r3_c16.gif");
	});

	$('#photo').cycle({
		fx: 'fade',// choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed: 600,
		timeout: 2000
	});
	$("#accordion").accordion({
		autoHeight: false,
		navigation: true,
		collapsible: true
	});
	$("#accordion1").accordion({
		autoHeight: false,
		navigation: true,
		collapsible: true
	});
	
	$('#w_date').blur(function() {
		$.getJSON('/reserve/w_date.php', 
		{w_date:$('#w_date').val()}, 
		function(data) {
				var select = $('#voyage');
				var options = select.attr('options');
				$('option', select).remove();
	
			$.each(data, function(index, array) {
				options[options.length] = new Option(array['text'], array['val']);
			});
	
		});
	});

	$('#n_date').blur(function() {
		$.getJSON('/reserve/n_date.php', 
		{n_date:$('#n_date').val()}, 
		function(data) {
				var select = $('#n_voyage');
				var options = select.attr('options');
				$('option', select).remove();
	
			$.each(data, function(index, array) {
				options[options.length] = new Option(array['text'], array['val']);
			});
	
		});
	});

	$('#inn').change(function() {
		$.getJSON('/reserve/n_inn.php', 
		{inn:$('#inn').val()}, 
		function(data) {
				var select = $('#n_inn');
				var options = select.attr('options');
				$('option', select).remove();
	
			$.each(data, function(index, array) {
				options[options.length] = new Option(array['text'], array['val']);
			});
	
		});
	});

	$('#w_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd",
		minDate: '+1d',
		onClose: function(date) {
		  	$("#w_date").blur();
			  xajax_price(xajax.getFormValues('form1'));
		} 
		/*
		function(date) {
			var splitDate = date.split("-");
			var d = new Date(splitDate[0],splitDate[1]-1,splitDate[2]);
			
			$('#voyage option').each(function(){  
				if( $(this).val() == '09:00'){  
					$(this).remove();  
				 }  
			});  
			if( d.getDay()==0 || d.getDay()==6){
				$("select#voyage").html("<option value='09:00'>09:00~11:30</option><option value='14:00'>14:00~16:30</option>"); 
			}else{
			}
		} 
		*/
	});
	
	$('#n_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd",
		minDate: '+1d',
		onClose: function(date) {
		  	$("#n_date").blur();
			  xajax_price(xajax.getFormValues('form1'));
		} 
	});

	$('#rafting_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd",
		minDate: '+1d',
		onClose: function(date) {
			  xajax_price(xajax.getFormValues('form1'));
			  document.form1.pick_date.value = $('#rafting_date').val();
			  document.getElementById("pick").selectedIndex = 1;
		} 
	});

	$('#m_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd",
		minDate: '+1d',
		onClose: function(date) {
			  xajax_price(xajax.getFormValues('form1'));
		} 
	});

	$('#c_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd",
		minDate: new Date(2011, 7, 1),
		onClose: function(date) {
			  xajax_price(xajax.getFormValues('form1'));
		} 
	});
	
	$('#pick_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd",
		minDate: '+1d',
		onClose: function(date) {
			  xajax_price(xajax.getFormValues('form1'));
		} 
	});

	$('#remitDate').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd"
	});
	$('#r_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd"
	});
	$('#inn_date').datepicker({
		changeMonth: true,
		duration: 'fast',
		dateFormat: "yy-mm-dd"
	});
	
	$( "#tabs" ).tabs();
	$( "#pricetabs" ).tabs();
	
	$( "#dialog, #dolphin, #399" ).dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		width: 400
	});

	$( "#inn1, #inn2, #inn3" ).dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		width: 550
	});

	$( "#opener" ).click(function() {
		$( "#dialog" ).dialog( "open" );
		return false;
	});
	
	$( "#opend" ).click(function() {
		$( "#dolphin" ).dialog( "open" );
		return false;
	});

	$( "#open1" ).click(function() {
		$( "#inn1" ).dialog( "open" );
		return false;
	});
	$( "#open2" ).click(function() {
		$( "#inn2" ).dialog( "open" );
		return false;
	});
	$( "#open3" ).click(function() {
		$( "#inn3" ).dialog( "open" );
		return false;
	});

	$( "#open4" ).click(function() {
		$( "#inn1" ).dialog( "open" );
		return false;
	});
	$( "#open5" ).click(function() {
		$( "#inn2" ).dialog( "open" );
		return false;
	});

	$( "#openstart" ).click(function() {
		$( "#399" ).dialog( "open" );
		return false;
	});

	$( "#close" ).dialog();

	$("#form1").validate({

		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			mobil: {
				required: true,
				minlength: 10
			},
			tel: "required",
			contract: "required",
			total_fee: "required"
		},
		messages: {
			name: "請輸入姓名",
			tel: "請輸入市內電話",
			mobil: {
				required: "請輸入手機號碼",
				minlength: "手機號碼應為10個數字"
			},
			email: "請輸入有效的email",
			contract: "請閱讀訂位須知",
			total_fee: "請按下「計算總價」的按鈕"
		}

	});
	
	$("#Submit").click(function(){
		if( $("form").valid() ){
			xajax_price(xajax.getFormValues('form1'));
			document.form1.Submit.value = 'Thank You! 訂單處理中，請稍候...';
			document.form1.Submit.disabled = true;
			xajax_save(xajax.getFormValues('form1'));
			xajax_gmail(xajax.getFormValues('form1'));
		}
	});	

});

