function ajaxFunction(item, id)
{
	var $ = jQuery;
	
	var previous_label_holder = $('a#a_' + id).next('ins').eq(0);
	// If this tab is already explanded, close it.
	if( $('#' + id+':visible').length > 0 )
	{
		var new_label = previous_label_holder.text();
		previous_label_holder.text( $('a#a_' + id).find('span').text() );
		$('#' + id ).hide();		
		$('a#a_' + id)
			.removeClass('loading')
			.removeClass('active')
			.find('span').text( new_label );
		return;
	}
	
	// Show ajax spinner image.
	$('a#a_' + id)
		.addClass('loading');
		//.find('span').text('');
	
	// Get cabin data and display.
	$.get(item, function(data)
	{
		var new_label = previous_label_holder.text();
		previous_label_holder.text( $('a#a_' + id).find('span').text() );
		$('#'+id).html( data );
		$('#' + id).show();	
		$('a#a_' + id)
			.removeClass('loading')
			.addClass('active')
			.find('span').text( new_label );
	});
}

jQuery(document).ready(function($){
	jQuery(".fare_breakdown_link")
		.click(function(e){
			e.preventDefault();
		})
		.each(function(){
			$(this).qtip({
				content: jQuery(this).next('.fare_breakdown_wrapper').html(),
				position: {
					my: 'top left',
					target: 'mouse',
					viewport: $(window), // Keep it on-screen at all times if possible
					adjust: {
						x: 10,  y: 20
					}
				},
				hide: {
					fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
				},
				style: {
					classes: 'ui-tooltip-shadow ui-tooltip-blue tooltip',
					tip: { corner: false }
				}
			});
		}
	);

	$('li.cabin_details a').live('click',
		function(e)
		{
			e.preventDefault();
			// google analytics tracking
			try
			{
				pageTracker._trackEvent('cabin_description', 'click');
			} catch(e){};

			var new_label = $(this).closest('li').find('ins').text();
			$(this).closest('li').find('ins').text( $(this).text() );
			if( $(this).hasClass('active') )
			{
				$(this)
					.removeClass('active')
					.text( new_label )
					.closest('li').find('ul').slideUp('fast');
			}
			else
			{
				$(this)
					.addClass('active')
					.text( new_label )
					.closest('li').find('ul').slideDown('fast');
			}
		}
	);
});

