//Changement de typo
$(document).ready(function(){
		Cufon.replace('#content_home dt', { fontFamily: 'Helvetica Condensed' });
		Cufon.replace('#bloc_gauche dt', { fontFamily: 'Helvetica Condensed' });
		Cufon.replace('#bloc_content h1', { fontFamily: 'Helvetica Condensed' });
		Cufon.replace('#bloc_content h2', { fontFamily: 'Helvetica Condensed' });
		Cufon.replace('#bloc_content h3', { fontFamily: 'Helvetica Condensed' });
		Cufon.replace('#form_contact legend', { fontFamily: 'Helvetica Condensed' });
		Cufon.replace('#bloc_content #page_plan_adresse dt', { fontFamily: 'Helvetica Condensed' });
		
		
});

//Slide pour la fiche artisan
$(function() {
$(".slidetabs").tabs(".images > p", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: "slow"

	// start from the beginning after the last tab
	

// use the slideshow plugin. It accepts its own configuration
}).slideshow();
});

//Overlays 
$(function() {
	$('a[rel]').overlay({ 
		top: 200,
		expose: { 
			color: '#000', 
			loadSpeed: 200, 
			opacity: 0.8 
		}
	});	
});


//Newsletter

$(document).ready(function(){
	$("#newsletter a").click(function(){
		if ($("#bloc_envoie").is(":hidden")){
			$("#bloc_envoie").slideDown("slow",function() {
				$('#inscr_log').focus();
			});
		}
		else{
			$("#bloc_envoie").slideUp("slow");
		}
	})
	
	$('#bloc_envoie form').submit(function() {
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		//Erreur
		if (!filter.test($('#inscr_log').val())) {
			$('#inscr_log').css('border', '1px solid red');
		} else { //C'est valide !
			$("#bloc_envoie").slideUp("slow");
			data = '<div id="contentlight" style="width:500px; background-color: white; border: 2px solid black; padding: 20px; "><p><img style="margin-top:5px; font-weight:bold; color: gray;" src="images/loading.gif" alt="Patientez..." /></p></div>';
			$.lightbox(data);
			
			setTimeout(function() {
				$.ajax({
					url: 'newsletter.php',
					data: 'email=' + $('#inscr_log').val(),
					type: 'post',
					success: function(result) {
						if (result) {
							data = '<p>Votre adresse a bien été ajouté à notre newsletter</p><p><br /><a style="color: #E58415;font-weight: bold;" href="#" onclick="$(\'#lightbox,#lightoverlay\').remove()">Fermer</a></p>';
							$('#contentlight').html(data);
							$('#inscr_log').val('');
						} else {
							data = '<p>Une erreur est survenue pendant l\'ajout de votre adresse</p><p><br /><a style="color: #E58415;font-weight: bold;" href="#" onclick="$(\'#lightbox,#lightoverlay\').remove()">Fermer</a></p>';
							$('#contentlight').html(data);
						}
					}
				});
			}, 1000);
		}
		return false;
	});

	$('#form_contact').submit(function() {
		var safe = true;
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		$('#error_mail,#error_required').hide();
		$('#form_contact').find('.required').removeAttr('style').each(function() {
			var element = $(this);
			if (element.val() == '') {
				safe = false;
				element.css('border', '1px solid red');
				$('#error_required').show();
			}
		});
		if (!filter.test($('#form_contact .email').val())) {
			$('#error_mail').show();
			safe = false;
		}
		return safe;
	});
	
});

function closeForm() { return false; }

(function($) {
	$.lightbox = function(html) {		
		var lightoverlay = $('<div></div>').attr('id', 'lightoverlay').css({
			background: '#000',
			position: 'absolute',
			opacity: 0,
			left: 0,
			top: 0,
			zIndex: 9999
		});
		
		var lightbox = $('<div></div>').attr('id', 'lightbox').css({
			position: 'absolute',
			top: 0,
			opacity: 0,
			left: 0,
			zIndex: 10000
		}).append(html);
		
		$('body').append(lightoverlay).append(lightbox);
		
		lightbox.fadeTo('fast', 1);
		lightoverlay.fadeTo('fast', .8);
		
		lightoverlay.click(close);
		lightbox.find('a.close').click(close);
		
		resizeOverlay();
		centerLightbox();
		
		$(window).resize(resizeOverlay).resize(centerLightbox).scroll(centerLightbox);
		
		function close() {
			lightoverlay.fadeTo(0, 'fast', function() {
				lightoverlay.remove();
			});
			
			lightbox.fadeTo(0, 'fast', function() {
				lightbox.remove();
			});
		}
		
		function resizeOverlay() {
			var window_width = $(window).width();
			var document_height = $(document).height();
			
			$('#lightoverlay').width(window_width).height(document_height);
		}
		
		function centerLightbox() {
			var window_width = $(window).width();
			var document_height = $(window).height();
			
			var lightbox_width = $('#lightbox').width();
			var lightbox_height = $('#lightbox').height();
			
			$('#lightbox').css({
				left: (window_width - lightbox_width) / 2 + 'px',
				top: (document_height - lightbox_height) / 2 + 'px'
			});
		}
	}
	
})(jQuery);



