$(function() {
	
	$("input#sendContact").click(function() {
		test = checkRequieredFields('contactForm');
		if(test==true){
		
			monNom = $("#nom").attr("value");
			monPrenom = $("#prenom").attr("value");
			monEmail = $("#email").attr("value");
			monTel = $("#tel").attr("value");
			monAdresse = $("#adresse").attr("value");
			monCp = $("#cp").attr("value");
			monVille = $("#ville").attr("value");
			monPays = $("#pays").attr("value");
			monPersonne = $("#personne").attr("value");
			monMessage = $("#message").attr("value");
					
		$("#monCallback").load("ajax-contact.php", { 'nom':monNom, 'prenom':monPrenom, 'email':monEmail, 'tel':monTel, 'adresse':monAdresse, 'cp':monCp, 'ville':monVille, 'pays':monPays, 'personne':monPersonne, 'message':monMessage }, function() {
					$("#contactForm").fadeOut("fast",function(){
					$("#reponse").fadeIn("fast");
				});
			});
		}
			
	});
	
	$("input#sendInscription").click(function() {
		test = checkRequieredFields('newsletterForm');
		if(test==true){
		
			monNom = $("#nom").attr("value");
			monEmail = $("#email").attr("value");
								
		$("#monCallback").load("ajax-newsletter.php", { 'nom':monNom, 'email':monEmail }, function() {
					$("#newsletterForm").fadeOut("fast",function(){
					$("#reponse").fadeIn("fast");
				});
			});
		}
			
	});
	
	$("input#sendAmi").click(function() {
		test = checkRequieredFields('amiForm');
		if(test==true){
			monNom = $("#nom").attr("value");
			monEmail = $("#email").attr("value");
			amiNom = $("#nom_ami").attr("value");
			amiEmail = $("#email_ami").attr("value");
								
		$("#monCallback").load("ajax-ami.php", { 'nom':monNom, 'email':monEmail, 'nom_ami':amiNom, 'email_ami':amiEmail }, function() {
					$("#amiForm").fadeOut("fast",function(){
					$("#reponse").fadeIn("fast");
				});
			});
		}
			
	});
	
	$("input#sendPresse").click(function() {
		test = checkRequieredFields('presseForm');
		if(test==true){
		
			monNom = $("#nom").attr("value");
			monPrenom = $("#prenom").attr("value");
			monEmail = $("#email").attr("value");
			monTel = $("#tel").attr("value");
			monSupport = $("#support").attr("value");
			monMessage = $("#message").attr("value");
					
		$("#monCallback").load("ajax-presse.php", { 'nom':monNom, 'prenom':monPrenom, 'email':monEmail, 'tel':monTel, 'support':monSupport, 'message':monMessage }, function() {
					$("#presseForm").fadeOut("fast",function(){
					
					$("#reponse").fadeIn("fast");
				});
			});
		}
			
	});
	
	/********* expos en cours *********************/
	$('#logos').bxSlider({
		mode: 'fade',
		speed: 1000,
		pause: 6000,
		auto: true,
		controls: true,
		auto_direction: 'left',
		width: 247,
		wrapper_class: 'slider-wrapper'
	});
	
	/****** gestion des slideshow ********************/
	$('#images').bxSlider({
		mode: 'horizontal',
		speed: 300,
		pause: 5000,
		auto: true,
		captions: true,
		controls: true,
		infiniteLoop: false,
		hideControlOnEnd: true,
		auto_direction: 'left',
		wrapper_class: 'images-wrapper'
	});
	
	/******* conférences *********************/
	$('.conf').hover(function(){
		$(this).addClass('survol');
	}, function() {
		$(this).removeClass('survol');
	});
	
	$(".conf").click(function(){
		var conference = $(this).attr("id");
		$("#conferenceRight").load("ajax-conferences.php", { 'conference':conference, 'action':"affichConference" });		
	});
	
	/****************************** editions :: ajout panier  **********************************/
	$("a.addPanier").click(function() {
				
		var nom = $(this.parentNode.parentNode.parentNode).find("h2 a").html();
		var categorie = $(this).find("img").attr("class");
		var id_article = String($(this.parentNode).attr("id"));
		var total = id_article.length;
		var pos = id_article.lastIndexOf('n');
		id_article = id_article.substr(pos+1, (total-1));
		var prix = $(this.parentNode.parentNode).find(".prix").html();
		var qty = 1;
		var action = "ajout";
		
		var image = $(this.parentNode.parentNode.parentNode.parentNode).find(".vignette img").attr("src");
		
		$("#panier").load("ajax-panier.php", { 'action':action, 'categorie':categorie, 'nom':nom, 'id_article':id_article, 'prix':prix, 'qty':qty  },function(){ 
			
			var box = "<div id='ajout'><h2>Vous venez d'ajouter a votre s&eacute;lection :</h2>";
			box += "<img src='"+image+"' width='150' />";
			box += "<strong>"+nom+"<br /><br />Prix : "+prix+"&euro;</strong>";
			box += "<div class='myhr'></div>";
			box += "<div id='ajoutNav'><a href='#' id='closeBox'>Poursuivre ma visite</a> <a href='editions-et-catalogues/ma-selection.html'>Voir ma s&eacute;lection</a></div></div>";
			jQuery.facebox(box);
			
			/**** bind sur le bouton de fermeture*****/
			$("a#closeBox").click(function() {
				jQuery(document).trigger('close.facebox');
				return false;
			});

		});
		
		return(false);
	});	
	
	/****************************** ma sélection :: envoi commande  **********************************/
	$("input#sendCommande").click(function() {
		test = checkRequieredFields('commandeForm');
		if(test==true){
		
			monNom = $("#nom").attr("value");
			monPrenom = $("#prenom").attr("value");
			monEmail = $("#email").attr("value");
			monTel = $("#tel").attr("value");
			monAdresse = $("#adresse").attr("value");
			monCp = $("#cp").attr("value");
			monVille = $("#ville").attr("value");
			monPays = $("#pays").attr("value");
			monMessage = $("#message").attr("value");
					
		$("#monCallback").load("ajax-commande.php", { 'nom':monNom, 'prenom':monPrenom, 'email':monEmail, 'tel':monTel, 'adresse':monAdresse, 'cp':monCp, 'ville':monVille, 'pays':monPays, 'message':monMessage }, function() {
					$("#commandeForm").fadeOut("fast",function(){
					$("#reponse").fadeIn("fast");
				});
			});
		}
			
	});	
	
	/****************************** lancer video **********************************/
	$("a.launchVideo").click(function() {
									  
		var identifiant = $(this).find("img").attr('id');
		var plateforme = $(this).find("img").attr('class');
		
		switch(plateforme){
			case 'youtube':
				//---- si youtube
				var box = "<object width='750' height='500'>";
				box += "<param name='movie' value='http://www.youtube.com/v/"+identifiant+"&rel=0&fs=1'></param>";
				box += "<param name='allowFullScreen' value='true'></param>";
				box += "<param name='wmode' value='transparent'></param>";
				box += "<embed src='http://www.youtube.com/v/"+identifiant+"&rel=0&fs=1' type='application/x-shockwave-flash' wmode='transparent' width='750' height='500' allowfullscreen='true'></embed>";
				box += " </object>";
			break;
			case 'dailymotion':	
				//---- si dailymotion
				var box = "<object width='750' height='500'>";
				box += "<param name='movie' value='http://www.dailymotion.com/swf/video/"+identifiant+"'></param>";
				box += "<param name='allowFullScreen' value='true'></param>";
				box += "<param name='allowScriptAccess' value='always'></param>";
				box += "<param name='wmode' value='transparent'></param>";
				box += "<embed type='application/x-shockwave-flash' src='http://www.dailymotion.com/swf/video/"+identifiant+"' width='750' height='500' wmode='transparent' allowfullscreen='true' allowscriptaccess='always'></embed>";
				box += "</object>";				
			break;
		}
		
		jQuery.facebox(box);
		
		return false;
	});
	
	
	
	$(document).bind('afterClose.facebox', function(){ 
		$("#facebox .popup .content").html('');										
	});
	
	/****************************** rubriques du slideshow **********************************/
	$("a#affichPhotos").click(function() {
		$("#videos").css('display','none');
		$("#reportages").css('display','none');
		$("#colonne-droite .bx-wrapper").fadeIn(300);							   
		return false;
	});
	$("a#affichVideos").click(function() {
		$("#colonne-droite .bx-wrapper").css('display','none');
		$("#reportages").css('display','none');
		$("#videos").fadeIn(300);
		return false;
	});
	$("a#affichReportages").click(function() {
		$("#videos").css('display','none');
		$("#colonne-droite .bx-wrapper").css('display','none');
		$("#reportages").fadeIn(300);							   
		return false;
	});
	
});
