function favoris() {
    if ( navigator.appName != 'Microsoft Internet Explorer') {
        window.sidebar.addPanel('Thalazur Thalassothérapie & Spa', 'http://www.thalazur.fr', '');
    } else { 
        window.external.AddFavorite('http://www.thalazur.fr','Thalazur Thalassothérapie & Spa');
    }
}

function thalassoBio() {
	window.location.href = $('#logo-bio-swf-wrap a:first').attr('href');
}

(function($) {
	$.fn.menuRollOver = function() {
		return this.each(function() {
			
			//var itemSelected = $('.item-selected:has(.sous-menu)', this);
			//if (itemSelected.length) $.fn.menuRollOver.Open(itemSelected);
			
			$('.sous-menu', this).each(function() {
				var h = $(this).outerHeight(true)+5;
				$(this).css({top:-h,height:h});
			});
			
			$('.sous-menu li', this).hover(
				function () {$(this).addClass('li-hover');}, 
				function () {$(this).removeClass('li-hover');}
			);
			$('.item:has(.sous-menu)', this).hover(
				function () {$.fn.menuRollOver.Open(this);}, 
				function () {$.fn.menuRollOver.Close(this);}
			);
		});
	};
	
	$.fn.menuRollOver.Open = function(obj) {
		$('.item-titre:gt(0)', obj).remove();
		$('.item-titre', obj).clone().prependTo($('.sous-menu:eq(0)', obj));
		$(obj).addClass('item-show').find('.sous-menu').fadeIn("fast");
	};
	
	$.fn.menuRollOver.Close = function(obj) {
		$(obj).find('.sous-menu').fadeOut("fast");
	};
	
	$.fn.offresV2 = function(options) {
		var defaults = {selector:'.content-wrap'};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var self = $(this);
			var actus = $(options.selector);
			var offres = $('.offre-speciale', actus);
			var interval = null;
			
			$('a.nav-prev', self).click(function () {
				slideSwitch('prev');
				slideStart();
				return false;
			});
			
			$('a.nav-next', self).click(function () {
				slideSwitch('next');
				slideStart();
				return false;
			});
			
			var slideStart = function() {
				clearInterval(interval);
				interval = setInterval(slideSwitch, 10000, 'next');
			};
			
			var slideSwitch = function(action) {
				var active = $(options.selector+':visible', self);
				
				switch(action) {
					case 'prev':
						var next = active.prev(options.selector).length>0 ? active.prev(options.selector) : $(options.selector+':last', self);
						break;
					default:
						var next = active.next(options.selector).length>0 ? active.next(options.selector) : $(options.selector+':first', self);
				}
				active.fadeOut('slow');
				next.fadeIn('slow');
				navSwitch(offres.index($('.offre-speciale:eq(0)', next)));
			};
			
			var navSwitch = function(index) {
				var index = parseInt(index)+1;
				var html = index+1 > offres.length ? index : index+'-'+(index+1);
				$('.nav .counter', self).html(html+'/'+offres.length);
			};
			
			if(actus.length>1) {
				navSwitch(offres.index($(options.selector+':visible .offre-speciale:eq(0)', self)));
				slideStart();
			} else {
				$('.nav', self).hide();
			}
		});
	};
	
	$.fn.offres = function(options) {
		
		var defaults = {selector:'.offre-speciale'};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var self = $(this);
			var actus = $(options.selector);
			var interval = null;
			
			$('a.nav-prev', self).click(function () {
				slideSwitch('prev');
				slideStart();
				return false;
			});
			
			$('a.nav-next', self).click(function () {
				slideSwitch('next');
				slideStart();
				return false;
			});
			
			var slideStart = function() {
				clearInterval(interval);
				interval = setInterval(slideSwitch, 10000, 'next');
			};
			
			var slideSwitch = function(action) {
				var active = $(options.selector+':visible', self);
				
				switch(action) {
					case 'prev':
						var next = active.prev(options.selector).length>0 ? active.prev(options.selector) : $(options.selector+':last', self);
						break;
					default:
						var next = active.next(options.selector).length>0 ? active.next(options.selector) : $(options.selector+':first', self);
				}
				active.fadeOut('slow');
				next.fadeIn('slow');
				navSwitch(actus.index($(next, self)));
			};
			
			var navSwitch = function(index) {
				var index = parseInt(index)+1;
				$('.nav .counter', self).html(index+'/'+actus.length);
			};
			
			if(actus.length>1) {
				navSwitch(actus.index($(options.selector+':visible', self)));
				slideStart();
			} else {
				$('.nav', self).hide();
			}
		});
	};  
})(jQuery);

$(document).ready(function() {
	
	/* -------------------------------------------------------------- 
	   GENERAL
	-------------------------------------------------------------- */
	var params = {wmode:"transparent", menu:"false", quality:'best'};
	var attributes = {};
	var flashvars = {};
	
	//Disparition des éléments .js-timeout
	setTimeout(function () {$('.js-timeout').fadeOut("slow");}, 3000);

	//Menu
	$('#menu').menuRollOver();
	
	//Datepicker
	$.datepicker.regional['fr'] = {
		closeText: 'Fermer',
		prevText: '&#x3c;Préc',
		nextText: 'Suiv&#x3e;',
		currentText: 'Courant',
		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'],
		dateFormat: 'dd-mm-yy', firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['fr']);
	
	/* -------------------------------------------------------------- 
	   INDEX
	-------------------------------------------------------------- */
	var id = $('#index');
	if (id.length == 1) {
		//slideshow sur les actus & les promos
		$(".offres-speciales", id).offres({selector:'.offre-speciale'});
		$(".offres-speciales-v2", id).offresV2();
		
		var content = $('#index .nos-destinations .content');
		content.css('height', $('.content-defaut', content).height()+30);
		var timeout;
		$('#map li a', id).hover(
			function() {
				//$('#index .content-img img').
				var className = $(this).attr('class');
				//var content = $('#index .nos-destinations .content');
				if (!$('.content-selected', content).hasClass(className)) {
					clearTimeout(timeout);
					$('.content-effet', content).removeClass('content-selected').fadeOut();
					$('.content-'+className, content).addClass('content-selected').fadeIn();
					content.css('height', $('.content-'+className, content).height()+30);
				}
			},
			function() {
				//var content = $('#index .nos-destinations .content');
				clearTimeout(timeout);
				timeout = setTimeout(function() {
					$('.content-effet', content).removeClass('content-selected').fadeOut();
					$('.content-defaut', content).addClass('content-selected').fadeIn();
					content.css('height', $('.content-defaut', content).height()+30);
				}, 1000);
			}
		);
		swfobject.embedSWF("/inc/swf/4-avantages.swf", "avantages-swf", "480", "50", "8.0.0", false, {lien:'http://www.thalazur.fr/devis/'}, params, attributes);
	}
	
	/* -------------------------------------------------------------- 
	   HEADER
	-------------------------------------------------------------- */
	var id = $('#header');
	if (id.length == 1) {
		swfobject.embedSWF("/inc/swf/logo-bio.swf", "logo-bio-swf", "75", "61", "8.0.0", false, flashvars, params, attributes);
	}
	
	/* -------------------------------------------------------------- 
	   PRODUITS
	-------------------------------------------------------------- */
	var id = $('#produits');
	if (id.length == 1) {
		var visuel = $('.gammes .visuel', id).css({opacity: 0, marginLeft : -10, marginTop: -10}).animate({opacity: 1, marginLeft: 0, marginTop: 0}, 800);
		$('.gamme .visuel', id).css({opacity: 0}).animate({opacity: 1}, 2000);
		
		$('#boutique_livraison', id).click(function() {
			var checked = $(this).attr('checked');
			if (checked) $('#boutique_livraison_view').hide();
			else $('#boutique_livraison_view').show();
		});
	}
	
	/* -------------------------------------------------------------- 
	   ESPACES
	-------------------------------------------------------------- */
	var id = $('#espaces');
	if (id.length == 1) {
		$('.visuel', id).css({opacity: 0}).animate({opacity: 1}, 800);
	}
	
	/* -------------------------------------------------------------- 
	   CURES
	-------------------------------------------------------------- */
	var id = $('#cures');
	if (id.length == 1) {
		$('a.jsanim', id).click(function () {
			if (!$(this).hasClass('selected')) {
				$('a.jsanim').removeClass('selected');
				$(this).addClass('selected');
				var jsanimConteneur = $('#etiquettes-h146 .jsanim-conteneur');
				//var numSplit = (this.id).split('-');
				//var numVal = numSplit[1];
				var index = $('.'+this.id, jsanimConteneur).index();
				var marginTop = index*-202;
				if (parseFloat(jsanimConteneur.css('marginTop')) == marginTop) return false;
				jsanimConteneur.stop(true, false).css({opacity: 0.5}).animate({opacity: 1, marginTop: index*-202}, 1000);
				return false;
			}
			return true;
		});
		
		$('#etiquettes .etiquette .visuel', id).css({opacity: 0}).animate({opacity: 1}, 800);
		
		$('.jsanim-conteneur .etiquette', id).click(function (e) {
			window.location.href = $('a.info-plus', this).attr('href');
		});
	}
	
	/* -------------------------------------------------------------- 
	   SOINS
	-------------------------------------------------------------- */
	var id = $('#soins');
	
	
	if (id.length == 1) {
		

		if ($('.sstitre', id).length > 1) {
			$('.soin').hide();
		}
		
		$('a.sointoggle', id).click(function () {
			var numSplit = (this.id).split('-');
			var numVal = numSplit[1];
			var soinParent = $('.soinparent-'+numVal);
			if (soinParent.is(':hidden')) soinParent.show(); else soinParent.hide();
			return false;
		});
	}
	/* -------------------------------------------------------------- 
	   PROMOS
	-------------------------------------------------------------- */
	var id = $('#promos');
	if (id.length == 1) {
		$('.visuel', id).css({opacity: 0}).animate({opacity: 1}, 1000);
	}
	
	/* -------------------------------------------------------------- 
	   COMPTE PRO
	-------------------------------------------------------------- */
	var id = $('#compte-pro');
	
	if (id.length == 1) {
		
		$("form[name='espace-pro[connexion][form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				email : $("input[name='espace-pro[connexion][email]']", form),
				mdp : $("input[name='espace-pro[connexion][mdp]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.email.val() != '' && input.mdp.val() != '') form.submit();
			return false;
		});
		
	}
	
	/* -------------------------------------------------------------- 
	   COMPTE CLIENT
	-------------------------------------------------------------- */
	var id = $('#compte-client');
	
	if (id.length == 1) {
		
		$("form[name='espace-client[connexion][form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				email : $("input[name='espace-client[connexion][email]']", form),
				mdp : $("input[name='espace-client[connexion][mdp]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.email.val() != '' && input.mdp.val() != '') form.submit();
			return false;
		});
		
		$("form[name='espace-client[inscription][form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				email : $("input[name='espace-client[inscription][email]']", form),
				mdp : $("input[name='espace-client[inscription][mdp]']", form),
				mdpbis : $("input[name='espace-client[inscription][mdpbis]']", form),
				nom : $("input[name='espace-client[inscription][nom]']", form),
				prenom : $("input[name='espace-client[inscription][prenom]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.email.val() != '' && input.mdp.val() != '' && input.mdpbis.val() != '' && input.nom.val() != '' && input.prenom.val() != '') form.submit();
			return false;
		});
		
		$("form[name='espace-client[profil][form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				email : $("input[name='espace-client[profil][email]']", form),
				nom : $("input[name='espace-client[profil][nom]']", form),
				prenom : $("input[name='espace-client[profil][prenom]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.email.val() != '' && input.nom.val() != '' && input.prenom.val() != '') form.submit();
			return false;
		});	
		
		$("form[name='espace-client[mdp][form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				old : $("input[name='espace-client[mdp][old]']", form),
				_new : $("input[name='espace-client[mdp][new]']", form),
				newbis : $("input[name='espace-client[mdp][newbis]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.old.val() != '' && input._new.val() != '' && input.newbis.val() != '') form.submit();
			return false;
		});		
		
		$("form[name='espace-client[mdpperdu][form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				email : $("input[name='espace-client[mdpperdu][email]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.email.val() != '') form.submit();
			return false;
		});	
	}
	
	/* -------------------------------------------------------------- 
	   BROCHURES
	-------------------------------------------------------------- */
	var id = $('#brochures');
	
	if (id.length == 1) {
		$("form[name='brochures[form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				nom : $("input[name='brochures[nom]']", form),
				prenom : $("input[name='brochures[prenom]']", form),
				email : $("input[name='brochures[email]']", form),
				tel : $("input[name='brochures[tel]']", form),
				port : $("input[name='brochures[port]']", form),
				adresse : $("input[name='brochures[adresse]']", form),
				cp : $("input[name='brochures[cp]']", form),
				ville : $("input[name='brochures[ville]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if (input.nom.val() != '' && input.prenom.val() != '' && input.email.val() != '' && input.adresse.val() != '' && input.cp.val() != '' && input.ville.val() != '') form.submit();
			return false;
		});	
		
		$(".brochure-checkboxes", id).click(function() {
			var code = $(this).attr('value');
			if ($(this).attr('checked'))
				$('#brochure-checkbox-'+code+' input:checkbox').attr('checked', 'checked');
			else
				$('#brochure-checkbox-'+code+' input:checkbox').removeAttr('checked');
		});
		
		$(".brochure-checkboxes-selected", id).each(function() {
			var code = $(this).attr('value');
			$(this).attr('checked', 'checked');
			//$('#brochure-checkbox-'+code+' input:checkbox:not(:eq(1))').attr('checked', 'checked');
			$('#brochure-checkbox-'+code+' input:checkbox').attr('checked', 'checked');
		});
	}
	
	/* -------------------------------------------------------------- 
	   NEWSLETTER
	-------------------------------------------------------------- */
	var id = $('#newsletter');
	
	if (id.length == 1) {
		
		$("form[name='newsletter[form]'] .submit", id).click(function() {
			var form = $(this).parents('form');
			var input = {
				email : $("input[name='newsletter[email]']", form)
			};
			$.each(input, function(k, v) { v.val($.trim(v.val())); });
			if ( input.email.val() != '' ) form.submit();
			return false;
		});	
		
	}
	
	/* -------------------------------------------------------------- 
	   JEU CONCOURS
	-------------------------------------------------------------- */
	var id = $('#jeu-concours');
	
	if (id.length == 1) {
		
		$('.jeu-concours-next, .jeu-concours-prev', id).click(function() {
			var JeuConcoursAnim = $('.jeu-concours-anim');
			var JeuConcoursElement = $(this).parents('.jeu-concours-element');
			var width = parseFloat(JeuConcoursElement.css('width'));
			var index = $(JeuConcoursElement, JeuConcoursAnim).index();
			var margin = $(this).hasClass('jeu-concours-next') ? -(index+1)*width : -(index-1)*width;
			JeuConcoursAnim.stop(true, false).css({opacity: 0.5}).animate({opacity: 1, marginLeft: margin}, 500);
			return false;
		});
		
		$('.jeu-concours-checkbox', id).click(function() {
			var li = $(this).parents('li');
			var ul = li.parents('ul');
			var input = ul.parents('.jeu-concours-element').find('input');
			var index = $(li, ul).index();
			$('li:not(:eq('+index+'))', ul).removeClass('checked');
			
			if (li.hasClass('checked')) {
				li.removeClass('checked');
				input.val('0');
			} else {
				li.addClass('checked');
				input.val(index+1);
			}
			
			return false;
		});
		
		$('.jeu-concours-end', id).click(function() {
			var reponsesUtilisateur = $('.jeu-concours-reponse-utilisateur:input');
			var submit = true;
			reponsesUtilisateur.each(function(k, v) {
				var val = parseFloat($(v).val());
				if (isNaN(val) || val <= 0) submit = false;
			});
			
			if (!submit) alert('Veuillez répondre à toutes les questions.');
			else $(this).parents('form').submit();
			return false;
		});
	}
	
	/* -------------------------------------------------------------- 
	   PRESSE (en parle)
	-------------------------------------------------------------- */
	var id = $('#presse');
	
	if (id.length == 1) {
		$('.presse-lien img', id).animate({opacity: 0.5}, 500);
		$('.presse-lien', id).hover(
			function() {
				$('img', this).animate({opacity: 1}, 500);
			},
			function() {
				$('img', this).animate({opacity: 0.5}, 500);
			}
		);
	}
	
	/* -------------------------------------------------------------- 
	   DESTINATIONS
	-------------------------------------------------------------- */
	/*
	var id = $('#destinations');
	
	if (id.length == 1) {
		var map = $('#map', id);
		var destination = $('.destination', id);
		$('a', map).hover(
			function() {
				$('li', map).removeClass('selected');
				destination.children().hide();
				$('.'+$(this).attr('class'), destination).show();
			},
			function() {
				$(this).parents('li').addClass('selected');
			}
		);
		
	}
	*/
});
