/* Javascripts utilisés sur le site
 * Mettez l'ensemble de vos fonctions générique javascript ici
 * 
 * La liaison avec les page se fait à l'aide du code ci-dessous :
 * <script type="text/javascript" src="css-js/scripts.js"></script>
 */

/* addRemoveEvent
********************/
function addRemoveEvent(add, el, evt, func){
	if(add){
		if(el.addEventListener) el.addEventListener(evt, func, false);
		else if (el.attachEvent) el.attachEvent("on" + evt, func);
	}else{
		if(el.removeEventListener) el.removeEventListener(evt, func, false);
		else if (el.detachEvent) el.detachEvent("on" + evt, func);
	}
}

/* swf object
********************/
function injectSO(){
	var so_head = new SWFObject("swf-xml/header.swf", "soInjected_header", "950", "241", "8", "#FFFFFF");
	so_head.addParam("wmode", "transparent");
	so_head.write("header");
	var accMontre = document.getElementById("acc_montre");
	if (accMontre){
		var so_montre = new SWFObject("swf-xml/montre.swf", "soInjected_montre", "150", "240", "8", "#E6E8F7");
		so_montre.addParam("wmode", "transparent");
		so_montre.write("acc_montre");
	}
}

/* clearOnFocus
********************/
function initClearOnFocus(){
	textRecherche = document.getElementById("text_recherche");
	if (textRecherche) clearOnFocus("text_recherche");
}
function clearOnFocus(el){
	var toClear = document.getElementById(el);
	if(!toClear) return;
	toClear.onfocus = function(){
		this.value="";
		this.onfocus = null;
	};
}

/* anchors
********************/
function initAnchors(){
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; ++i){
		if (!anchors[i].getAttribute("href") || !anchors[i].getAttribute("rel")) continue;
		var relation = String(anchors[i].getAttribute("rel"));
		if (relation.match("popup")) anchors[i].onclick=popup;
		if (relation == "external") anchors[i].onclick=externalLink;
	}
}
function popup(){
	var relation = String(this.getAttribute("rel"));
	if(relation == "popup"){
		window.open(this, "pop", "scrollbars=no");
	}else{
		var arguments = relation.substring(6,relation.length-1).split(";");
		window.open(this,arguments[0],'toolbar=0,location=0,directories=0,status=0,menubar=0,' + arguments[1] + ',resizable=no,width=' + arguments[2] + ',height=' + arguments[3] + ',top=' + arguments[4] + ',left=' + arguments[5]);
	}
	return false;
}
function externalLink(){
	window.open(this);
	return false;
}

/* swapPic
********************/
function swapPic(){
	document.getElementById("bigpict").src = this;
}

function initSwapPic(){
	var swapZone = document.getElementById("thumbs");
	if(!swapZone) return;
	var triggers = swapZone.getElementsByTagName("a");
	for (var i=0; i<triggers.length; ++i){
		triggers[i].onclick = function(){ return false; };
		triggers[i].onmouseover = swapPic;
	}
}

/* init
********************/
addRemoveEvent(true, window, "load", injectSO);
addRemoveEvent(true, window, "load", initClearOnFocus);
addRemoveEvent(true, window, "load", initSwapPic);
addRemoveEvent(true, window, "load", initAnchors);
