$(document).ready(function() {
	$('.theme-eco-initiative .posts').jCarouselLite({
		btnNext:'.theme-eco-initiative .next',
		btnPrev:'.theme-eco-initiative .prev',
		circular:false
	});
	
	$('.theme-lab-report .posts').jCarouselLite({
		btnNext:'.theme-lab-report .next',
		btnPrev:'.theme-lab-report .prev',
		circular:false
	});
	
	$('.theme-small-premium .posts').jCarouselLite({
		btnNext:'.theme-small-premium .next',
		btnPrev:'.theme-small-premium .prev',
		circular:false
	});
	
	$('#theme_menu ul').hide();
	$('#theme_menu').bind('click', function(){
		$('#theme_menu ul').slideToggle();
	});
	
	if(location.search == '?order=alpha'){
		$('.navigation a').each(function(){
			var url = $(this).attr('href');
			$(this).attr('href', url+'?order=alpha');
		});
	}
	
	$("a.FB_Link").live("mouseover", function(){
	  var uid = $(this).parent().attr("uid");
	  $(this).attr("href", "/contributors/fb"+uid);
	});
	
	// clean up registration fields
	if($('#registerform-tml-main').length > 0){
		$('#month').closest('p').add('#day').closest('p').add('#year').closest('p').wrapAll('<fieldset id="birthdate"></fieldset>');
		$('#birthdate').append('<legend>Birthdate</legend>');
		
		var licensehtml = $('#license').closest('label').html();
		var newlicensehtml = licensehtml.split('<br>');
		$('#license').closest('label').html(newlicensehtml[1]);		
	}
	
	if(typeof $.validator != "undefined"){
		$.validator.addMethod("notFBEmail", function(value, element){
			return this.optional(element) || !((new RegExp(/proxymail\.facebook\.com$/)).test(value));
		}, "E-mail address is invalid. Please enter your correct e-mail address.");
	
		$.validator.addMethod("notFBDisplayName", function(value, element){
			return this.optional(element) || !((new RegExp(/^Facebook User$/)).test(value));
		}, "Your display name cannot be \"Facebook User\"");
	
		$("form#your-profile").validate({
			rules: {
				first_name: {
					required: true
				},
				last_name: {
					required: true
				},
				display_name: {
					required: true,
					notFBDisplayName: true
				},
				email: {
					required: true,
					email: true,
					notFBEmail: true
				}
			}
		});
	}
});
