$(document).ready(function() {

/***********************************************
***  EXPANDERS  ********************************
************************************************/

	$('.ts-expanderTrigger').click(function(){
		
			var $this = $(this), li = $this.closest('li'), div = li.find('.ts-expanderContent').stop();
			$('.ts-expanderItems li').not(li).find('.ts-expanderContent').stop().each(function() {
					var $this = $(this);
					$this.css({
							'height': $this.height(),
							'min-height': ''
						}).animate({
								height: '0px'
							}, 500, function() {
									$this.closest('.ts-expanded').removeClass('ts-expanded');
								});
				});
			if(li.is('.ts-is_closing')) {
				li.removeClass('ts-expanded');
			}
			else if(li.is('.ts-is_opening')) {
				li.addClass('ts-expanded');
			}
			if(li.is('.ts-expanded')) {
				li.removeClass('ts-is_opening').addClass('ts-is_closing');
				div.each(function() {
						var $this = $(this);
						$this.css({
								'height': $this.height(),
								'min-height': ''
							}).animate({
									height: '0px'
								}, 500, function() {
										$(this).closest('li').removeClass('ts-expanded ts-is_closing')
									});
					});
			}
			else {
				li.addClass('ts-expanded ts-is_opening').removeClass('ts-is_closing');
				div.animate({
						height: div.data('originalHeight') +'px'
					}, 500, function() {
							$(this).css({
									'min-height': div.data('originalHeight'),
									'height': ''
								});
							li.removeClass('ts-is_opening');
						});
			}

		});
	$('.ts-expanderContent').each(function(){
			var $this = $(this), height = $this.height();
			$this.css({
					height: '0px'
				}).data('originalHeight', height);
		});
	
/***********************************************
***  INITIALIZE DATEPICKER  ********************
************************************************/
	
	$(".ts-datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
	
/***********************************************
***  PROGRESSIVE ENHANCMENT  *******************
************************************************/
	
	$('.ts-ticketTable tr').each(function() {
		$(this).find('th:first, td:first').addClass('ts-first');
		$(this).find('th:last, td:last').addClass('ts-last');
	});
	
/***********************************************
***  SHOW MORE LINK  ***************************
************************************************/
	
	$('.rb-showMoreLink').click(function() {
		$(this).parents('.ts-summaryContainer').addClass('ts-expanded');
		return false;
	});
	
/***********************************************
***  SHOW ROOMS/RATES LINK  ********************
************************************************/
	
	$('.ts-btnShowRoomRates, .ts-btnShowTicketPrices, .ts-btnShowAvailability').click(function() {
		var $this = $(this);
		var content = $this.closest('.ts-expanderContent');
		$this.closest('.ts-expanderContent').find('.ts-ticketTable').removeClass('ts-collapsed');
		$this.parent().hide();
		content.data('originalHeight', content.height());
		return false;
	});

/***********************************************
***  ROOM TYPE POPUPS  *************************
************************************************/

	$('.ts-roomDetailPopup').fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'	:	600, 
		'speedOut'	:	200,
		'overlayColor'	:	'#000',
		'padding'	:	0,
		'scrolling'	:	'no'
	});


});

$('.ts-roomDetail .ts-imgThumbs a').live('click', function(e) {
		e.preventDefault();

		var $this = $(this);
		$this.closest('.ts-roomDetail').find('.ts-imgMain img').attr('src', $this.find('img').attr('src').replace(/\/thumbs\//i, '/large/'));

	});




