// Fonctions Javascript concernant le site entier


// Fonction permettant de demander le téléchargement d'une ressource
	function GetRessource (RessourceId) {
		window.open("download.php?ressid=" + RessourceId);
		return(true);
	}

// Fonction de chargement d'un objet Flash
	function SWFLoad ( ContainerId, SourceFile, Width, Height ) {
		if ( document.getElementById(ContainerId) ) {
			if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
				var x = "<embed type=\"application/x-shockwave-flash\" src=\"" + SourceFile + "\" width=\"" + Width + "\" height=\"" + Height + "\" />";
			} else {
				var x = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" height=\"" + Height + "\" width=\"" + Width + "\">";
					x += "<param name=\"movie\" value=\"" + SourceFile + "\">";
					x += "<param name=\"quality\" value=\"best\">";
					x += "<param name=\"play\" value=\"true\">";
					x += "</object>";
			}
			document.getElementById(ContainerId).innerHTML = x;
		}
	}

	
	
// Fonction permettant de charger les images nécessaire au menu gauche	
	function preloadLFMImages (IsPublic) {
		alert(document.images.length);
			var StartImgs = "";
			var ImgFileName = new Array();
			if (IsPublic) {
				StartImgs = "imgs/fr/public/left_menu/fr_lmnu_pub_";
				ImgFileName = new Array("accueil", "present", "news", "services", "links", "contacts", "glossary", "downloads");
			} else {
				StartImgs = "imgs/fr/private/left_menu/fr_lmnu_priv_";
				ImgFileName = new Array("accueil", "present", "news", "services", "links", "contacts", "glossary", "downloads");
			}
			var StartImgs = "imgs/fr/public/left_menu/fr_lmnu_pub_";
			var EndImgOn = "_off.jpg";
			var EndImgOff = "_on.jpg";
			var ImgSrcs = new Array();
			for (var iImg = 0 ; iImg < ImgSrcs.length; iImg++) {
				NewImageOff = new Image();
				NewImageOn = new Image();
				NewImageOff.src = StartImgs + ImgSrcs[iImg] + EndImgOff;
				NewImageOn.src = StartImgs + ImgSrcs[iImg] + EndImgOn;
				document.images.push(NewImageOff);
				document.images.push(NewImageOn);
			}
			alert(document.images.length);
	}
	
// Fonction de changement d'image
	function changeStateImage(ImageName, ImageState) {
		
		//document.images[ImageName].src = LFMImgs[ImageName][ImageState].src;
		xxx = new Image();
		xxx.src = LFMImgs[ImageState][ImageName];
		document.images[ImageName].src = xxx.src;	}
	
	
// Fonction permettant de rendre visible un élément à partir de son id
	function ShowById (ObjectId) {
		document.getElementById(ObjectId).style.visibility='visible';
	}
// Fonction permettant de rendre visible un élément à partir de son id
	function HideById (ObjectId) {
		document.getElementById(ObjectId).style.visibility='hidden';
	}
// Fonction permettant d'afficher un calque du glossaire
	function ShowGlossaryDiv (DivId, LkId) {
		var Obj = document.getElementById(LkId);
		Left = findPosX(Obj) + 50;
		Top = findPosY(Obj) + 20;
		//alert(Top + "x" + Left);
		document.getElementById(DivId).style.top = Top;
		document.getElementById(DivId).style.left = Left;
		document.getElementById(DivId).style.visibility='visible';
	}
	
// sélectionne un calque
	function SelPublicLayer(ObjectId) {
		if (ObjectId == 'divsubpresent') {
			ShowById('divsubpresent');
			HideById('divsubnews');
			HideById('divservices');
		} else if (ObjectId == 'divsubnews') {
			ShowById('divsubnews');
			HideById('divservices');
			HideById('divsubpresent');
		} else if (ObjectId == 'divservices') {
			ShowById('divservices');
			HideById('divsubnews');
			HideById('divsubpresent');
		} else {
			HideById('divservices');
			HideById('divsubnews');
			HideById('divsubpresent');			
		}
	}	
	
// Retrouve la position d'un objet
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}

function Blink() {
	$('span.Blink').each(function (i) {
		$(this).fadeIn(300).fadeOut(500);
	});
	setTimeout( 'Blink()', 1000 );
}

// Jquery...
$(document).ready(function(){
	Blink();
});



