/* 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", "head_injectSO", "795", "168", "8", "#969561");
	so_head.write("anim-flash");
}

/* 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;
}

/* clearOnFocus
********************/
var toClear = new Array();
toClear.push("nl_mail");
toClear.push("head_recherche");
toClear.push("mail_visit");
toClear.push("mail_ami");

function initClearOnFocus(){
	for (var i=0; i<toClear.length; ++i){
		var itemToClear = document.getElementById(toClear[i]);
		if(!itemToClear) continue;
		addRemoveEvent(true, itemToClear, "focus", clearOnFocus);
	}
}
function clearOnFocus(e){
	var evt = e || window.event;
	var evtTarget = evt.target || evt.srcElement;
	evtTarget.value="";
	addRemoveEvent(false, evtTarget, "focus", clearOnFocus);
}

/* menu mooFX
********************/
function montre(){
	var menuIndex = window.menuIndex;
	var myStretch = document.getElementsByClassName('stretch');
	var myStretcher = document.getElementsByClassName('stretcher');
	var myAccordion = new fx.Accordion(myStretch, myStretcher, {opacity: false});
	if(menuIndex==undefined) var menuIndex = null;
	myAccordion.showThisHideOpen(myStretcher[menuIndex]);
}

/* init
********************/
document.observe("dom:loaded", function() {
  injectSO();
});
//addRemoveEvent(true, window, "load", injectSO);
addRemoveEvent(true, window, "load", initAnchors);
addRemoveEvent(true, window, "load", initClearOnFocus);
addRemoveEvent(true, window, "load", montre);

