$(function(){

	$('#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});
	$('#widget11-contact').pager('p',{navId:'pager'});
	
	if($('#widget11-content').length){
		$('#widget11-content').pager('p',{navId:'pager'});
	}
	$('#widget12-content').pager('li',{navId:'pager',numP:10});
	$('#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:10});
	//$('.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});
	
	if($('.warning-pack').length>0){
		$('.warning-pack').hide();
		$('a#warning-pack-toggle').click(function() {
		    $('.warning-pack').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';}
}