$(document).ready(function() {
	
	$("#contentAux #servicesList").carousel({
		dispItems: 1, 
		pagination: true,
		autoSlide: true,
		delayAutoSlide: 6000,
		autoSlideInterval: 5000
		// animSpeed: 800
		// autoSlideInterval: 5000,
		// delayAutoSlide: 2000,
		// animSpeed: 500,
		// loop: false
	});
	
	var n = $("#courseWrapper ul li").length;
	if (n > 1) {
		$("#courseWrapper").carousel({
			dispItems: 1, 
			pagination: true,
			autoSlide: true,
			delayAutoSlide: 4000,
			autoSlideInterval: 5000
			// animSpeed: 800
			// autoSlideInterval: 5000,
		});
	};
	
	$('a.carousel-control.next').appendTo($('.carousel-pagination'));
	$('a.carousel-control.previous').prependTo($('.carousel-pagination'));
	$('p#viewAllCourses').appendTo($('.center-wrap'));
	
	$("input").focus(function () {
		$(this).css('color','#58585a');
	});
	
	$('input').blur(function() {
		$(this).css('color','#999999');
	});
	
	$("#serviziSuMisura tr:nth-child(even), #serviziStudentiContent tr:nth-child(even)").addClass("even");
	
	$("#registerForm").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
			ripetiEmail: {
				required: true,
				email: true,
				equalTo: "#email"
			},
			password: {
				required: true
			},
			ripetiPassword: {
				required: true,
				equalTo: "#password"
			},
			nome: "required",
			cognome: "required",
			societa: "required",
			indirizzo: "required",
			citta: "required",
			cap: "required",
			provincia: "required",
			giorno: "required",
			mese: "required",
			anno: "required",
			privacy: "required",
            ship_name: "required",
			ship_surname: "required",
			ship_company: "required",
			ship_addr: "required",
			ship_city: "required",
			ship_postal_code: "required",
			ship_country: "required",
			ship_phone: "required",
			telefono: "required"
		}
	});
	
	$("#sendMail").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
			nome: "required",
			cognome: "required",
            privacy: "required",
			telefono: "required"
		}
	});
	
	$("#backendMain .messaggi .resize a, #backendMain .bilanci .resize a").live("click", function(e){
		e.preventDefault();
		$(this).toggleClass('active');
		$(this).parent().parent().siblings().slideToggle('fast');
		var box =$(this).parent().parent().parent().attr("id").substring(3);
        $.get("chiudi.php", { box: box} ); 
	});
	
	$("#backendMain .benvenuto .resize a").live("click", function(e){
		e.preventDefault();
		$(this).toggleClass('active');
		$(this).parent().siblings('.benvenutoContent').slideToggle('fast');
		var box =$(this).parent().parent().parent().attr("id").substring(3);
		$.get("chiudi.php", { box: box} );
	});

	$('th.check input').change(function () {
	    if ($(this).attr("checked")) {
	        $(this).parent().parent().siblings().children('td.check').children().attr('checked', 'true');
	        return;
	    }
	    $(this).parent().parent().siblings().children('td.check').children().removeAttr('checked');
	});
	
	$('#intro.slideshow div').addClass('slide');
	$('#intro.slideshow').cycle();
	
	
	toggleText('emailLogin', 'e-mail');
	toggleText('passwordLogin', 'password');
	
	// $('#extra .login, #extra .user').hover();
	
	$('#extra .login > a, #extra .user > a').bind('click', function(e) {
		e.preventDefault();
		$(this).parent().toggleClass('enable');
	});
	
});


function toggleText(p1, p2){
    $('input'+'#'+p1).focus(function () {
        if (this.value == p2) {this.value = '';}
    });
    $('input'+'#'+p1).blur(function () {
        if (this.value == '') {this.value = p2;}
    });
}
