//JQUERY DOCUMENT
jQuery.easing.def = "easeOutQuad";
jQuery.validator.messages.required = "Obligatoire";
jQuery.validator.messages.email = "Invalide";
jQuery.validator.messages.number = "Numérique";
jQuery.validator.addMethod("telephone", function(value, element) {
	return this.optional(element) || /([\d]{3}||\([\d]{3}\))[\-\s.]?[\d]{3}[\-\s.]?[\d]{4}/.test(value);
},	"Invalide");
jQuery.validator.addMethod("codepostal", function(value, element){
	return this.optional(element) || /^((([a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}[\s\-]?[0-9]{1}[a-zA-Z]{1}[0-9]{1}))|([0-9]{5}([\-][0-9]{4})?))$/.test(value);
}, "Invalide");
$(function(){
	// MAIN MENU
	// ACCORDION
	//---------------------------------------------------
	var	arraySection = [],
	section = $('#principal').attr('class');
	arraySection[""] = -1;
	arraySection["section-explorer"] = 0;
	arraySection["section-travailler"] = 1;
	arraySection["section-etudier"] = 2;
	arraySection["section-vivre"] = 3;
	section = arraySection[section];
	$.tools.tabs.addEffect("accordion",function(i, done){
		var j = this.getIndex();
		this.getPanes().eq(j).stop(true,true).slideUp(1000,"easeOutBack");
		this.getPanes().eq(i).stop(true,true).slideDown(500,"easeOutBounce");
		done.call();
	});
	$("#menu_principal ul").css({"display":"none","height":"180px"});
	$("#menu_principal").tabs('#menu_principal > ul',{tabs:'h1',event:'mouseover',effect:'accordion',initialIndex:section});
	// SECTION
	// INSTITUTIONS ET ADMISSION
	// ACCORDION
	//---------------------------------------------------
	if($("#institutions").length){
		$(".toggle").slideUp(0);
		$(".toggler").each(function(){
			if($(this).next().hasClass('toggle')){
				$(this).click(function(){
					if(!$(this).hasClass('current')) {
						$('.toggler.current').removeClass('current');
						$('.toggle.current').removeClass('current').slideUp();
						$(this).toggleClass('current');
						$(this).next('.toggle').toggleClass('current').slideToggle();
					}
				});
			}
		});
	}
	// TOGGLE SLIDE CONTENT TEXT
	//---------------------------------------------------
	$(".texteReduction").hide().after('<p class="alignRight" ><a class="lienReduction" href="#" id="maximizeText" >En lire plus</a></p>');
	$(".lienReduction").click(function(){
		$(".lienReduction").fadeOut("fast");
		$(".texteReduction").slideToggle("normal",function(){
			if($(".lienReduction").attr("id") == "maximizeText"){
				$(".lienReduction").html("Réduire").attr("id","minimizeText").fadeIn("fast");
			}else{
				$(".lienReduction").html("En lire plus").attr("id","maximizeText").fadeIn("fast");
			}
		});
		return false;
	});
	// DERNIERS ÉVÉNEMENTS
	// WIDGET
	//---------------------------------------------------
	$(".scrollable").scrollable({easing:"easeOutBack",mousewheel:true,vertical:true});
	// VALIDATION
	// FORMULAIRES DIVERS
	//---------------------------------------------------
	$("form#cse-search-box input[type='text']").focus(function(){
		$(this).select();
	});
	$("form#frmInfolettre input[type='text']").focus(function(){
		$(this).select();
	});
	$("form#frmInfolettre").validate({
		errorPlacement: function(error, element) {
			error.insertBefore(element.prev("label"));
		},
		submitHandler:function(form){
			$(form).ajaxSubmit({
				url:'validinfolettre.php',
				resetForm: true,
				success: function(html){
					alert(html);
				}
			});
		}
	});
	$("form#frm_contact").validate({
		ignore: ".ignore",
		errorPlacement: function(error, element) {
			error.insertBefore(element.prev("label"));
		},
		submitHandler:function(form) {
			$(form).ajaxSubmit({
				url:'validcontact.php',
				resetForm: true,
				success: function(html) {
					alert(html);
				}
			});
		}
	});
	// SI NAVIGATEUR == IE6
	// AJOUTE CLASSES AUX ÉLÉMENTS FORMULAIRE
	//---------------------------------------------------
	if(!$.support.style) {
		$("input[type='button'],input[type='submit'],input[type='reset']").addClass("bouton");
		$("input[type='checkbox']").addClass("checkbox");
		$("input[type='text']").addClass("text");
	}
	// ADDTHIS PANEL
	//---------------------------------------------------
	if($("#addthis").length){
		$("#addthis").removeClass("nodisplay");
	}	
	// FANCYBOX CALL
	//---------------------------------------------------
	if($("a.fancybox").length){
		$("a.fancybox").fancybox({
			'autoScale':false,
			'centerOnScroll':true,
			'opacity':true,
			'overlayColor':'#CCC',
			'padding':0,
			'titlePosition':'inside'
		});
	}
	
	if($("a.fancyboxframe").length){
		$("a.fancyboxframe").fancybox({
			'autoScale':false,
			'centerOnScroll':true,
			'opacity':true,
			'overlayColor':'#CCC',
			'padding':0,
			'titlePosition':'inside',
			'height': "90%",
			'width': 900
		});
	}
	// SECTION
	// NOUVEAUX ARRIVANTS
	//---------------------------------------------------
	if($("#onglets_arrivants").length) {
		$("#tabs").find("a#t6").click(function() {
			window.location.href = $(this).attr("href");
		});
		$("#tabs").tabs("#panes .pane",{
			effect: "fade",
			history: true
		});
	}
	$("form#NouveauxArrivants").validate({
		ignore: ".ignore",
		submitHandler:function(form) {
			$(form).ajaxSubmit({
				url:'validnouveauxarrivants.php',
				resetForm: true,
				success: function(html) {
					alert(html);
				}
			});
		}
	});
	// STICKY BANNER
	//---------------------------------------------------
	if($("#sticky_banner").length) {
		$('#sticky_banner').meerkat({
			height: '130px',
			width: '100%',
			position: 'bottom',
			close: '.close-meerkat',
			delay: 1,
			animationIn: 'slide',
			animationSpeed: 500,
			easingin: 'easeInOutExpo'
		});
	}
	// SECTION
	// HISTOIRES DE PECHE
	//---------------------------------------------------
	$('.peche-vraifaux').css('display', 'none');
	$('.peche-crepas a').click(function() {
		var x = $(this).attr("className");
		if($(this).parent().next().css('display') == 'none') {
			$('.peche-vraifaux').hide('fast');
			$(this).parent().next('#voir_' + x).toggle("fast");
		}
		return false;
	});
	$('.peche-cre a').click(function() {
		var x = $(this).attr("className");
		$('#voir_' + x).toggle("fast");
		$.scrollTo('#top-bloc', {
			duration: 1000,
			easing: 'easeOutExpo'
		});
		return false;
	});
	$('#jumpMenu').change(function() {
		var hash = '#' + $(this).val();
		$.scrollTo(hash, {
			duration: 1000,
			easing: 'easeInOutExpo'
		});
	});
});
