﻿/*----------------------------------------------------------------------------//
// Javascript pour le site client  -------------------------------------------//
//----------------------------------------------------------------------------//
// Client : EBSU
// Date   : 20 mars 2009
//----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
// Inclusion dynamique des fichiers externes javascripts
/*----------------------------------------------------------------------------*/
function importJavascript(src) {
    document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
}
function importCss(href, media) {
    document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
}

/*----------------------------------------------------------------------------*/
// Importations de fichiers
/*----------------------------------------------------------------------------*/
importJavascript("/includes/abso.thickbox.js");
importCss("/includes/abso.thickbox.css", "screen");

$(document).ready(function() {
	
	$("td").children("a").find("img").each(function() {
        var src = $(this).attr("src");
        if(src.indexOf("/pages/images/") != -1 && ($(this).css("width") == "77px" || $(this).css("width") == "110px" || $(this).css("width") == "250px")) {
            $(this).parent("a").addClass("Popup");
            $(this).parent("a").attr("rel", "Galery");
        }
    });

	
	// ---------------------------------------------------------------------------
	// SCRIPT DE NETTOYAGE DES TABLEAUX ------------------------------------------
	// ---------------------------------------------------------------------------
	$("table.TableauGenere").each(function(){
		
		// Nettoyage des classes
		$(this).find(".CelluleTexte1").removeAttr("class");
		$(this).find(".CelluleTexte2").removeAttr("class");
		$(this).find(".CelluleTitreG").removeAttr("class");
		$(this).find(".CelluleTitre").removeAttr("class");
		$(this).find(".CelluleTitreD").removeAttr("class");
		$(this).find(".LienPDF").removeAttr("class");
		
		// Alternance dans la couleur de fond des rangées
		$("tr:even td", this).addClass('CelluleTexte2');
		$("tr:odd td", this).addClass('CelluleTexte1');
		
		// Application des styles pour les titres
		$("tr:first", this).each(function(){
			$("td", this).removeClass("CelluleTexte2");
			$("td", this).addClass("CelluleTitre");
			$("td:first", this).removeClass("CelluleTitre");
			$("td:first", this).addClass("CelluleTitreG");
			$("td:last", this).removeClass("CelluleTitre");
			$("td:last", this).addClass("CelluleTitreD");
		});
		
		// Application du style pour les liens PDF
		$("tr", this).each(function(){
			$("td:last a", this).addClass("LienPDF");							
		});
	});
});

/* - Fonction : Menu Deroulant
-----------------------------------------------------------*/
var lastMenuOn, timerMenu = null;
var lastMenuClose = true;

function initMenuDeroulant() {
	// Mouse Over Action
	$("ul#MenuDeroulant").children("li").each(function(){
    	$(this).children("a").hover(function(){
			if(timerMenu != null){ clearTimeout(timerMenu); }
			if(lastMenuClose || lastMenuOn != $(this).parent().attr("class")) {
				if(lastMenuOn != null) {
					$("."+lastMenuOn).children("ul").stop(true,true).slideUp('fast');
					$("."+lastMenuOn).children("a").removeClass("Over");
					lastMenuClose=true;
				}
				$(this).addClass("Over");
				$(this).next("ul").slideDown("fast", function(){ lastMenuClose=false; });
				lastMenuOn = $(this).parent().attr("class");
			}
			else if($(this).next("ul").length > 0) {
				$(this).addClass("Over");
				lastMenuOn = $(this).parent().attr("class");
			}
			
		},function(){//Out
			if($(this).next("ul").length > 0) {
				timerMenu = setTimeout(function(){
					$("."+lastMenuOn).children("ul").stop(true,true).slideUp('fast',function(){ $("."+lastMenuOn).children("a").removeClass("Over"); lastMenuClose=true; });
				},800);
			}
			else
				$("."+lastMenuOn).children("a").removeClass("Over"); 
		});
	});
	// Mouse Enter/Leave Action
	$("ul#MenuDeroulant ul").bind("mouseenter",function(){
		if(timerMenu != null){ clearTimeout(timerMenu); }
	}).bind("mouseleave",function(){
		currentMenuOnObj = $(this);
		timerMenu = setTimeout(function(){
			currentMenuOnObj.stop(true,true).slideUp('fast',function(){ $("."+lastMenuOn).children("a").removeClass("Over"); lastMenuClose=true; });
		},500);
	});
	
	
	$("#EnteteAccueil").mouseover(function(){
		stopSlideShow();
	});
	$("#EnteteAccueil").mouseout(function(){
		startSlideShow();
	});
}


/* - Fonction : SlideShow Accueil
-----------------------------------------------------------*/
var timerSS = 4000; var t;
var arrMenu = new Array();
var arrMenuImg = new Array();
var currItem = 0;
var arrMenuLink = new Array();

function initSlideShow() {
    $("map#Entete").children("area").each(function(i) {
        arrMenu.push($(this).attr("id"));
        arrMenu[$(this).attr("id")] = i;
        arrMenuImg.push($(this).attr("title"));
		arrMenuLink.push($(this).attr("href"));
        $(this).attr("title", $(this).attr("alt"));
        $(this).mouseover(function() {
            stopSlideShow();
            $("#EnteteAccueil").attr("src", arrMenuImg[arrMenu[$(this).attr("id")]]);
			$(".LienSlideShow").attr("href", arrMenuLink[arrMenu[$(this).attr("id")]]);
        });
		$(this).mouseout(function() {
            currItem = arrMenu[$(this).attr("id")];
            startSlideShow();
        });
    });
    startSlideShow();
}
function SlideShow() {
    currItem = currItem + 1;
    if (currItem >= arrMenu.length) { currItem = 0; }
    $("#EnteteAccueil").attr("src", arrMenuImg[currItem]);
	$(".LienSlideShow").attr("href", arrMenuLink[currItem]);
    startSlideShow();
}
function startSlideShow() {
    t = setTimeout(SlideShow, timerSS);
}
function stopSlideShow() {
    clearTimeout(t);
}