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

/* menu
*********************/
function initMenu(){
	var mt = document.getElementById('headMenu').getElementsByTagName('dt');
	for(var i=0; i < mt.length; i++){
		var mtid = mt[i].getAttribute('id');
		if(mtid == 'majeur'){
			addRemoveEvent(true, mt[i], 'mouseover', function(){ swapMenu('smenu1'); });
			continue;
		}
		else if(mtid == 'mineur'){
			addRemoveEvent(true, mt[i], 'mouseover', function(){ swapMenu('smenu2'); });
			continue;
		}
		else if(mtid == 'club'){
			addRemoveEvent(true, mt[i], 'mouseover', function(){ swapMenu('smenu3'); });
			continue;
		}
		else{
			addRemoveEvent(true, mt[i], 'mouseover', function(){ swapMenu(); });
		}
	}
	addRemoveEvent(true, document.getElementById('contenu'), 'mouseover', function(){ swapMenu(); });
}
function swapMenu(id){
	for (var i = 1; i <= 10; i++){
		var di = document.getElementById('smenu'+i);
		if(di) di.style.display = 'none';
	}
	if(id) document.getElementById(id).style.display = 'block';
}

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

/* embed swf
*********************/
swfobject.embedSWF("swf-xml/header.swf", "headFlash", "980", "168", "8.0.0", "swf-xml/expressInstall.swf", {}, {}, {});

/* central init
*********************/
swfobject.addDomLoadEvent(function(){
	initMenu();
	initAnchors();
	sIFR.replaceElement(named({
		sSelector:"#contenuTexte h1",
		sFlashSrc:"type/avant_guarde_md_bt_it.swf",
		sColor:"#004981",
		sLinkColor:"#004981",
		sBgColor:"#FFFFFF",
		sHoverColor:"#004981",
		nPaddingTop:0,
		nPaddingBottom:0,
		sFlashVars:"textalign=left&offsetLeft=10",
		sWmode:"transparent"
	}));
});

