var format = "ft";
var offre = "ot";
var duree = "dt";
var zone = "zf";//ze pour debug
var profil = "pt";
var offre_abo = $("#abo li:hidden").size(); 
// simplifier js 4 en 1
// 
$(function(){
    $("#abo li.ze").hide();
    $("#abo li.not").hide();
    $('.format').each(function() {
        $(this).data('fisChecked', $(this).is(':checked'));
    
        $(this).click(function() {
            if ( $(this).is(':checked') !== $(this).data('fisChecked') ) {
                // do changed action
                //$("li").not($("."+$(this).val())).hide();
                //$("."+$(this).val()).show();
                format = $(this).val();//$(this).attr("class") = $(this).val();
                $("#abo li").show();
                $("#abo li").not($("."+format)).hide();
                $("#abo li").not($("."+offre)).hide();
                $("#abo li").not($("."+duree)).hide();
                $("#abo li").not($("."+zone)).hide();
                $("#abo li").not($("."+profil)).hide();
                offre_abo = $("#abo li:hidden").size();
                if($("#abo li").size()-offre_abo<1){
                    $("#abo li.not").show();
                }else{
                    $("#abo li.not").hide();
                }
                //alert ("format : "+format+"\n offre : "+offre+"\n duree : "+duree+"\n zone : "+zone+"\n profil : "+profil);
            } else {
                $(this).data('fisChecked', !$(this).data('fisChecked') );
            }
        })
    });
    $('.offre').each(function() {
        $(this).data('oisChecked', $(this).is(':checked'));
    
        $(this).click(function() {
            if ( $(this).is(':checked') !== $(this).data('oisChecked') ) {
                // do changed action
                //$("li").not($("."+$(this).val())).hide();
                //$("."+$(this).val()).show();
                offre = $(this).val();//$(this).attr("class") = $(this).val();
                $("#abo li").show();
                $("#abo li").not($("."+format)).hide();
                $("#abo li").not($("."+offre)).hide();
                $("#abo li").not($("."+duree)).hide();
                $("#abo li").not($("."+zone)).hide();
                $("#abo li").not($("."+profil)).hide();
                offre_abo = $("#abo li:hidden").size();
                if($("#abo li").size()-offre_abo<1){
                    $("#abo li.not").show();
                }else{
                    $("#abo li.not").hide();
                }
                //alert(offre_abo); 
                //alert ("format : "+format+"\n offre : "+offre+"\n duree : "+duree+"\n zone : "+zone+"\n profil : "+profil);
            } else {
                $(this).data('oisChecked', !$(this).data('oisChecked') );
            }
        })
    });
    $('.duree').each(function() {
        $(this).data('disChecked', $(this).is(':checked'));
    
        $(this).click(function() {
            if ( $(this).is(':checked') !== $(this).data('disChecked') ) {
                // do changed action
                //$("li").not($("."+$(this).val())).hide();
                //$("."+$(this).val()).show();
                duree = $(this).val();//$(this).attr("class") = $(this).val();
                $("#abo li").show();
                $("#abo li").not($("."+format)).hide();
                $("#abo li").not($("."+offre)).hide();
                $("#abo li").not($("."+duree)).hide();
                $("#abo li").not($("."+zone)).hide();
                $("#abo li").not($("."+profil)).hide();
                offre_abo = $("#abo li:hidden").size();
                if($("#abo li").size()-offre_abo<1){
                    $("#abo li.not").show();
                }else{
                    $("#abo li.not").hide();
                }
                //alert(offre_abo);
                //alert ("format : "+$("li").$("."+duree).show().size()+"\n offre : "+offre+"\n duree : "+duree+"\n zone : "+zone+"\n profil : "+profil);
            } else {
                $(this).data('disChecked', !$(this).data('disChecked') );
            }
        })
    });
    $('.zone').each(function() {
        $(this).data('zisChecked', $(this).is(':checked'));
    
        $(this).click(function() {
            if ( $(this).is(':checked') !== $(this).data('zisChecked') ) {
                // do changed action
                //$("li").not($("."+$(this).val())).hide();
                //$("."+$(this).val()).show();
                zone = $(this).val();//$(this).attr("class") = $(this).val();
                $("#abo li").show();
                $("#abo li").not($("."+format)).hide();
                $("#abo li").not($("."+offre)).hide();
                $("#abo li").not($("."+duree)).hide();
                $("#abo li").not($("."+zone)).hide();
                $("#abo li").not($("."+profil)).hide();
                offre_abo = $("#abo li:hidden").size();
                if($("#abo li").size()-offre_abo<1){
                    $("#abo li.not").show();
                }else{
                    $("#abo li.not").hide();
                }
                //alert(offre_abo);
                //alert ("format : "+format+"\n offre : "+offre+"\n duree : "+duree+"\n zone : "+zone+"\n profil : "+profil);
            } else {
                $(this).data('zisChecked', !$(this).data('zisChecked') );
            }
        })
    });
    $('.profil').each(function() {
        $(this).click(function() {
            if ( $(this).is(':checked')) {
                profil="pe";
            } else {
                profil="pa";
            }
            $("#abo li").show();
            $("#abo li").not($("."+format)).hide();
            $("#abo li").not($("."+offre)).hide();
            $("#abo li").not($("."+duree)).hide();
            $("#abo li").not($("."+zone)).hide();
            $("#abo li").not($("."+profil)).hide();
            offre_abo = $("#abo li:hidden").size();
            if($("#abo li").size()-offre_abo<1){
                $("#abo li.not").show();
            }else{
                $("#abo li.not").hide();
            }
            //alert(offre_abo);
            //alert ("format : "+format+" offre : "+offre+" duree : "+duree+" zone : "+zone+" profil : "+profil);
        })
    
    });
    //if ($(".profil").not(.is(':checked'))) { $(".ft").each().show();})

    
	$('#kiosque').tabs({ fxFade: true, fxSpeed: 100 });
	
	var i=1;	
	$("#kiosque").everyTime(15000,function() {
		$('#kiosque').triggerTab(i);
		i++;
		if(i>3){i=1}
	});
	
	$('#recherche').tabs({ fxFade: true, fxSpeed: 100 });
	var browser = {
	    IE: !!(window.attachEvent && !window.opera) ? true : false,
	    Opera: !!window.opera ? true : false,
	    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1 ? true : false,
	    Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1 ? true : false,
	    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) ? true : false,
	    Safari: !!navigator.userAgent.match(/Apple.*Safari/) ? true : false
	}
	if(!browser.Safari){
		var uriCourant2 = document.location.pathname;
		if(uriCourant2=="/index/2_index.php"){$('#recherche').triggerTab(2);}
		if(uriCourant2=="/index/2_numero.php"){$('#recherche').triggerTab(3);}
	}
	//$("#onglet1 input[type=text][name=keyword]").attr('value')="La Renaissance";
	//$("#onglet2 input[type=text][name=motClef]").attr('value')="Napoléon";
	/*$("#onglet1 input").click(){
		//$('#onglet1 input[type=text][name=keyword]:checked').length
		//$("#onglet1 input[type=text][name=keyword]").attr('value')="";
		
		
		$("a#gras").click(function() {
    var style = $("input[@name=input]").val() + "coucou" ;
    $("input[@name=input]").val(style);
});

	}
	
	
	$("#keyword").val()="La Renaissance";
	$("#motclef").val()="Napoleon";*/
	$("int").wrap('<p style="font-weight:bold"></p>');
	$("intertitre").wrap('<h3></h3>');
	$("question").wrap('<p style="font-weight:bold"></p>');
	$('#more').tabs({ fxFade: true, fxSpeed: 100 });
	$('#more2').accordion({header: "h2",autoheight: false});
	$('#widget4-content').accordion({header: "h2",autoheight: false});
	$('#w4t').show();
	$('#widget11-contact').pager('p',{navId:'pager'});
	
	if($('#widget11-content').length){
		$('#widget11-content').pager('p',{navId:'pager'});
	}
	$('#widget12-content').pager('li',{navId:'pager',numP:12});
	$('#widget12-couv').pager('li',{navId:'pager',numP:20});
	$('#widget12-best-couv').pager('li',{navId:'pager',numP:4});
	$('#widget12-recherche').pager('li',{navId:'pager',numP:15});
	$('#widget12-portraits').pager('li',{navId:'pager',numP:7});
	$('#widget12-carte-blanche').pager('li',{navId:'pager',numP:12});
	//$('.widget12-agenda').pager('li',{navId:'pager',numP:30});
	$('#widget12-livre').pager('li',{navId:'pager',numP:11});
	
	$('#carousel-mensuel').jcarousel({'scroll':4});
	$('#carousel-collections').jcarousel({'scroll':4});
	$('#carousel-mensuel-presse').jcarousel({'scroll':4});
	$('#carousel-collections-presse').jcarousel({'scroll':4});
	$('#carousel-hors-serie-presse').jcarousel({'scroll':4});
	$('#carousel-divers-presse').jcarousel({'scroll':4});
	$('#carousel-couvertures').jcarousel({'scroll':1});
	
	
	$('#Atlas-1-description').hide();
	$('#Atlas-1-affiche-description').click(function() {$('#Atlas-1-description').toggle("slow");return false;});
	
	
	if($('.warning-pack').length>0){
		$('.warning-pack').hide();
		$('a#warning-pack-toggle').click(function() {
		    $('.warning-pack').toggle(400);return false;
		});
	}
	if($('.warning-pack2').length>0){
		$('.warning-pack2').hide();
		$('a#warning-pack-toggle2').click(function() {
		    $('.warning-pack2').toggle(400);return false;
		});
	}
	$("a.top").anchorAnimate();
	$("#partage-article").formValidation({alias:"name",required:"accept",err_list:true});  
	
	//gestion de la hauteur des iframes
	var iFrames = document.getElementsByTagName('iframe');
	// Resize heights.
	function iResize()
	{
		// Iterate through all iframes in the page.
		for (var i = 0, j = iFrames.length; i < j; i++)
		{
			// Set inline style to equal the body height of the iframed content.
			iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
		}
	}

	// Check if browser is Safari or Opera.
	if ($.browser.safari || $.browser.opera)
	{
		// Start timer when loaded.
		$('iframe').load(function()
			{
				setTimeout(iResize, 0);
			}
		);

		// Safari and Opera need a kick-start.
		for (var i = 0, j = iFrames.length; i < j; i++)
		{
			var iSource = iFrames[i].src;
			iFrames[i].src = '';
			iFrames[i].src = iSource;
		}
	}
	else
	{
		// For other good browsers.
		$('iframe').load(function()
			{
				// Set inline style to equal the body height of the iframed content.
				this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
			}
		);
	}
	
	var theFrame = $("iframe", parent.document.body);
	//theFrame.height($(document.body).height() + 10);

})

function LoginAgreg(login,MdP) { // Vérifie le formulaire
	 if(login.value=="") { alert('Login requis !')
		login.focus();return false }
	 if(MdP.value=="") { alert('MdP requis !')
		MdP.focus();return false }
	 
	 var login2 = login.value.substring(0,1)+login.value.substring(4,5);
	 var MdP2 = MdP.value.substring(4,5)+MdP.value.substring(1,2);
	 if(login2!=MdP2) { alert('Vous n\'avez pas rentré le bon mot de passe');return false }


	  date=new Date;
	  date.setMonth(date.getMonth()+1); // expire dans un mois
	  ecrire_cookie("LoginValid", "oui", date);
	 tb_remove();return false 
}

function montre(id) {
	var e = document.getElementById(id);
	if (e.style.display=='block') {e.style.display='none';} else {e.style.display='block';}
}