$(function(){
	
	$('a.contactLink').colorbox({
		innerWidth: '640px',
		onComplete: function(){setupForm();},
		onClosed: function(){location.reload(true)},
		overlayClose: false,
		scrolling: false
	});	
		
	$('a.cancel').click(function(){
		
		return confirm('Are you sure you wish to cancel this appointment?');
		
	});
		
	$('a.loginLink').colorbox({
		innerWidth: '400px',
		onComplete: function(){setupForm();},
		onClosed: function(){location.reload(true)},
		scrolling: false
	});
		
	$('div#banner ul').innerfade({
		animationtype: 'fade',
		speed: 'slow',
		timeout: 5000,
		type: 'sequence',
		containerheight: '270px'
	});
			
	$('#sideImages').innerfade({
		animationtype: 'fade',
		speed: 'slow',
		timeout: 5000,
		type: 'sequence',
		containerheight: '173px'
	});
	
	$('#diaryNav a').live('click', function(){
		
		$('#diary').fadeTo('fast', 0);
		$("#diary").load($(this).attr('href'), function(){$('#diary').fadeTo('fast', 1);});
		
		return false;
		
	});
	
	$('.slot a').live('click', function(){
		
		if ($(this).hasClass('disabled') == false) {
			$(this).addClass('disabled');
			return true;
		}		
	});
	
	
});

function setupForm() {
	
	
	
	if ($('#Relative0OtherInformation').val() == '') {
		$('#Relative0OtherInformation').val($('#Relative0OtherInformation').attr('title')).addClass('inactive');
	}
		
	$('#Relative0OtherInformation').click(function(){
		
		if ($('#Relative0OtherInformation').val() == $('#Relative0OtherInformation').attr('title')) {
			$('#Relative0OtherInformation').val('').removeClass('inactive');
		}
		
	});
	
	$('#Relative0OtherInformation').blur(function(){
		
		if ($('#Relative0OtherInformation').val() == '') {
			$('#Relative0OtherInformation').val($('#Relative0OtherInformation').attr('title')).addClass('inactive');
		}
		
	});
	
	$('#CustomerAddForm').submit(function(){
		if ($('#Relative0OtherInformation').val() == $('#Relative0OtherInformation').attr('title')) {
			$('#Relative0OtherInformation').val('').removeClass('inactive');
		}
		
		$('#cboxLoadedContent > div').fadeTo('fast', 0);
		
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data){
				$('#cboxLoadedContent > div').html(data);
				$.fn.colorbox.resize();
				setupForm();
				$('#cboxLoadedContent > div').fadeTo('fast', 1);
				
			},
			dataType: 'html'
		});

		return false;
	});
	
	$('#CustomerLoginForm').submit(function(){
		
		$('#cboxLoadedContent > div').fadeTo('fast', 0);
		
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data){
				$('#cboxLoadedContent > div').html(data);				
				setupForm();
				$('#cboxLoadedContent > div').fadeTo('fast', 1);
				
			},
			dataType: 'html'
		});
		return false;
	});
	
}
