//<![CDATA[

// EXTEND JQUERY SCROLLTO
jQuery.fn.extend({
	scrollTo : function(speed, easing) {
		return this.each(function() {
			var targetOffset = $(this).offset().top;
			jQuery("html,body").animate({scrollTop: targetOffset}, speed, easing);
		});
	}
});

// CARROUSEL HOME PAGE
carrouselHomePage = function() {
	if (jQuery("#slideShow").length) {
		jQuery("#slideShow").cycle({
		  fx: 'fade',
		  speed: 'fast',
		  timeout: 4000,
		  pager: '#navSlideShow',
		  pagerEvent: 'click',
		  pagerAnchorBuilder: function(idx, slide) {
			  return '#navSlideShow li:eq(' + (idx) + ') a';
		  }
		});
	}
}

// CHECK COMMENTS FORM
checkFormComments = function() {
	jQuery("#commentform").validate({
		rules: {
			author: "required",
			email: {required:true, email:true},
			comment: "required"
		},
		messages: {
			author: "Veuillez saisir votre pseudo",
			email: {required:"Veuillez saisir votre email", email:"Cette adresse email est incorrecte"},
			comment: "Veuillez saisir votre message"
		},
		showErrors: function (errors, validator) {
			if (this.errorList.length) {
					jQuery("#errorMessage").fadeIn();
					jQuery("#errorMessage").html("<p>Les champs indiqués ci-dessous sont mal renseignés :<\/p>");
					jQuery("#errorMessage").scrollTo(1000);
			} else {
				jQuery("#errorMessage").hide();
			}
			this.defaultShowErrors();
		},
		focusInvalid: false,
		onfocusin: false,
		onkeyup: false,
		onclick: false,
		onfocusout: false,
		errorLabelContainer: jQuery("#errorMessage")
	});
	
}

// COMMENTS DOM MANIPULATION
commentsDomManipulations = function() {
	if (jQuery(".commentlist").length) {
		jQuery(".commentlist").after(jQuery("#respond"));
		jQuery(".commentlist").after(jQuery("#respond h3.reply"));
	}
	else
		if ( jQuery("#respond").length )
			jQuery("#respond").show();
	
	if (jQuery("#content h3.reply").length) {
		jQuery("#content h3.reply").click(function() {
			jQuery("#respond").show('slow');
    });
	}
}

jQuery(document).ready(function() {
	carrouselHomePage();
	checkFormComments();
	commentsDomManipulations();
});
//]]>
