/* 
	Main JS
*/

$(document).ready(function(){
// --------------------------------------------
//									Autocomplete
// Pour plus d'infos:
// http://jqueryui.com/demos/autocomplete/#custom-data


// --------------------------------------------
//									Datepicker
//
	$.datepicker.regional['fr'] = {
			closeText: 'Fermer',
			prevText: '&#x3c;Préc',
			nextText: 'Suiv&#x3e;',
			currentText: "Choisir aujourd'hui",
			monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
			'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
			monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun',
			'Jul','Aoû','Sep','Oct','Nov','Déc'],
			dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
			dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
			dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
			weekHeader: 'Sm',
			dateFormat: 'dd/mm/yy',
			firstDay: 0,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
		$.datepicker.setDefaults($.datepicker.regional['fr']);
		
	$(".datepicker").datepicker({
		showButtonPanel: true
	});
	
	$(".choixdate").click(function(){
		$(this).prev(".datepicker").datepicker("show");
	});
 
// --------------------------------------------
//									Tooltip
//
	$(".step2").hide();
	
	$("a.tooltip-link").simpletooltip({ 
		click: true,
		showEffect: "fadeIn", 
		hideEffect: "fadeOut",
		//hideOnLeave: false,
		hideDelay: 0.3,
		margin: 0,
		hideCallback: function(tooltip) {
			$(".step2").hide();
		}
	});		
		
		$("a.log").click(function () {
			$(".step1").hide("slow");
			$(".step2").slideDown();
			return false;
		});
		
		$("a.return-step1").click(function () {
			$(".step2").slideUp('fast');
			$(".step1").show("slow");
			return false;
		});
		
		$("a.tooltip-link").click(function () {
			$(".step2").slideUp('fast');
			$(".step1").show();
			return false;
		});
		
	$(".login a.no-js").hide();
	$(".login a.js").show();
	
	$("a.login-link.js").simpletooltip({ 
		click: true,
		showEffect: "fadeIn", 
		hideEffect: "fadeOut",
		//hideOnLeave: false,
		hideDelay: 0.3,
		margin: 20,
		showCallback: function(tooltip) {
			$("a.login-link").addClass('active');
		},
		hideCallback: function(tooltip) {
			$("a.login-link").removeClass('active');
		}
	});
		
// --------------------------------------------
//									Affichage des cartes
//
  $(".map").hide();
	$(".map-bt-arr").click(function () {
		$(this).parent().next(".map").toggle("slow");
		return false;
	});
	$(".map-bt-dep").click(function () {
		$(this).parent().next(".map").toggle("slow");
		return false;
	});
	

	
// --------------------------------------------
//									Formulaires
//
	$('input[type=text]').addClass('inpt');
	
	$('input[type=text]').focus(function(){ 
	    if($(this).val() == $(this).attr('defaultValue')) {
	      $(this).val('').toggleClass('in');
	    }
	  });
	  
	  $('input[type=text]').blur(function(){
	    if($(this).val() == '') {
	      $(this).val($(this).attr('defaultValue')).toggleClass('in');
	    } 
	  });

	
// --------------------------------------------
//									Formulaires
//
	//$(".js-hide").css("display","none");

if($('.horar').height() || $('.tarifs-table').height()){
	$('table tr:odd').addClass('odd'); //zebra action
}

$(".to-show").hide();

$(".aide .accordion").live('click', function(e){
	e.preventDefault();
	$(this).parent().next(".to-show").slideToggle(200);
	$(this).toggleClass('active');
});

$(".tgl-next").live('click', function(e){
	e.preventDefault();
	$(this).next('form').slideToggle(400, function(){
		var txt = $(this).prev('.tgl-next');
		txt.text(function(){
			var newStr = "";
			if(txt.text().split(" ", 1) == "Masquer"){
				newStr = "Afficher" + txt.text().slice(txt.text().indexOf(" "));
				return newStr;
			} else {
				newStr = "Masquer" + txt.text().slice(txt.text().indexOf(" "));
				return newStr;
			}
		});
	});

});

});
