/* ______________________[ 01 | Interactivité du menu principal (menu horizontal) ]________________________ */

/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmdog.com/articles/suckerfish/ */

function SmartHover(who) {
	if (document.all&&document.getElementById&&document.getElementsByTagName&&document.getElementById(who)) {
		navRoot=document.getElementById(who);
		for (i=0;i<navRoot.childNodes.length;i++) {
			node=navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {this.className+=" over";}
				node.onmouseout=function() {this.className=this.className.replace(" over", "");}
			}
		}
	}
	SmartFocus(who);
}

function SmartFocus(who) {
	var navLnk=document.getElementById(who).getElementsByTagName("A");
	var navItm=document.getElementById(who).getElementsByTagName("LI");
	for (var n=0;n<navItm.length;n++) {
		if (navItm[n].className!="on") navItm[n].className="y";
	}
	for (var i=0;i<navLnk.length;i++) {
		navLnk[i].onfocus=function() {
			if (this.parentNode.parentNode.id==who) {
				this.parentNode.className+=" over";
			} else {
				this.parentNode.parentNode.parentNode.className+=" over";
			}
		}
		navLnk[i].onblur=function() {
			if (this.parentNode.parentNode.id==who) {
				this.parentNode.className=this.parentNode.className.replace(" over", "");
			} else {
				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(" over", "");
			}
		}
	}
}



/* ______________________[ 02 | Gestion de la taille du texte d’un article ]________________________ */

/* Ce script modifie la taille du texte contenu dans <div id="bloc_txt"/>. Si JavaScript n’est pas activé ou si les méthodes 
ne sont pas supportées, il ne se passera rien mais cela ne provoquera pas d’erreur. */

function SmartSize() {
	if (document.getElementById&&document.getElementById("TaillePlus")&&document.getElementById("TailleMoins")&&document.getElementById("main")) {
		var cibleplus=document.getElementById("TaillePlus");
		var ciblemoins=document.getElementById("TailleMoins");
		var cibletxt=document.getElementById("main");
		cibleplus.onclick=function() {
			var sizestr=cibletxt.style.fontSize.substring(0,cibletxt.style.fontSize.length-2);
			var sizeinter=cibletxt.style.lineHeight.substring(0,cibletxt.style.lineHeight.length-2);
			sizestr=sizestr!=""?parseInt(sizestr):11;
			sizeinter=sizeinter!=""?parseInt(sizeinter):15;
			if (sizestr < 40) {
			cibletxt.style.fontSize=sizestr+1+"px";
			cibletxt.style.lineHeight=sizeinter+1+"px";
			}
		}
		ciblemoins.onclick=function() {
			var sizestr=cibletxt.style.fontSize.substring(0,cibletxt.style.fontSize.length-2);
			var sizeinter=cibletxt.style.lineHeight.substring(0,cibletxt.style.lineHeight.length-2);
			sizestr=sizestr!=""?parseInt(sizestr):11;
			sizeinter=sizeinter!=""?parseInt(sizeinter):15;
			if (sizestr != 0) {
			cibletxt.style.fontSize=sizestr-1+"px";
			cibletxt.style.lineHeight=sizeinter-1+"px";
			}
		}
	}
}


/* ______________________[ 07 | Onglets Fiches ]________________________ */

function AttribAction() {
	var args=AttribAction.arguments;
	for (n=0;n<args.length;n+=2) {
		var tgName=args[n];
		var fcName=args[n+1];
		if (document.getElementById&&document.getElementById(tgName)&&document.getElementById(fcName)) {
			tg=document.getElementById(tgName);
			fc=document.getElementById(fcName);
			if (fcName!="fiche1") {
				fc.style.position="absolute";
				fc.style.top="-1500px";
				fc.style.left="-1500px";
			}
			if (tg.nodeName=="A") {
				tg.onclick=function() {
					ResetAll(args);
					HideMeThatCard(args);
					tt="fiche"+this.id.substr(this.id.length-1, 1);
					ttt=document.getElementById(tt);
					ttt.style.position="relative";
					ttt.style.top="auto";
					ttt.style.left="auto";
					this.parentNode.className="on";
					window.scroll(0,0);
					return false;
				}
			}
		}
	}
}

function ResetAll(vt) {
	for (n=0;n<vt.length;n+=2) {
		if (document.getElementById&&document.getElementById(vt[n])) {
			var tgR=document.getElementById(vt[n]);
			tgR.parentNode.className="off";
		}
	}
}

function HideMeThatCard(tn) {
	for (n=0;n<tn.length;n+=2) {
		var fcName=tn[n+1];
		if (document.getElementById&&document.getElementById(fcName)) {
			ctb=document.getElementById(fcName);
			ctb.style.position="absolute";
			ctb.style.top="-1500px";
			ctb.style.left="-1500px";
		}
	}
}

function fromUrl() {
	var location=window.location.href;
	var thisPage=location.substring(location.lastIndexOf("#")+1);
	if (thisPage=="thema") {
		var tb=fromUrl.arguments;
		ResetAll(tb);
		HideMeThatCard(tb);
		tt="fiche2";
		ttt=document.getElementById(tt);
		ttt.style.position="relative";
		ttt.style.top="auto";
		ttt.style.left="auto";
		trig2=document.getElementById("trigger2");
		trig2.parentNode.className="on";
		window.scroll(0,0);
		return false;
	}
}



/* ______________________[ 03 | Lancement d’une impression pour les navigateurs compatibles ]________________________ */

/* Les utilisateur de MacOS ne peuvent bénéficier de cette fonctionnalité : il peut être intéressant de prévoir une explication 
à ces utilisateurs sur la page d’aide par exemple. */

function DirectPrint() {
	if (window.print) self.print();
}


/* ______________________[ 04 | Plan du site ]________________________ */

/*function RnkFolder(element) {
	var el=document.getElementById(element);
	var es=el.parentNode.style;
	var et=el.parentNode.parentNode.firstChild.style;
	el.parentNode.parentNode.firstChild.blur();
	es.display=es.display=="none"||es.display==""||!es.display?"block":"none";
	et.backgroundImage=et.backgroundImage=="url(../../img/fd_on.gif)"?"url(../../img/fd_off.gif)":"url(../../img/fd_on.gif)";
}*/

addEvent(window, "load", makeTreesC);

function makeTreesC() {
     // We don't actually need createElement, but we do
    // need good DOM support, so this is a good check.
    if (!document.createElement) return;
    
    uls = document.getElementsByTagName("ul");
    for (uli=0;uli<uls.length;uli++) {
        ul = uls[uli];
        if (ul.nodeName == "UL" && ul.className == "treeview") {
            processULELC(ul);
        }
		  
	 } 
}




function processULELC(ul) {
    if (!ul.childNodes || ul.childNodes.length == 0) return;
    // Iterate LIs
    for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
        var item = ul.childNodes[itemi];
        if (item.nodeName == "LI") {
            // Iterate things in this LI
            var a;
            var subul;
	    subul = "";
            for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
                var sitem = item.childNodes[sitemi];
                switch (sitem.nodeName) {
                    case "A": a = sitem; break;
                    case "UL": subul = sitem; 
                               processULELC(subul);
                               break;
                }
            }
            if (subul) {
                associateELC(a,subul);
            } else {
                a.parentNode.className = "aq3bullet";
            }
        }
    } 
}

function associateELC(a,ul) {
	
     if (a.parentNode.className.indexOf('aq3open') == -1)
      a.parentNode.className = 'aq3closed';
    a.onclick = function () {
        this.parentNode.className = (this.parentNode.className=='aq3open') ? "aq3closed" : "aq3open";
        return false;
	 }
}


	
/*              Utility functions                    */

function addEvent(obj, evType, fn){
  /* adds an eventListener for browsers which support it
     Written by Scott Andrew: nice one, Scott */
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}


/* tout afficher / tout masquer */

function affichage(element) 
	{
		var uls = document.getElementsByTagName('ul');
		var lis = document.getElementsByTagName('li');
		var hs = document.getElementsByTagName('h2')
		
		if (element=='all')
		{
			for(var i = 0; i < uls.length; ++i) 
			{
				if (uls[i].className=='treeview') {
					uls[i].style.display=uls[i].style.display=="none"?"block":"block";
					
				}
			
			}
			
			for(var i = 0; i < hs.length; ++i) 
			{
				if ((hs[i].nextSibling&&hs[i].nextSibling.className=="treeview") || (hs[i].nextSibling.nextSibling&&hs[i].nextSibling.nextSibling.className=="treeview"))
				hs[i].className="on"
			}
		
			for(var i = 0; i < lis.length; ++i) 
			{
				if (uls.className=='treeview' || lis[i].parentNode.className=='treeview')
				{
				lis[i].className = (lis[i].className=='aq3bullet') ? "aq3bullet" : "aq3open";
				}
			}
		}
		
		else
		{
			for(var i = 0; i < uls.length; ++i) 
			{
				if (uls[i].className=='treeview')
				{
					uls[i].style.display=uls[i].style.display=="block"?"none":"none";
					
				}
			}
			
			for(var i = 0; i < hs.length; ++i) 
			{
				if ((hs[i].nextSibling&&hs[i].nextSibling.className=="treeview") || (hs[i].nextSibling.nextSibling&&hs[i].nextSibling.nextSibling.className=="treeview"))
				hs[i].className="off"
			}
		
			for(var i = 0; i < lis.length; ++i) 
			{
				if (uls.className=='treeview' || lis[i].parentNode.className=='treeview')
				{
				lis[i].className = (lis[i].className=='aq3bullet') ? "aq3bullet" : "aq3open";
				}
			}
		}
	} 

/* ______________________[ 06 | Gestion de l’ouverture/fermeture des « <h2/> » ]________________________ */

function SmartPlan() {
	var args=SmartPlan.arguments;
	if (document.getElementById&&document.getElementById(args[0])) {
		var root=document.getElementById(args[0]).getElementsByTagName("H2");
		for (a=0;a<root.length;a++) {
		if (root[a].nodeName=="H2") {
				SmartOpenClose(root[a]);
			}
		}
	}	
}		


function SmartOpenClose(who) {

		if (who.nextSibling.nextSibling&&who.nextSibling.nextSibling.className=="treeview") 
		{
			var Sister=who.nextSibling.nextSibling;
			Sister.style.display="block";
			who.className="on";
		}
	
		else if (who.nextSibling&&who.nextSibling.className=="treeview") {
			var Sister=who.nextSibling;
			Sister.style.display="block";
			who.className="on";
		}
		
		
		who.onclick=function() {
				if (Sister)
				{
				Sister.style.display=Sister.style.display=="none"?"block":"none";
				who.className=who.className=="off"?"on":"off";
				}
			}	


}		

/* ______________________[ 05 | Lancement des scripts ]________________________ */

window.onload=function() {
	var agt=navigator.userAgent.toLowerCase();
	SmartHover("NavigationPrincipale");
	SmartSize();
	SmartPlan("plansite");
	if(agt.indexOf("msie 5.0")==-1) {AttribAction("trigger1","fiche1","trigger2","fiche2","trigger3","fiche3", "trigger4","fiche4");}
	if(agt.indexOf("msie 5.0")==-1) {fromUrl("trigger1","fiche1","trigger2","fiche2","trigger3","fiche3", "trigger4","fiche4");}
}

/**
	Frédéric Saunier
	http://www.tekool.net/javascript/backtothehtml

	This program is part of a free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

**/

/*****************************************************************************
* BackToTheHtml Command
*///**************************************************************************
function BackToTheHtml(node)
{
	if(node == null)
		this.node = document; 
	else
		this.node = node; 
};
BackToTheHtml.prototype.node = null;

BackToTheHtml.prototype.execute = function()
{
	this.activateObject();
}

BackToTheHtml.prototype.activateObject = function(domObject)
{
	var aDomObject = this.node.getElementsByTagName('object');
	var activationObject;
	for(var i=0; i<aDomObject.length; i++)
		if
		(
			aDomObject[i].getAttributeNode('BackToTheHtml') == null
			&&
			(activationObject = this.getActivationObject(aDomObject[i])) != null
		)
			activationObject.execute();
};

BackToTheHtml.prototype.getActivationObject = function(domObject)
{
	var classid = domObject.classid.toUpperCase().substr('clsid:'.length);
	var mimeType = domObject.type.toLowerCase();

	switch(true)
	{
		case 
			classid == 'D27CDB6E-AE6D-11CF-96B8-444553540000' 
			||
			mimeType == 'application/x-shockwave-flash'
		:
			return new ActivateObjectFlash(domObject);

		default :
			return null;
	}
};

BackToTheHtml.uniqueID = function(prefix)
{
	var sPrefix;
	if(prefix == null)
		sPrefix = 'uniqueId';
	else
		sPrefix = prefix;
		
	var i=0;
	while(document.getElementById(sPrefix + (i++)))
		;
	return sPrefix + (i-1);
};

BackToTheHtml.isParentOf = function(parent,child)
{
	var found = false;
	for(var i=0; i<parent.childNodes.length; i++)
		if(parent.childNodes[i] == child)
			return true;
		else
			found = arguments.callee(parent.childNodes[i],child);

	return found;
}

/*****************************************************************************
* ActivateObject Command
*///**************************************************************************
function ActivateObject(domObject)
{
	this.domObject = domObject;
}

ActivateObject.prototype.domObject = null;
ActivateObject.prototype.classid = null;
ActivateObject.prototype.aHtmlAttribute = ['accessKey','align','alt','archive','border','code','codeBase','codeType','declare','dir','height','hideFocus','hspace','lang','language','name','standby','tabIndex','title','useMap','vspace','width'];
ActivateObject.prototype.aObjectProperty = null;

ActivateObject.prototype.execute = function()
{
	this.xndObjectId = BackToTheHtml.uniqueID();
	this.setTextHtml();
	this.writeObject();

	this.xndObject = document.getElementById(this.xndObjectId);
	this.setSpecialProperties();
	this.removeOriginalObject();
}

ActivateObject.prototype.setTextHtml = function()
{
	var str = '';
	str += '<object BackToTheHtml ' + '\n';
	str += ' classid="clsid:' + this.classid + '" ' + '\n';

	//Add HTML attributes to the <object> tag
	for(var i=0; i<this.aHtmlAttribute.length; i++)
	{
		var name = this.aHtmlAttribute[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '')
			str += '\t' + name + '="' + this.domObject[name].toString() + '" ' + '\n';
	}

	str += 'id="' + this.xndObjectId + '" ' + '\n';
	str += '>';

	for(var i=0; i<this.aObjectProperty.length; i++)
	{
		var name = this.aObjectProperty[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '' )
			str += '\t<param name="' + name + '" value="' + this.domObject[name].toString() + '"></param>' + '\n';
	}
	str += '</object>';

	this.textHtml = str;
};

ActivateObject.prototype.writeObject = function()
{
	this.domObject.insertAdjacentHTML("afterEnd",this.textHtml);
};

ActivateObject.prototype.setSpecialProperties = function()
{
	if(typeof this.domObject.className != 'undefined' && this.domObject.className.toString() != '')
		this.xndObject.className = this.domObject.className

	if(typeof this.domObject.style.cssText != 'undefined' && this.domObject.style.cssText.toString() != '')
		this.xndObject.style.cssText = this.domObject.style.cssText;

	if(typeof this.domObject.SWRemote != 'undefined' && this.domObject.SWRemote.toString() != '')
		this.xndObject.FlashVars = this.domObject.SWRemote;

	if(typeof this.domObject.codebase == 'undefined' || this.domObject.codebase.toString() == '')
		this.xndObject.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0';

	if(typeof this.domObject.id != 'undefined' && this.domObject.id.toString() != '')
		this.xndObject.id = this.domObject.id;

};

ActivateObject.prototype.removeOriginalObject = function()
{
	this.domObject.parentNode.removeChild(this.domObject);
};

/*****************************************************************************
* ActivateObjectFlash Command
*///**************************************************************************
function ActivateObjectFlash(domObject)
{
	ActivateObject.call(this,domObject);
}
ActivateObjectFlash.prototype = new ActivateObject;
ActivateObjectFlash.prototype.aObjectProperty = ['FrameNum','Playing','Quality','Quality2','Scalemode','Scale','AlignMode','SAlign','BackgroundColor','BGColor','Loop','Movie','WMode','Base','DeviceFont','EmbedMovie','SWRemote','FlashVars','AllowScriptAccess'];
ActivateObjectFlash.prototype.classid = 'D27CDB6E-AE6D-11CF-96B8-444553540000';


/*****************************************************************************
* Script initialisation
*///**************************************************************************
if(typeof ActiveXObject != 'undefined' && typeof Function.call != 'undefined')
{
	var styleId = BackToTheHtml.uniqueID();
	document.write('<style id="' + styleId + '" ></style>');
	var domStyle = document.getElementById(styleId);

	var isHead = false;
	var aHead = document.getElementsByTagName('head');
	for(var i=0; i<aHead.length; i++)
		if(BackToTheHtml.isParentOf(aHead[i],domStyle))
			isHead = true;

	if(isHead)
	{
		document.write('<style type="text/css">OBJECT{visibility:hidden;}</style>');
		document.onreadystatechange = function()
		{
			if(document.readyState == 'complete')
			{
				new BackToTheHtml().execute();
				document.styleSheets[document.styleSheets.length-1].addRule("OBJECT","visibility:visible;");
				//alert('head');
				//alert(document.body.innerHTML);
			}
		}
	}
	else
	{
		new BackToTheHtml().execute();
		//alert('body');
		//alert(document.body.innerHTML);
	}
	
	domStyle.parentNode.removeChild(domStyle);
}

