// Redirection si on n'est pas sur le bon domaine
if (window.location.host != 'forum.aube-asso.fr') {
	urlRedirect = 'http://forum.aube-asso.fr';
	if (window.location.pathname != '/forum.htm' && window.location.pathname != '/index.htm') {
		urlRedirect += window.location.pathname;
	}
	if (read_cookie('aube_redirect') == null) {
		today = new Date() ;
		expdate = new Date() ;
		expdate.setTime(today.getTime() + (15*365*24*60*60*1000)) ;
		document.cookie = "aube_redirect=1;expires=" + expdate.toGMTString();
		alert("Le forum de l'association Aube a d\351m\351nag\351.\n\nVous allez \352tre automatiquement redirig\351 vers la nouvelle adresse.\nPensez \340 mettre \340 jour vos favoris.\n\n");
	}
	window.location = urlRedirect;
}

// Insertion de la feuille de style IE
if (navigator.userAgent.indexOf('MSIE') != -1) {
	var ieCSS = document.createElement('link');
	ieCSS.rel='stylesheet';
	ieCSS.href='http://www.aube-asso.fr/style/font_style_IE.css';
	ieCSS.type='text/css';
	document.getElementsByTagName("head")[0].appendChild(ieCSS);
}

$(document).ready(function(){
	// taille du nom de l'utilisateur pour déconnexion
	deco = $("#m9").children("a").html();
	if (deco != null) {
		user = deco.substring(deco.indexOf("[", 0) + 2, deco.indexOf("]", 0) - 1);
		toReplace = '[ ' + user + ' ]';
		// raccourcissement du nom si trop grand
		if (user.length > 15) {
			user = user.substring(0, 15) + '...';
		}
		$("#m9").children("a").html(deco.replace(toReplace, '<span class="user">[' + user + ']</span>'));
	}
	
	// MP reçus clignotant
	if ($('#msg').html() != 'Messagerie') {
		blinkMsg();
	}
	
	// Un joli séparateur de signature
	$("div.signature_div").each(function() {
		br = $(this).children("br");
		if (br.length == 0) {
			$(this).remove();
			return true;
		}
		br.each(function(i) {
			if (i > 1) {
				return false;
			}
			$(this).remove();
			return true
		});
		$(this).prepend('<hr/>');
		return true;
	});

	// Survol des elements navbar
	for (var i=1; i <= 10; i++) {
		$("#m"+i).mouseover(function() {
			$(this).addClass("mActif");
		});
		$("#m"+i).mouseout(function() {
			$(this).removeClass("mActif");
		});
	}
	
	// Survol des elements bas
	for (var i=1; i <= 6; i++) {
		$("#mb"+i).mouseover(function() {
			$(this).addClass("mActif");
		});
		$("#mb"+i).mouseout(function() {
			$(this).removeClass("mActif");
		});
	}
	
});

// Fonction pour faire clignoter
function blinkMsg() {
	if ($('#msg').parent().hasClass('mActif')) {
		$('#msg').parent().removeClass('mActif');
	} else {
		$('#msg').parent().addClass('mActif');
	}
	setTimeout("blinkMsg()",1000);
}

// Fonction de lecture de cookie
function read_cookie(nom) {
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen){
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) {
			return cook_arg(j);
		}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) {
			break;
		}
	}
	return null; 
}

// Fonction de lecture d'un élément de cookie
function cook_arg(offset){
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr=document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr)); 
}