/*
 * jQuery Dissociated RollOver + Shuttle Request Ajax
 * Script for SeaHorse
 *
 * Copyright (c) 2009-2010 Domenico M. Maresca - domenico.maresca@gmail.com
 *
 * $Date: 2008-01-24, last up 2010-04-15 $
 * $Rev: 0.15.7001 $
 */
 
$(document).ready(function(){
						   
	$('a.fancybox').fancybox({
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		onStart:function(){$('#animation,#places').hide();},
		onClosed:function(){$('#animation,#places').show();}
	});
	
	$(".datepicker").datepicker({
		showOn: 'button',
		buttonImage: '/images/layout/calendar.png',
		buttonImageOnly: true,
		dateFormat: 'yy-mm-dd'
	});
	
	$("a.new").click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	ShuttleRequestHandler();
	ShuttleRequestAddValidator();

	swfobject.embedSWF("/images/contents/box-places.swf", "places", "176", "435", "9.0.0", "/images/contents/expressInstall.swf", null, null, null);
	
	var containerListVehicles = 'div.vehicles-list';
	var contentsContainerVehicles = 'div.vehicles-description';
	var contentItemVehicles = 'div.description';	
	
	var containerListExcursions = '#excursions-list';
	var contentsContainerExcursionss = 'div.container';
	var contentItemExcursions = 'img';	
	
	dissociatedRollOver('click',containerListVehicles,contentsContainerVehicles,contentItemVehicles);
	dissociatedRollOver('mouseover',containerListExcursions,contentsContainerExcursionss,contentItemExcursions);

	$('input[name=service_type]').change(function(){
		try{
			if(this.value=='Single (one way)'){
				$("fieldset.return input,fieldset.return select").attr('disabled','disabled');
			}else{
				$("fieldset.return input,fieldset.return select").attr('disabled','');
			}
		}catch(e){}
	});
	
});


function dissociatedRollOver(action,containerList,contentsContainer,contentItem){
	$(containerList+' ul li a').bind(action,function () {
		var el = $(contentsContainer+' '+contentItem+':not(:hidden)');
		if($(el).attr('id')==$(this).attr('rel')) return
		el.fadeOut("slow");
		$('#'+this.rel).fadeIn("slow");
	});
	$(contentsContainer+' '+contentItem+':not(:first)').each(function(i){
		$(this).hide();
	});
}

function ShuttleRequestAddValidator(){
	$("#ShuttleReqForm").validationEngine({
		validationEventTriggers:"keyup blur",
		success : SendData
	});
}

function SendData(){	
	try{
		var serviceType = $('input[name=service_type]:checked').val();
		var selectTypeTransfer=$('select[name=type_of_transfer]').get(0);
		var selectOutboundHour=$('select[name=outbound_Hour]').get(0);
		var selectOutboundMinute=$('select[name=outbound_Minute]').get(0);
		var selectOutboundPax=$('select[name=outbound_pax]').get(0);
		var selectReturnHour=$('select[name=return_Hour]').get(0);
		var selectReturnMinute=$('select[name=return_Minute]').get(0);
		var selectReturnPax=$('select[name=return_pax]').get(0);
		var formData ={
				action: 'shuttle-request',
				type_of_transfer: selectTypeTransfer.options[selectTypeTransfer.selectedIndex].value,
				pickup_point: $('input[name=pickup_point]').val(),
				destination: $('input[name=destination]').val(),
				transfer_mode: $('input[name=transfer_mode]:checked').val(),
				service_type: $('input[name=service_type]:checked').val(),
				outbound_date: $('input[name=outbound_date]').val(),
				outbound_Hour: selectOutboundHour.options[selectOutboundHour.selectedIndex].value,
				outbound_Minute: selectOutboundMinute.options[selectOutboundMinute.selectedIndex].value,
				outbound_pax: selectOutboundPax.options[selectOutboundPax.selectedIndex].value,
				return_date: $('input[name=return_date]').val(),
				return_Hour: selectReturnHour.options[selectReturnHour.selectedIndex].value,
				return_Minute: selectReturnMinute.options[selectReturnMinute.selectedIndex].value,
				return_pax: selectReturnPax.options[selectReturnPax.selectedIndex].value,
				name: $('input[name=name]').val(),
				phone: $('input[name=phone]').val(),
				flight_details: $('input[name=flight_details]').val(),
				mobile_phone: $('input[name=mobile_phone]').val(),
				email: $('input[name=email]').val()
		}
		if(serviceType=='Single(one way)'){
			formData['return_date']='';
			formData['return_Hour']='';
			formData['return_Minute']='';
			formData['return_pax']='';
		}
		var el = $('<a href="/shuttle-request.php" title="Shuttle Request" class="fancybox"></a>');
		$(el).fancybox({
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 500,
			'height': 320,
			'width': 640,
			onStart:function(){$('#animation').hide();$('#places').show();},
			onClosed:function(){$('#animation').show();$('#places').show();},
			ajax: {type: "POST", data: formData}
		});
		el.click();
	}catch(e){
		alert("Errore: \n"+e);
	}
	
	ShuttleRequestAddValidator();
	return false;
}

function ShuttleRequestHandler(){	
	$("#btnSendShuttleReq").click(function(){
		var newFields = $('<fieldset class="personalData">'+
						'<p><label>Name and Surname</label><input type="text" name="name" id="data[shuttle][name]" class="validate[required,length[5,100]]" /></p>'+
						'<p><label>Flight details</label><input type="text" name="flight_details" id="data[shuttle][flight_details]" class="validate[optional,length[5,100]]" /></p>'+
						'<p><label>Telephone</label><input type="text" name="phone" id="data[shuttle][phone]" class="validate[required,length[5,100]]" /></p>'+
						'<p><label>Mobile Phone</label><input type="text" name="mobile_phone" id="data[shuttle][mobile_phone]" class="validate[optional,length[5,100]]" /></p>'+
						'<p><label>E-mail</label><input type="text" name="email" id="data[shuttle][email]" class="validate[required,custom[email]]" /></p></fieldset>'+
						'<p><input type="submit" class="button" name="" value="Send!" /></p>');
		newFields.hide();
		$('#box-left.shuttleService').animate({height:675},'slow');
		$('#ShuttleReqForm').append(newFields);
		newFields.fadeIn('slow');
		$(this).remove();
		ShuttleRequestAddValidator();
		return false;
	});
	//$("#btnSendShuttleReq").attr('type','button');
	$("#btnSendShuttleReq").attr('value','Continue');
}