$(document).ready( function ( event )
{


	// Therapy slideshow
	if ( $('#TherapiesSlideshow').length > 0 ) {
		$('#NavigateForeward').show().hover(function ( event )
		{
			$(this).stop().animate({
				backgroundPosition: "4px 0"
			}, 80);
		},
		function ( event )
		{
			$(this).animate({
				backgroundPosition: "0 0"
			}, 80);
		});//.click(function(event){event.preventDefault();});
	
		$('#NavigateBackward').show().hover(function ( event )
		{
			$(this).stop().animate({
				backgroundPosition: "0 0"
			}, 80);
		},
		function ( event )
		{
			$(this).animate({
				backgroundPosition: "4px 0"
			}, 80);
		});
	
		function initTherapySlideshow( pluginInstance )
		{
			$('#NavigateBackward').click(function( event ){
				pluginInstance.prev();
				return false;
			});

			$('#NavigateForeward').click(function( event ){
				pluginInstance.next();
				return false;
			});
		}
		
		$('#TherapiesSlideshowContent').jcarousel({
			scroll: 1,
			auto: 0,
			initCallback: initTherapySlideshow,
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
	}
	
	// Team gallery
	if ( $('#TeamGallery').length > 0 ) {
		function placeContentText( element )
		{
			var html = $(element).children('.ContentText').html();
			$('td.Team > .description').remove();
			$(element).parents('td.Team').append('<div class="description">' + html + '</div>');
			$('td.Team .description').hide().fadeIn(500);
		}
		
		
		$('#TeamGallery').parents('td').children('.Intro').remove();
		
		$('#TeamGallery > li:first-child').toggleClass('current');
		
		$('#TeamGallery > li:not(:first-child)').stop().animate({
			opacity: '0.4'
		});
		placeContentText($('#TeamGallery > li.current'));
		
		
		$('#TeamGallery > li').click( function ( event )
		{
			event.preventDefault();
			
			if ($(this).hasClass('current')) return;
			
			$('#TeamGallery > li.current').removeClass('current').stop().animate({
				opacity: 0.4
			});
			
			$(this).addClass('current');
			
			placeContentText(this);
		});
		
		$('#TeamGallery > li').hover(function ( event )
		{
			$(this).stop().animate({
				opacity: 1
			});
		}, function ( event )
		{
			if ($(this).hasClass('current')) return;
			
			$(this).stop().animate({
				opacity: 0.4
			});
		});
		
		
	}
	
	if ( $('#OpeningHours').length > 0 ) {
		
		$('#OpeningHours').addClass('scripted').prepend('<div id="TimeTabs"></div>');
		
		var tabCounter = 1;
		
		$('#OpeningHours .Panel').each(function ( )
		{
			var title = $(this).children('h3.title').html();
			$('#TimeTabs').append('<a href="#" rel="content-' + tabCounter + '">' + title + '</a>');
			$(this).children('h3.title').remove();
			
			$(this).addClass('content-' + tabCounter);
			
			tabCounter++;
		});
		
		$('#OpeningHours .Panel:not(:first)').hide();
		$('#TimeTabs a:first').addClass('current');
		$('#TimeTabs a:not(:first)').addClass('notfirst');
		
		
		$('#TimeTabs > a').click(function ( event )
		{
			event.preventDefault();
			
			if ( $(this).hasClass('current') ) return;
			
			var classSelector = '.Panel.' + $(this).attr('rel');
			$('#OpeningHours .Panel').hide();
			$('#TimeTabs a.current').removeClass('current');
			$(classSelector).show();
			
			$(this).addClass('current');
		});
		
		$('#TimeTabs > a').hover(function( event )
		{
			$(this).stop().animate({
				bottom: '3px'
			}, 100);
		}, function ( event )
		{
			$(this).stop().animate({
				bottom: '0px'
			}, 100);
		});
		
	}
	
	
	if ( $('#PhotoSlideshow').length > 0 ) {
		
		$('#PhotoBackward').show();
		$('#PhotoForward').show();
		
		function initPhotoSlideshow( pluginInstance )
		{
			$('#PhotoBackward').click(function( event ){
				pluginInstance.prev();
				return false;
			});

			$('#PhotoForward').click(function( event ){
				pluginInstance.next();
				return false;
			});
		}
		
		$('#PhotoSlideshow').jcarousel({
			auto: 0,
			initCallback: initPhotoSlideshow,
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
	}
	
	
	if ( $('a.blend').length > 0 ) {
		$('a.blend').animate({
			opacity: 0.75
		}, 0);
		
		$('a.blend').hover(function ( event ) {
			$(this).stop().animate({
				opacity: 1
			}, 100);
		}, function ( event )
		{
			$(this).stop().animate({
				opacity: 0.75
			}, 100);
		});
	}
	
	/*
		Subnavigation
	*/
	$('ul#SiteNavigation > li:has(.Submenu)').each(function( )
	{
		$(this).hover(function( event )
		{
			$(this).children('.Submenu').slideDown(100);
		},
		function( event )
		{
			$(this).children('.Submenu').slideUp(100);
		});
	});
	
	
	
	
	    
	
});
