
	jQuery(document).ready(function(){
		calendar_today = new Date;
		jQuery('#pick_a_date').datepicker(
			{
				dateFormat : 'yy-mm-dd',
			onSelect: function(date) {
				jQuery('#traveling_date').val(date);
			},
			beforeShowDay: function(date) {
				if (date < calendar_today) {
					return false;					
				} else {
					return[disabled_days[date.getDay()]];	
				}
			} 	
			}				
		);
        jQuery('.gallery_thumbnail a').lightBox();
		
		jQuery('#ticket_prices').hide();
		//Create the Superfish Menus!
		jQuery("ul.slidingmenu").superfish({
			hoverClass	: "sfHover",
			delay		: 500,
			animation	: {opacity:"show"},
			speed		: "slow"
		});

		jQuery("select#origin_town").change(function(){
			jQuery('#ticket_prices').slideUp('slow');
			jQuery("select#destination_town").html('<option value="-1">Please Wait...</option>');
			
			
			var selectedOrigin = (jQuery(this).val());
			
			//console.log(selectedOrigin);
			
			if (selectedOrigin == 'rockhampton (fri) (terminal)' | selectedOrigin == 'rockhampton (rail)' | selectedOrigin == 'rockhampton (terminal)')
				doTerminalWarning();
			
			
			
			jQuery.getJSON("/includes/getDestinations.php",{id: jQuery(this).val(), ajax: 'true'}, function(j){
			  var options = '';
			      
			  for (var i = 0; i < j.length; i++) {
			    options += '<option value="' + j[i].value + '">' + j[i].name + '</option>';
			  }
			  jQuery("select#destination_town").html(options);
			})
		});
		
		
		
          jQuery("select#destination_town").change(function(){
            if (jQuery(this).val() != -1) {
            jQuery('#ticket_prices').slideUp('slow');
		    jQuery.getJSON("/includes/getPrices.php",{
                origin: jQuery("select#origin_town").val(),
                destination: jQuery("select#destination_town").val(),
                ajax: 'true'
                }, function(j){

		      if (j.length == 1) {

                jQuery("#ticket_origin_town").val(jQuery("select#origin_town").val());
                jQuery("#ticket_destination_town").val(jQuery("select#destination_town").val());
jQuery("select#origin_town").val().substr(0, 1).toUpperCase() + jQuery("select#origin_town").val().substr(1)
                jQuery("span.price_healthcare").html(j[0].healthcare);
                jQuery("span.price_school").html(j[0].school);
                jQuery("span.price_standard").html(j[0].standard);
                jQuery("span.origin_town").html(jQuery("select#origin_town").val().substr(0, 1).toUpperCase() + jQuery("select#origin_town").val().substr(1));
                jQuery("span.destination_town").html(jQuery("select#destination_town").val().substr(0, 1).toUpperCase() + jQuery("select#destination_town").val().substr(1));
                jQuery('#ticket_prices').slideDown('slow');

                price_standard = parseFloat(j[0].standard);
                price_healthcare = parseFloat(j[0].healthcare);
                price_school = parseFloat(j[0].school);
                price_child = parseFloat(0.00);
                jQuery("#ticket_prices select").change();
		
		
		
		
              }


            });

           }

          });
	
          jQuery("#ticket_prices select").change(function(){



            var tickets_standard = parseFloat(jQuery("select[name='standard_tickets'] option:selected").val());
            var tickets_healthcare = parseFloat(jQuery("select[name='healthcare_tickets'] option:selected").val());
            var tickets_school = parseFloat(jQuery("select[name='school_tickets'] option:selected").val());
            var tickets_child = parseFloat(jQuery("select[name='child_tickets'] option:selected").val());

            var all_tickets_cost =
            (price_standard * tickets_standard) +
            (price_healthcare * tickets_healthcare) +
            (price_school * tickets_school) +
            (price_child * tickets_child);
            //alert(price_standard + ' '+ tickets_standard + ' '+ price_healthcare + ' '+ tickets_healthcare + ' '+ price_school + ' '+ tickets_school + ' '+ price_child + ' '+ tickets_child);
            jQuery("#total_ticket_cost").val('$'+all_tickets_cost.toFixed(2));


          });

		
	  
		
	jQuery('#submit_ticket_step_1').click(checktandc);	
		
	});
	
	
	function checktandc() {
			
			if (!jQuery('#accept-t-c').attr('checked')) {
				
				alert('Please read and accept the Terms and Conditions to continue booking your tickets.');
				return false;
			}
			return true;
	}
	
	function showtandc() {
		
		window.open('http://www.paradisecoaches.com.au/pages/terms-and-conditions/popup','terms-and-conditions','scrollbars=yes,resizable=yes,width=550,height=400,left='+(screen.availWidth/2-275)+',top='+(screen.availHeight/2-200)+'');
		
		return false;
		
	}
	
	
	function doTerminalWarning() {
		var terminalwarning = 'Please note that we do not gurantee a tilt train connection coming from Brisbane ' +
		'with our coach departing the railway station at 6:30PM.'+"\n"+"\n"+
		'This is displayed in our terms and conditions and Paradise Coaches takes no ' +
		'responsibility for the Tilt Train not arriving in Rockhampton on time.'+"\n"+"\n"+
		'If notified prior of a late arrival, Paradise Coaches can only wait '+
		'a maximum of 15 minutes for a late Tilt Train.';
		
		
		alert(terminalwarning);
		
	}
