function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

$(document).ready(function(){

	/*
		Sponsors carousel
	*/
	$('#footer .sponsors').jcarousel({
		auto: 2,
        wrap: 'circular',
		scroll: 1,
		animation: 'slow'
	});

	/*
		Switch program
	*/
	$('a.day1').click(function(){
		$('a.day2').removeClass('active');
		$('a.day1').addClass('active');
		
		$('#schedule_day2').fadeOut('fast',function(){
			$('#schedule_day1').fadeIn('fast');
		});
		
		return false;
	});
	$('a.day2').click(function(){
		$('a.day1').removeClass('active');
		$('a.day2').addClass('active');
		
		$('#schedule_day1').fadeOut('fast',function(){
			$('#schedule_day2').fadeIn('fast');
		});
		
		return false;
	});
		
	/*
		Registration
	*/
	$('#registration_submit').click(function() {
        if ($('#name').val() != '' && $('#address').val() != '' && $('#post').val() != '' && $('#country').val() != '' && $('#company').val() != '' && $('#vat').val() != '' && $('#email').val() != '') {
			if (isValidEmailAddress($('#email').val())) {
				$('#content.registration p.error').fadeOut('fast');
				$('#registration_form').ajaxSubmit({
		            url: $('#registration_form').attr('action'),
		            dataType: 'json',
		            success: function(data){
		                if (data.success == true) {
		                    window.location = 'thanks.php'
		                }
		            }
		        });
			} else {
				$('#content.registration p.error').html('Invalid email address').fadeIn('fast');
			}
		} else {
			$('#content.registration p.error').html('All fields are required').fadeIn('fast');
		}
    });
	/*
		Latest news
	*/
	active_news = $('#content.latest .single.active');
	if (active_news.length > 0){
		$('#content.latest .news').fadeOut('fast', function(){
			$(active_news).fadeIn('fast');
		});
	};
    /*
     * Enable this for news details
	$('#content.latest .news h2, #content.latest .news .more').click(function(){
		clicked = $(this);
		$('#content.latest .news').fadeOut('fast', function(){
			$('#content.latest #' + clicked.attr('rel')).fadeIn('fast');
		});
		
		return false;
	});
    */
	$('#content.latest .single .back').click(function(){
		$(this).parent('.single').fadeOut('fast', function(){
			$('#content.latest .news').fadeIn('fast');
		});	
		
		return false;
	});
	/*
		Latest news from footer
	*/
	$('#footer .latest_feed h3').click(function(){
		clicked = $(this);
		
		//window.location = 'latest.php?active=' + clicked.attr('rel');
		window.location = 'latest.php';
		
		return false;
	});
	/*
		About more
	*/
	$('#content.about a.more').live('click', function(){
		$('#content .about_container').fadeOut('fast',function(){
			$('#content').removeClass('about').addClass('international');
			$('#content .international_container').fadeIn('fast');
		});
		
		return false;
	});
	$('#content.international a.back').live('click',function(){
		$('#content .international_container').fadeOut('fast',function(){
			$('#content').removeClass('international').addClass('about');
			$('#content .about_container').fadeIn('fast');
		});
		
		return false;
	});
});
