$(document).ready(function() {
/*
	if($.browser.msie && $.browser.version != '8.0') {
		alert("Attention : votre navigateur n'est pas à jour\nVous utilisez une version obsolète d'internet explorer. Ceci peut entraîner des dysfonctionnements dans l'affichage du site.\nPour éviter tout problème et pour votre sécurité, veillez à mettre à jour votre système en utilisant l'outil Windows Update,\nou utilisez un navigateur alternatif comme Firefox ou Google Chrome.");
	}
*/
	$('#compass').superfish({
		animation: {
			opacity: 'show',
			height: 'show'
		}
	});
	$('#compass a[href=#]').click(function(event) {
		event.preventDefault();
	});
	$('.scrollpane').jScrollPane({
		scrollbarWidth: 5,
		scrollbarMargin: 20,
		showArrows: true,
		wheelSpeed: 10
	});
	$('.tabs').simplyTabs({
		onShow: function() {
			var h = $('.tab-visible').height();
			$('.simplyTabs').height(h);
		}
	});
	$('.simplyTabs').height($('.tab-visible').height());
	
	/**
	 * NEWSLETTER
	 */
	function resetNewsletterForm() {
		$('#main').fadeTo('slow', 1);
		$('#newsletter-panel').fadeOut('slow', function() {
			$('#newsletter-contact-email').val('entrez votre adresse e-mail');
			$('#newsletter-panel :radio').removeAttr('checked');
			$('#newsletter-contact-response').empty();
		});
	};

	$('#newsletter-contact').ajaxForm({
		target: '#newsletter-contact-response',
		success: function() {
			setTimeout('resetNewsletterForm();', 2500);
		}
	});
	$('#call-newsletter-panel').click(function() {
		$('#newsletter-panel').fadeIn('slow');
		$('#main').fadeTo('slow', 0.3);
	});
	$('#newsletter-contact-cancel').click(function() {
		resetNewsletterForm();
	});
	$('#newsletter-contact-email').focus(function() {
		if($(this).val() == 'entrez votre adresse e-mail') {
			$(this).val('');
		}
	});
	
	/**
	 * BROCHURE
	 */
	function resetBrochureForm() {
		$('#main').fadeTo('slow', 1);
		$('#brochure-panel').fadeOut('slow', function() {
			$('#brochure-contact-name').val('nom');
			$('#brochure-contact-firstname').val('prénom');
			$('#brochure-contact-addr1').val('adresse -- ligne 1');
			$('#brochure-contact-addr2').val('adresse -- ligne 2');
			$('#brochure-contact-cp').val('code postal -- zip');
			$('#brochure-contact-city').val('ville');
			$('#brochure-contact-country').val('pays');
			$('#brochure-contact-response').empty();
		});
	};
	$('#brochure-contact').ajaxForm({
		target: '#brochure-contact-response',
		success: function() {
			setTimeout(function(){resetBrochureForm();}, 2500);
		}
	});
	$('#call-brochure-panel').click(function() {
		$('#brochure-panel').fadeIn('slow');
		$('#main').fadeTo('slow', 0.3);
	});
	$('#brochure-contact-cancel').click(function() {
		resetBrochureForm();
	});
	$('#brochure-contact-name').focus(function() {
		if($(this).val() == 'nom') {
			$(this).val('');
		}
	});
	$('#brochure-contact-firstname').focus(function() {
		if($(this).val() == 'prénom') {
			$(this).val('');
		}
	});
	$('#brochure-contact-addr1').focus(function() {
		if($(this).val() == 'adresse -- ligne 1') {
			$(this).val('');
		}
	});
	$('#brochure-contact-addr2').focus(function() {
		if($(this).val() == 'adresse -- ligne 2') {
			$(this).val('');
		}
	});
	$('#brochure-contact-cp').focus(function() {
		if($(this).val() == 'code postal -- zip') {
			$(this).val('');
		}
	});
	$('#brochure-contact-city').focus(function() {
		if($(this).val() == 'ville') {
			$(this).val('');
		}
	});
	$('#brochure-contact-country').focus(function() {
		if($(this).val() == 'pays') {
			$(this).val('');
		}
	});
	
	/**
	 * SEARCH TOOL
	 */
	var searchTimeout = null;
	///
	$('#searchtool input')
		.focus(function() {
			if($(this).val() == "recherchez ...") {
				$(this).val('');
			}
		})
		.blur(function() {
			if($(this).val() == "") {
				$(this).val("recherchez ...");
			}
		})
		.keyup(function() {
			jElt = $(this);
			clearTimeout(searchTimeout);
			searchTimeout = setTimeout(function() {
				$('#searchresults').remove();
				$.getJSON('/fr/search/all/' + encodeURIComponent(jElt.val()), function(data) {
					$('#searchtool').append(
						$(document.createElement('ul'))
							.attr('id', 'searchresults')
					);
					$.each(data.results, function(i, item) {
						$('#searchresults').append(
							$(document.createElement('li'))
								.append(
									$(document.createElement('a'))
										.attr('href', item.link)
										.text(item.name)
								)
						);
					});
				});
			}, 800);
		});
});