/*************************************************
	Cache/montre des div
**************************************************/
function pop() {
    var myAs = document.getElementsByTagName('a');
    for (var a = 0; a < myAs.length; ++a) {
		// Si le lien a une classe de type pop
        if (myAs[a].className == 'pop') {
		// on extrait l'id de la popup à partir du href
            var pop = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
		// si la popup existe on l'affiche (display block)
            if (pop) {
                pop.style.display = 'none';
                myAs[a].onclick = function() {
                    thisPopup = document.getElementById(this.href.substring(this.href.lastIndexOf('#') + 1))
                    thisPopup.style.display = (thisPopup.style.display == 'none') ? 'block' : 'none';
                    return false;
                };
            }
        }
    }
}
/*************************************************
	Affichage des png sous ie6
**************************************************/
function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>";
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}
/*************************************************
	Postion fixed sous ie6
**************************************************/
function fixed_top(select,offS){
	return Number(offS+document.documentElement.scrollTop+document.body.scrollTop)+'px';
}
function fixed_left(select,offS){
	return Number(offS+document.documentElement.scrollLeft+document.body.scrollLeft)+'px';
}
function fixed_bottom(select,offS){
	return Number(-offS+document.documentElement.clientHeight-select.offsetHeight+document.documentElement.scrollTop+document.body.scrollTop)+'px';
}
function fixed_right(select,offS){
	return Number(-offS+document.documentElement.clientWidth-select.offsetWidth+document.documentElement.scrollLeft+document.body.scrollLeft)+'px';
}
/*************************************************
	Fonction ecrire cookies
**************************************************/
function EcrireCookie(nom, valeur){
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+((expires==null) ? "" : ("; expires="+expires.toGMTString()))+((path==null) ? "" : ("; path="+path))+((domain==null) ? "" : ("; domain="+domain))+((secure==true) ? "; secure" : "");
}
//EcrireCookie("dejavenu", "oui");
/*************************************************
	Fonction lire cookies
**************************************************/
function getCookieVal(offset){
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(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 getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}
//nbvisites=LireCookie("dejavenu");

/***************************************************
			couleur de tag
***************************************************/
function rand ( n ){
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}
function gotags(){
	var tab_couleur = ["","#D5B920","#F7F7F7","#DF2278","#C2D220","#D65421","#20A0CF","#ffffff"];
	var mes_tags = document.getElementById('tagcloud').getElementsByTagName('li');
	for(var i = 0;i<mes_tags.length;i++){
		//alert('rand = '+rand(7)+' et couleur ='+tab_couleur[rand(7)]);
		mes_tags[i].childNodes[0].style.color = tab_couleur[rand(7)];
	}
}
function gotags2(){
	gotags();
//ocument.getElementsByTagName("*").length
	//document.getElementById('tagcloud').getElementsByTagName("a").style.color = '#00ff00';
}

	/***************************************************
			Set les cookies
	***************************************************/
	var ready = 'non';
	function cook(){
		var jete = ready;
		var date = new Date;
		date.setMonth(date.getMonth()+1);
		EcrireCookie("visible", jete, date);
	}
	function cookgo(){
		function matween(){
			new Effect.toggle($('bottom_nav'),'blind', {duration: 0.7});
		}
		if(LireCookie("visible") == 'oui'){
			if(!ie){
				setTimeout("btn_css(document.getElementById('btn1'));",1000);
				setTimeout(matween,1000);
			}else{
				btn_css(document.getElementById('btn2'));
				document.getElementById('bottom_h2').style.display = 'block'
				document.getElementById('bottom_nav').style.display = 'block'
			}
		} else if(LireCookie("visible") == null){
			if(!ie){
				document.getElementById('bottom_h2').style.display = 'block';
				setTimeout(matween,1000);
				setTimeout("btn_css(document.getElementById('btn2'));",1000);
				setTimeout("new Effect.Highlight('btn2', 1)",1200);
				setTimeout("new Effect.Highlight('btn2', 1)",2250);
				setTimeout(matween,3500);
				setTimeout("btn_cssback(document.getElementById('btn2'));",3500);
			}else{
				new Effect.ScrollTo('footer',{duration:1.5});
				//
				setTimeout("document.getElementById('bottom_h2').style.display = 'block';",2000);
				setTimeout("document.getElementById('bottom_nav').style.display = 'block';",2000);
				setTimeout("new Effect.ScrollTo('footer',{duration:0.7});",2000);
				//
				setTimeout("btn_css(document.getElementById('btn2'));",2000);
				setTimeout("new Effect.Highlight('btn2', 1)",2200);
				setTimeout("new Effect.Highlight('btn2', 1)",3250);
				//
				setTimeout(matween,4500);
				setTimeout("btn_cssback(document.getElementById('btn2'));",4500);
				//
				setTimeout("new Effect.ScrollTo('page',{duration:1.5});",5500);
			}
			ready = 'oui';
			cook();
		}
		/*else if(LireCookie("visible") == 'non'){
			if(!ie){
				//setTimeout("btn_css(document.getElementById('btn1'));",1000);
				//setTimeout(matween,1000);
			}else{
				btn_css(document.getElementById('btn2'));
				document.getElementById('bottom_h2').style.display = 'block'
				document.getElementById('bottom_nav').style.display = 'block'
			}
		}*/
	}
	/*************************************************
		Condition si ie6
	**************************************************/
	var ie = false;
	if (navigator.userAgent.indexOf("MSIE 6") != -1) {
		ie = true;
	}
	/*************************************************
		Boutons
	**************************************************/
	function btn_light(select){
		ready = 'oui';
		btn_css(select);
		btn_cssback(document.getElementById('btn2'));
		btn_cssback(document.getElementById('btn3'));
		if(document.getElementById('bottom_nav').style.display == 'none'){
			document.getElementById('bottom_h2').style.display = 'none';
			if(!ie){
				new Effect.toggle($('bottom_nav'),'blind', {duration: 0.7});
			}else{
				document.getElementById('bottom_nav').style.display = 'block';
				new Effect.ScrollTo('footer',{duration:0.7});
			}
		} else{
			if(!(document.getElementById('bottom_h2').style.display == 'none')){
				new Effect.toggle($('bottom_h2'),'blind', {duration: 0.5, fps: 30});
			}
		}
		cook();
	}
	function btn_full(select){
		ready = 'oui';
		btn_css(select);
		btn_cssback(document.getElementById('btn1'));
		btn_cssback(document.getElementById('btn3'));
		if(document.getElementById('bottom_nav').style.display == 'none'){
			document.getElementById('bottom_h2').style.display = 'block';
			if(!ie){
				new Effect.toggle($('bottom_nav'),'blind', {duration: 0.7});
			}else{
				document.getElementById('bottom_nav').style.display = 'block';
				new Effect.ScrollTo('footer',{duration:0.7});
			}
		} else{
			if(document.getElementById('bottom_h2').style.display == 'none'){
				if(!ie){
					new Effect.toggle($('bottom_h2'),'blind', {duration: 0.5, fps: 30});
				}else{
					document.getElementById('bottom_h2').style.display = 'block';
					new Effect.ScrollTo('footer',{duration:0.5});
				}
			}
		}
		cook();
	}
	function btn_close(select){
		ready = 'non';
		btn_cssback(document.getElementById('btn1'));
		btn_cssback(document.getElementById('btn2'));
		if(!(document.getElementById('bottom_nav').style.display == 'none')){
			new Effect.toggle($('bottom_nav'),'blind', {duration: 0.7});
		}
		cook();
	}
	/*************************************************
		css boutons
	**************************************************/
	function btn_css(select){
		select.style.position = "relative";
		select.style.height = "11px";
		select.style.top = "5px";
		select.style.backgroundColor = "#000000";
		if(ie){
			select.style.borderBottom = "4px solid #000000";
		}
	}
	function btn_cssback(select){
		select.style.height = "15px";
		select.style.top = "0px";
		select.style.backgroundColor = "#998058";
		if(ie){
			select.style.borderBottom = "none";
		}
	}
/*************************************************
	Appel de fonction au chargement
**************************************************/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
/*************************************************
	Appel de fonction au chargement
**************************************************/
function init() {
	if (navigator.userAgent.indexOf("MSIE 6") != -1) {
		correctPNG();
	}
}
/*************************************************
	Done !
**************************************************/
addLoadEvent(init);
addLoadEvent(pop);
addLoadEvent(cookgo);
addLoadEvent(gotags);
