$(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/profile/?user=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"){
		$("form#registerform-tml-main").validate({
			rules: {
				current_ride: {
					required: true
				},
				favorite_vehicle: {
					required: true
				},
				display_my_birthdate_on_my_public_profile: {
					required: true
				},
				gender: {
					required: true
				},
				city: {
					required: true
				},
				country: {
					required: true
				},
				license: {
					required: true
				}
			}
		});
	}
});

