/*
 * Provides AJAX functionality to the website.
 */

$("document").ready(function() {
	/**
	 * Click listener for ajax calls.
	 * This will bind all .ajax-call classes, both present and future, to the click listener.
	 *
	 * @return false
	 */
	$(".ajax-call").live('click', function() {
		// Who's been clicked on?
		var callerId = $(this).attr('id');

		// Default ajax url
		var url = null;

		// Different callers, different actions...
		switch(callerId) {
			case 'getDates':
				//get the id of the queried tour and ajax it.
				var tourIndex = $("#BookingTours").val();

				// if a tour has been selected (must be over 0), ajax it
				if(tourIndex > 0) {
					// construct the url
					url = '/scotlinetours/bookings/tour_dates/tour:' + tourIndex;
					 //ajax it
					$.get(url, function(data) {
						$('#dates').html(data);
					});
				}

				break;

			case 'getProfile':
				// construct url
				url = $(this).attr('href');

				// ajax it
				$.get(url, function(data) {
					$('#profiles').html(data);
				});

				break;

		}
		return false;
	});

});
