$(document).ready(function(){
	
	if($("#alert-notifications").length)
	{
		$("#alert-notifications").hide();
		
		$("#alert-notifications .alert-notification").css('width', '360px')
		
		$.fancybox(
			$("#alert-notifications").html(),
			{
	        	'autoDimensions'	: true,
	        	'overlayColor'		: 'none',
				'width'         	: 420,
				'height'        	: 'auto',
				'transitionIn'		: 'fade',
				'transitionOut'		: 'none'
			}
		);
	}
	
		
	$("table.floating-header").floatHeader();
	
	/* A nicer submit */
	$('.register-form .submit').hide();
	$('input .hidden').hide();
	
	$('.register-form a.forward').click(function() {
		$('.register-form').submit();
		return false;
	});
	
	
	$('.search-form a.search').click(function() {
		$('.search-form').submit();
		return false;
	});
	
	/* Show hide if refund is selected */
	var TOTAL_PRICE = parseFloat($('#total_price').text());
	
	if($('.register-form input[name="refund"]').attr("checked"))
	{
		$('#insurance').show();
		$('#total_price').text(TOTAL_PRICE+125);
		$('#tax').text( Math.round(0.06*(TOTAL_PRICE+125)*10)/10 );
		
	}
	else
	{
		$('#insurance').hide();
	}
	
	$('.register-form input[name="insurance"]').change(
		function(){
			// Calculate new price
			if($(this).attr("checked"))
			{
				$('#insurance').slideDown();
				$('#total_price').text(TOTAL_PRICE+125);
				$('#tax').text( Math.round(0.06*(TOTAL_PRICE+125)*10)/10 );
			}
			else
			{
				$('#insurance').slideUp();
				$('#total_price').text(TOTAL_PRICE);
				$('#tax').text( Math.round(0.06*(TOTAL_PRICE)*10)/10 );
			}
		}
	);
	
	
	/* Sync club select dropdown with radio buttons */
	$('.register-form select[name="club_id"]').change(
		function(){
			// Remove fancy checkbox/radio buttons
			$('.register-form #fields-membership .radio-club_id span').removeClass('ui-radio-state-checked');
			$('.register-form #fields-membership .radio-club_id label').removeClass('ui-radio-state-checked');
			
			$('.register-form #fields-membership .radio-club_id input').attr('checked', false);
		}
	);
	
	$('.register-form #fields-membership .radio-club_id input').change(
		function(){
			$('select[name="club_id"] option[value="0"]').attr("selected", true);
		}
	);
	
	
	/* A nicer checkbox/radio buttons */
	$('input[type=radio], input[type=checkbox]').checkBox();
	
	
	/* Labels in fields for some inputs */
	$("input.labelify").each(function()
		{
			if( $(this).val() == '')
			{
				$(this).labelify({labelledClass: 'labelified'});
			}
		}
	);
		
	// Dont hide for team register
	if($('#fields-team-name').length != 1)
	{
		function showMembers(class_id)
		{
			if(class_id == 13 || class_id == 19)
			{
				$('#fields-members').slideDown();
			}
			else
			{
				$('#fields-members').hide();
			}
		}
		
		$('.register-form #fields-class input').change(
			function(){
				showMembers($(this).val());
			}
		);
		
		showMembers($('.register-form #fields-class input[checked="checked"]').val());
	}
	
	
	
	
	
	
	if(jQuery.codaSlider || 1 == 1)
	{
	$('#coda-slider-1').codaSlider({
		dynamicTabs: false,
		dynamicArrows: false,
		autoSlide: true,
		autoSlideInterval: 5000,
		autoSlideStopWhenClicked: true
	});
	}
	
	 $('#content table tbody tr:odd').addClass('odd');
	 $('#content table tbody tr:even').addClass('even');
	
	/*
	//	Header navigation
	*/
	
	/*
	$('header ul li:hover ul').css('display', 'none');
	
	
	$('#header ul li').hover(
		function(){
			$(this).find('ul:first').css('display', 'none');
			$(this).find('ul:first').fadeIn(200);
		},function(){
			$(this).find('ul:first').css('display', 'none');
		}	
	);
	*/
	
	$('.page #content img').not($('.page-id-28 #content img')).not($('.page-id-26 #content img')).each(
		function()
		{
			var width = $(this).attr('width');
			var float = $(this).css('float');
			$(this).wrap('<div class="image-shadow-js float-'+float+'" />');
			$(this).wrap('<div class="image-shadow-js-inner" />');
		});
	
	/*
	//	Shortcuts
	*/
	$('#shortcuts-content').hide();
	
	$('#shortcuts-content div#shortcuts-content-partners').hide();
	$('#shortcuts-content div#shortcuts-content-newsletter').hide();
	
	
	function loadContent(content)
	{
		$('#shortcuts-content #shortcuts-content-inner>div').hide();
		$(content).show();
		$('#shortcuts-content').slideDown();
	}
	
	$('#shortcuts a').click(
		function(){
			contenturl = $(this).attr('href');
			
			if($(this).hasClass('active'))
			{
				$(this).removeClass('active');
				$('#shortcuts-content').slideUp();
			}
			else
			{
				$('#shortcuts a.active').removeClass('active');
				$(this).addClass('active');
				$('#shortcuts-content').slideUp(200, function(){loadContent(contenturl)});
			}
			return false;
		}
	);
	
	
	/*
	//	Additional info
	*/
	$('.additional-info').hide();
	
	$('span.additional-info-header').css('cursor', 'pointer')
	
	$('span.additional-info-header').click(
		function(){
			$(this).next('div').slideToggle(200)
			$(this).toggleClass('additional-info-header-active', '')
		}
	);
	
});
