/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|
|		Copyright (c) 2007
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

var siteMapManager;

/* ______________________[ 02 | Gestion de la taille du texte d’un article ]________________________ */

function SmartSize() {
	var args=SmartSize.arguments;
	if (document.getElementById && document.getElementById("Tplus") && document.getElementById("Tmoins")) {
		var cibleplus=document.getElementById("Tplus");
		var ciblemoins=document.getElementById("Tmoins");
		cibleplus.onclick=function() {
			for (n=0;n<args.length;n++) {
				if (document.getElementById(args[n])) {
					var cibletxt=document.getElementById(args[n]);
					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):12);
					cibletxt.style.fontSize=(sizestr+1)+"px";
				}
			}
		};
		ciblemoins.onclick=function() {
			for (n=0;n<args.length;n++) {
				if (document.getElementById(args[n])) {
					var cibletxt=document.getElementById(args[n]);
					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):12);
					cibletxt.style.fontSize=(sizestr-1)+"px";
				}
			}
		};
	}
};


/* ______________________[ 04 | Miscellaneous ]________________________ */

function OpenPopup(url,nom,option) {
	window.open(url,nom,option);
};

/* ______________________[ 01 | Gestion de l'icône Impression de la Page ]________________________ */

function DirectPrint() {
	if (window.print) self.print();
};

/* ______________________[ 03 | Bouton generique - (c) remy@smartpixel / Smart Agence, 2007]________________________ */

function AddToolButton(sContainerID, oParams){
	var DOM = document.createElement && document.getElementById && document.getElementById(sContainerID);
	if(DOM){
		var cible=document.getElementById(sContainerID).getElementsByTagName('UL');

		if(cible){
			var oLi = document.createElement("LI");
			var oLink = document.createElement("A");
			var oImg = document.createElement("IMG");

			with(oLink){
				id = oParams.linkId;
				title = oParams.imgAlt;
				href = oParams.linkHREF ? oParams.linkHREF : "javascript:;";
				onclick = oParams.onclick ? oParams.onclick : "";
			};
			with(oImg){
				src = oParams.imgSrc;
				alt = oParams.imgAlt;
			};
			oLink.appendChild(oImg);
			oLi.appendChild(oLink);

			// insertion ... avant un element existant
			if(oParams.insertBefore){
				var oNext = document.getElementById(oParams.insertBefore).parentNode;
				cible[0].insertBefore(oLi,oNext);
			}
			else{
				// ou en fin de liste
				cible[0].appendChild(oLi);
			}
		}	// end if cible
	}	// end if DOM
};	// end AddToolButton()


/* ______________________[ 07 | <select/> au clavier ]________________________ */

/* Thanks goes to Cameron Adams from http://www.themaninblue.com/ */

function initSelect(whichSelect) {
	if (document.getElementById&&document.getElementById(whichSelect)) {
		var theSelect=document.getElementById(whichSelect);
		theSelect.changed=false;
		theSelect.onfocus=selectFocussed;
		theSelect.onchange=selectChanged;
		theSelect.onkeydown=selectKeyed;
		theSelect.onclick=selectClicked;
		return true;
	}
};

function selectChanged(theElement) {
	var theSelect;
	if (theElement&&theElement.value) {
		theSelect=theElement;
	} else {
		theSelect=this;
	}
	if (!theSelect.changed) {
		return false;
	}
	if (theSelect.value&&theSelect.value!="0") window.location=theSelect.value;
	return true;
};

function selectClicked() {
	this.changed=true;
};

function selectFocussed() {
	this.initValue=this.value;
	return true;
};

function selectKeyed(e){
	var theEvent;
	var keyCodeTab="9";
	var keyCodeEnter="13";
	var keyCodeEsc="27";
	if (e) {
		theEvent=e;
	} else {
		theEvent=event;
	}
	if ((theEvent.keyCode==keyCodeEnter||theEvent.keyCode==keyCodeTab)&&this.value!=this.initValue) {
		this.changed=true;
		selectChanged(this);
	} else if (theEvent.keyCode==keyCodeEsc) {
		this.value=this.initValue;
	} else {
		this.changed=false;
	}
	return true;
};


function SmartToggle(sToggledElement,oParams) {
	if(document.createElement && document.getElementById) {
		var oTitle = document.createElement(oParams.titleTag);
		var oParent;
		var oToggledElement = document.getElementById(sToggledElement);
		if(oToggledElement) {
			oParent = document.getElementById(sToggledElement).parentNode;
			oTitle.innerHTML = oParams.innerHTML;
			oTitle.firstChild.className="toggle_hide";
			oTitle.firstChild.onclick=function() {
				var oTarget=this.firstChild;
				oTarget.innerHTML=(oTarget.innerHTML=='[Montrer]'?'[Masquer]':'[Montrer]');
				if(oTarget.innerHTML=="[Montrer]"){
					oTitle.firstChild.setAttribute('title',oParams.toggleAlt.show);
					oTitle.firstChild.className="toggle_show";
					oToggledElement = oParent.removeChild(oToggledElement);
				}
				else {
					oTitle.firstChild.setAttribute('title',oParams.toggleAlt.hide);
					oTitle.firstChild.className="toggle_hide";
					// simulation d'insertAfter
					oParent.insertBefore(oToggledElement,oTitle.nextSibling);
				}
			};
			oParent.insertBefore(oTitle, document.getElementById(sToggledElement));
		}
	}
};

/* Mettre la page courante en favoris ? MSIE and Firefox */
function myBookmark() {
	if (document.getElementById&&document.getElementById("favoris")) {
		var el=document.getElementById("favoris");
		var operaStr="&lsaquo; Ctrl + T &rsaquo; pour ajouter aux favoris.";
		if (document.all&&navigator.userAgent.indexOf("Opera")==-1) {
			window.external.AddFavorite(document.location,document.title);
		} else if (window.sidebar) {
			window.sidebar.addPanel(document.title,document.location.href,"");
		} else if (navigator.userAgent.indexOf("Opera")!=-1) {
			el.title=operaStr;
			window.status=operaStr;
		}
	}
};


/* ______________________ Tabbed list avec contenu changeant au clic ___________________ */

function cleanWhiteSpace(oElement) {
	for (var i = 0; i < oElement.childNodes.length; i++) {
		var oNode = oElement.childNodes[i];
		if (oNode.nodeType == 3 && !/S/.test(oNode.nodeValue)) {
			oElement.removeChild(oNode);
		}
	}
};

function getPosition(oElement) {
	var oParent = oElement.parentNode;
	var i = 0;

	while(oElement !== oParent.childNodes[i]) {
		i++;
	}

	return i;
};

function tabbedListManager(sListID) {
	var oList = document.getElementById(sListID);
	cleanWhiteSpace(oList);
	cleanWhiteSpace(oList.parentNode);
	cleanWhiteSpace(oList.parentNode.lastChild);
	var oContentsContainer = oList.parentNode.lastChild;
	var aContents = new Array();

	for(var i = 0 ; i < oContentsContainer.childNodes.length ; i++) {
		aContents[i] = oContentsContainer.childNodes[i].cloneNode(true);
	}

	oContentsContainer.removeChild(oContentsContainer.lastChild);

	for(var i = 0; i < oList.childNodes.length ; i++) {
		var currentNode = oList.childNodes[i];
		currentNode.onclick = function() {
			if(oContentsContainer.childNodes.length > 0){
				oContentsContainer.removeChild(oContentsContainer.childNodes[0]);
			}

			for( var j = 0 ; j < oList.childNodes.length ; j++) {
				oList.childNodes[j].className = "";
				oList.childNodes[j].innerHTML = '<a href="javascript:;">'+oList.childNodes[j].firstChild.innerHTML+'</a>';
			}

			this.className = "on";
			this.innerHTML = '<strong>' + this.firstChild.innerHTML + '</strong>';
			oContentsContainer.appendChild(aContents[getPosition(this)]);
		};
	}
};

/* 	Ouverture d'une pop-up sur clic d'un lien	*/
function OpenPopup(sLinkId,iWindowW,iWindowH){
	if(document.createElement && document.getElementById){
		var oLink = document.getElementById(sLinkId);
		if(oLink.tagName == "A") {
			oLink.onclick = function() {
				window.open(this.href,"wSendToFriend","menubar=no, status=no, scrollbars=no, width="+iWindowW+", height="+iWindowH);
				return false;
			};
		}
	}
};


function fixTopLink(sID,sTargetID) {


	var oElement = document.getElementById(sID);

	if(oElement) {
		if(oElement.tagName != "A") {
			var oElement = oElement.getElementsByTagName("A")[0];
		}
		if(oElement) {
			oElement.href = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search + "#" + sTargetID;
		}
	}
};

/* ______________________[ 08 | Lancement des scripts ]________________________ */

window.onload = function() {
	fixTopLink("pageTop","HautDePage");
/*	var treeWalker = document.createTreeWalker(document, NodeFilter.SHOW_TEXT, { acceptNode: function(node) { return /\S/.test(node.nodeValue) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT } }, false);
	while (treeWalker.nextNode()) {
		treeWalker.currentNode.parentNode.removeChild(treeWalker.currentNode);
	}*/

	AddToolButton("toolBox",{linkId:"print",linkHREF:"javascript:DirectPrint();",imgSrc:"img/toolbox/print.gif",imgAlt:"Imprimer cette page",insertBefore:"toFriend"});
	AddToolButton("toolBox",{linkId:"Tmoins",imgSrc:"img/toolbox/text_smaller.gif",imgAlt:"Texte plus petit",insertBefore:"print"});
	AddToolButton("toolBox",{linkId:"Tplus",imgSrc:"img/toolbox/text_bigger.gif",imgAlt:"Texte plus grand",insertBefore:"Tmoins"});
	AddToolButton("toolBox",{linkId:"favoris",linkHREF:"javascript:myBookmark();",imgSrc:"img/toolbox/add_bookmark.gif",imgAlt:"Ajouter aux favoris"});
	OpenPopup("toFriend",500,400);
	SmartSize("ColMenu","ColContenu","ColContextuelle","ColGrandesLignes","ColResume");
	SmartToggle("verbatim_content",{"titleTag":"H3","toggleTexts":{"show":"[Montrer]","hide":"[Masquer]"},"toggleAlt":{"show":"Montrer le verbatim","hide":"Masquer le verbatim"},"innerHTML":'<a href="javascript:;" title="Masquer le verbatim"><span class="fx">[Masquer]</span></a> Verbatim'});

	if(document.getElementById("tabbedList_debats")) {
		tabbedListManager("tabbedList_debats");
	}
	if(siteMapManager) {
		siteMapManager.initialize("subcontainer",false ).makeTreesC();
	}
};
