$(document).ready(function()
{

function coloriseTableau ()
{
	$("table.calendar tr").removeClass("normal gris");
	$("table.calendar tr.title:visible:even").addClass("gris");
	$("table.calendar tr.complement:visible:even").addClass("gris");
	$("table.calendar tr.title:visible:odd").addClass("normal");
	$("table.calendar tr.complement:visible:odd").addClass("normal");
}

var MaxTexte = 0; // met à zéro Ø la valeur max de la heuteur des blocs en accueil -> utilisée dans la ƒ calculeHauteurBlocAccueil()
var MaxVideo = 0; // met à zéro Ø la valeur max de la heuteur des blocs en accueil -> utilisée dans la ƒ calculeHauteurBlocAccueil()

//dimScreen()
//by Brandon Goldman
jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;
        
        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
        opacity = (opacity > 0) ? opacity : 0.5;
        return jQuery('<div></div>').attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000'
            ,height: '100%'
            ,left: '0px'
            ,opacity: 0
            ,position: 'fixed'
            ,top: '0px'
            ,width: '100%'
            ,zIndex: 99999
        }).appendTo(document.body).fadeTo(speed, opacity, callback);
    },
    
    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = jQuery('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(speed, function() {
            x.remove();
            if(typeof callback == 'function') callback();
        });
    }
});


	//ouvrir ds une nouvelle fenêtre tous les liens ayant l'attribut type=application
	$('a.spip_out,a.spip_url,a.spip_documents,a.ext').attr("target", "_blank");
	$('a').click(function(){
		$(this).blur();
	});

	$("ul.racine li.rubrique_quatre span").click(function()
	{
		$("ul.racine li.rubrique_quatre span").removeClass("activer");
		$("ul.racine li.rubrique_quatre ul").hide(200);
		$(this).parent().children().show(300);
		$(this).addClass("activer");
		return false;
	});
	
	$('a.lanceurVideo').click(function()
	{
		$(".affiche_video").fadeOut(500);
		var Instance = $(this).attr('id');
		$('#cible_' + Instance).fadeIn(300);
	});
	
	$('a.fermer').click(function()
	{
		$(".affiche_video").fadeOut(500);
	});
	
	$("a[href^='http://maps.google.fr/maps']").addClass("maplan");

/*
	$("p.inscription").click(function()
	{
		$.dimScreen(200, 0.7, function()
		{
	    	$('div#alert').css("position","fixed").fadeIn().html("<h3>Bienvenue au service d'inscription</h3> <p>Celui-ci sera accessible fin août. Très bonne continuation sur le site du Théâtre du Capitole.</p>");
	    });
	});
	
	$("div#alert").click(function()
	{
		$(this).hide(100);
		$.dimScreenStop();
	});
*/

	var texteType = $("#filtres-composites option#touttype").html();
	var texteLieu = $("#filtres-composites option#toutlieu").html();
	
	$("p.informer-choix").click(function() {
		$(this).hide(50);
		$("table.calendar tr").show();
		$("p.informer-choix").html("");
		$('#filtres-composites option').each( function() { $(this).attr("selected", false)});
		coloriseTableau();
	});

	$("#filtres-composites select").change(function()
	{
		var quoiChanger = $(this).children(":selected").attr("id");
		var texteFiltre = $("option#" + quoiChanger).text();

		if ( !(quoiChanger == "touttype" || quoiChanger == "toutlieu") )
		{
			$("table.calendar tr").hide();
			$("table.calendar tr." + quoiChanger).show();
			coloriseTableau();
		}
		else
		{
			$("table.calendar tr").show();
			$("table.calendar tr." + quoiChanger).hide();
			coloriseTableau();
		}
	});


	$("#filtre-liste-lieu select").change(function(){
		$('#filtre-liste-type option').each( function() { $(this).attr("selected", false)});
	});

	$("#filtre-liste-type select").change(function(){
		$('#filtre-liste-lieu option').each( function() { $(this).attr("selected", false)});
	});


	/* Calcule la hauteur des blocs DL */
	function calculeHauteurBlocAccueil ()
	{
		var classeIntroTexte = new Array();
		var classeIntroVideo = new Array();
		$(".annonce div.intro-texte").each(function(e) { classeIntroTexte[e] = $(this).height(); });
		$(".video div.intro-texte").each(function(e) { classeIntroVideo[e] = $(this).height(); });
	
		var paddingBot = 20; /* Padding du Bottom de chaque DD dans les fiches de listes */
		for (var i=0; i<classeIntroTexte.length; i++) if (classeIntroTexte[i]*1>MaxTexte) MaxTexte = classeIntroTexte[i];
		$(".annonce div.intro-texte").height(MaxTexte + paddingBot);	
		for (var i=0; i<classeIntroVideo.length; i++) if (classeIntroVideo[i]*1>MaxVideo) MaxVideo = classeIntroVideo[i];
		$(".video div.intro-texte").height(MaxVideo + paddingBot);	
	}

	calculeHauteurBlocAccueil();

	$("a[href$=pdf]").attr(target,"_blank");


}); // fin document.ready

