$(function()
{
	// Caroussel
	$('#carousel').jCarouselLite({
		auto: 8000
	});
	
	$('#podcast_id_check').attr('align','absmiddle');
	$('#podcast_email_check').attr('align','absmiddle');
	
	$('#carousel ul').css('visibility','visible');
	
	$('#podcast_id').change(function()
	{
		$('#podcast_id_check').attr('src', '/img/icon/wait.gif');	 	 
		$.post('create.php',{ action:'checkid', podcast_id:$(this).val() } ,function(data)
		{
	 		if(data == 'free')
	 		{
	  		$('#podcast_id_check').attr('src', '/img/icon/tick.png');
	  		$('#podcast_id_info').html('');
	  	}
	  	else
	  	{
	   		$('#podcast_id_check').attr('src', '/img/icon/unavailable.png');
	   		$('#podcast_id_info').html(data);
	 		}
		});
	});
	
	if($('#podcast_id').val() != '' && check == true)
	{
		$('#podcast_id_check').attr('src', '/img/icon/wait.gif');	 	 
		$.post('create.php',{ action:'checkid', podcast_id:$('#podcast_id').val() } ,function(data)
		{
	 		if(data == 'free')
	 		{
	  		$('#podcast_id_check').attr('src', '/img/icon/tick.png');
	  		$('#podcast_id_info').html('');
	  	}
	  	else
	  	{
	   		$('#podcast_id_check').attr('src', '/img/icon/unavailable.png');
	   		$('#podcast_id_info').html(data);
	 		}
		});
	}
	
	$('input[name="step1-submit"]').click(function()
	{
		if($('#podcast_id').val() == '') {
			$('#podcast_id_check').attr('src', '/img/icon/unavailable.png');
			$('#podcast_id_info').html(djpod_msg['type_id']);
			return false;
		}
		
		$('#step-1').fadeOut('slow',function()
		{
			$('#step-2').fadeIn();
			$.scrollTo($('#container').get(0),800);
		});
		
		return false;
	});
	
	$('#podcast_email').change(function()
	{
		$('#podcast_email_check').attr('src', '/img/icon/wait.gif');	 	 
		$.post('create.php',{ action:'checkmail', podcast_email:$(this).val() } ,function(data)
	 	{
	  	if(data == 'bad') // mauvais email
	  	{
	   		$('#podcast_email_check').attr('src', '/img/icon/unavailable.png');
	   		$('#podcast_email_info').html(djpod_msg['invalid_mail']);
		  }
		  else if(data == 'ok')
		  {
		  	$('#podcast_email_check').attr('src', '/img/icon/tick.png');
		  	$('#podcast_email_info').html('');
		  }
		  else
		  {
		  	$('#podcast_email_check').attr('src', '/img/icon/unavailable.png');
		  	$('#podcast_email_info').html(data);
		  }
	 	});
	});
	
	$('#podcast_author').click(function() {
		removeActive();
		$('#form-legend-author').addClass('form-legend-active');
	});	
	$('#podcast_author').keypress(function() {
		removeActive();
		$('#form-legend-author').addClass('form-legend-active');
	});
	
	$('#podcast_title').click(function() {
		removeActive();
		$('#form-legend-title').addClass('form-legend-active');
	});	
	$('#podcast_title').keypress(function() {
		removeActive();
		$('#form-legend-title').addClass('form-legend-active');
	});
	
	$('#podcast_site').click(function() {
		removeActive();
		$('#form-legend-site').addClass('form-legend-active');
	});
	$('#podcast_site').keypress(function() {
		removeActive();
		$('#form-legend-site').addClass('form-legend-active');
	});
	
	$('#podcast_desc').click(function() {
		removeActive();
		$('#form-legend-desc').addClass('form-legend-active');
	});
	$('#podcast_desc').keypress(function() {
		removeActive();
		$('#form-legend-desc').addClass('form-legend-active');
	});
	
	$('input[name="step2-submit"]').click(function()
	{
		$('#step-2').fadeOut('slow',function()
		{
			$('#step-3').fadeIn();
			$.scrollTo($('#container').get(0),800);
		});
		
		return false;
	});
	
	$('#podcast_email').click(function() {
		removeActive();
		$('#form-legend-mail').addClass('form-legend-active');
	});
	$('#podcast_email').keypress(function() {
		removeActive();
		$('#form-legend-mail').addClass('form-legend-active');
	});
	
	$('#podcast_pwd').click(function() {
		removeActive();
		$('#form-legend-pwd').addClass('form-legend-active');
	});
	$('#podcast_pwd').keypress(function() {
		removeActive();
		$('#form-legend-pwd').addClass('form-legend-active');
	});
	$('#podcast_pwd_c').click(function() {
		removeActive();
		$('#form-legend-confirm').addClass('form-legend-active');
	});
	$('#podcast_pwd_c').keypress(function() {
		removeActive();
		$('#form-legend-confirm').addClass('form-legend-active');
	});
	
	$('#user_name').click(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	$('#user_name').keypress(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	
	$('#user_firstname').click(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	$('#user_firstname').keypress(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	
	$('#user_address').click(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	$('#user_address').keypress(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	
	$('#user_zipcode').click(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	$('#user_zipcode').keypress(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	
	$('#user_city').click(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	$('#user_city').keypress(function() {
		removeActive();
		$('#form-legend-privacy').addClass('form-legend-active');
	});
	
	$('input[name="step1-back"]').click(function()
	{
		$('#step-2').fadeOut('slow',function()
		{
			$('#step-1').fadeIn();
			$.scrollTo($('#container').get(0),800);
		});
		
		return false;
	});
	
	$('input[name="step2-back"]').click(function()
	{
		$('#step-3').fadeOut('slow',function()
		{
			$('#step-2').fadeIn();
			$.scrollTo($('#container').get(0),800);
		});
		
		return false;
	});
	
	function removeActive()
	{
		$('.form-legend-active').removeClass('form-legend-active');
	}
	
	if(check == true) {
		$('#podcast_id').trigger('change');
	}
});	