/* ---------------------------------------------------------------
	CONTENU PLUS
 --------------------------------------------------------------- */
function listeRoman() {
	var myAjax = $.ajax({
		url: 'ajax/episods/liste_roman.php', type: 'POST',
		data: 'recherche=' + $('#recherche_titre').val() + '&recherche2=' + $('#recherche_select').val(),
		success: function(retour){$('#liste_roman').html(retour);},
		complete: function(){
			// Gestion du Flow
			$("#myController").jFlow({
				slides: "#mySlides",
				controller: ".jFlowControl", 
				slideWrapper : "#jFlowSlide", 
				selectedWrapper: "jFlowSelected",  
				width: "100%",
				height: "100%",
				duration: 400, // Temps en milisecondes 
				prev: ".jFlowPrev",
				next: ".jFlowNext"
			});
			
			//
			$('div[@class=vignette]').each( function(noeud){
				gestionAncre($(this));
				$(this).click( function(){
					var myAjax = $.ajax({
						url: 'ajax/session_id.php',
						data: 'clef=roman_id' + '&valeur=' + $(this).attr('id'),
						type: 'POST',
						complete: function(){
							affichageSecondaire();
						}
					});
				}); 
			});

		}
	});
}
/* ---------------------------------------------------------------
	ZONE SECONDAIRE
 --------------------------------------------------------------- */
function affichageSecondaire(){
	// MASQUE DE LA ZONE PRINCIPALE
	$("div.contenu_centre").css("visibility","hidden");
	// AFFICHAGE DE LA ZONE SECONDAIRE
	$("#zone_secondaire").show();
	
	var myAjax = $.ajax({
		url: 'ajax/episods/zone_secondaire.php', type: 'POST',
		success: function(retour){$('#zone_secondaire').html(retour);},
		complete: function(){
			// BOUTON FERMER
			gestionAncre("#fermer");
			$("#fermer").click(function(){
				$("#zone_secondaire").hide();					
				$("div.contenu_centre").css("visibility","visible");
			});

			// AFFICHAGE PAR DEFAUT
			demoTel("ajax/episods/resume.php");

			// SURVEILLANCE DU MENU
			$('#menu_roman a').each( function(noeud){
				gestionAncre($(this));
				$(this).click( function(){
					var idMenu = $(this).attr('id');
					switch(idMenu){
						case "resume": demoTel("ajax/episods/resume.php"); break;
						case "premier": demoTel("ajax/episods/premier_episode.php"); break;
						case "abonnement": affichageAbonnement(); break;
					}
				}); 
			});
		}
	});

}

/* ---------------------------------------------------------------
	ABONNEMENT
 --------------------------------------------------------------- */
function affichageAbonnement(){	
	var myAjax = $.ajax({
		url: 'ajax/episods/abonnement.php', type: 'POST',
		success: function(retour){$('#demo_tel').html(retour);},
		complete: function(){
			$("#exemple").attr("style","top:88px;");
			$("#exemple").fadeIn(1500);

			$("#form_email").validate({
				debug: true,
				rules: {
					email: { required: true, email: true }
					},				
				messages: {
					email: { required: "Votre adresse mail est obligatoire", email: "Cette adresse n'est pas valide."}
					},				
				submitHandler: function(form) {
					var options = { 
						url: "ajax/episods/upd_abonnement.php", type: 'post',	dataType: 'json',
						beforeSubmit: function(){ affichageMessage('before' , 'traitement en cours'); },
						success: function(json){
							$("#email").attr('value', '');
							$("#message_confirmation").show();
							$("#message_confirmation").html(json.message); 
						},
						complete: function(){ // A MODIFIER
							//alert('toto');
							//$("#detail").html(json.message);
						}
					}; 
					$("#form_email").ajaxSubmit(options); 
					return false; 
			   }
			});

		}
	});
}
/* ---------------------------------------------------------------
	FONCTIONS A LANCER LORS DU CHARGEMENT DE LA PAGE
 --------------------------------------------------------------- */
$(document).ready(function(){
	// MENU PRINCIPAL - AFFICHAGE DES BOUTONS
	boutonMenu('episods');
	
	// AFFICHAGE DE LA LISTE DES ROMANS
	listeRoman();
	
	// SURVEILLANCE DU FORMULAIRE DE RECHERCHE
	$('#recherche_titre').keyup(listeRoman);
	$('#recherche_select').change(listeRoman);
	
	// Verification si ouverture automatique d'un feuilleton
	var verifOuverture = $('#conteneur').attr('ouverture');
	if(verifOuverture == 1) affichageSecondaire();
	
});
// -------------------------------------------------------------