var clock_hide;

function reset_clock() {
clearTimeout(clock_hide);
clock_hide=null;
}

function stop_it(func, args, t) {
	if (! eval('window.'+func) ) return;
	else {
		if (clock_hide) reset_clock();
	clock_hide = setTimeout(func+'('+args+')',t);	
	}
}

function choix_cheveux_sous_menu(f) {
reset_clock();
var m=document.getElementById('choix_cheveux_sous_menu');
m.style.display=f==1?'block':'none';
m.style.visibility=f==1?'visible':'hidden';
 if (document.getElementById('scrolldiv2_content'))
 document.getElementById('scrolldiv2_content').style.visibility=f==1?'hidden':'visible';
}

function after_ajax() {
var s=document.getElementById('scrolldiv2_content');	
	if (s) {
	var h = s.clientHeight;
		if (h==0) h = s.offsetHeight;
		
		if (h>102) { //cf css de #scrolldiv2_content dans scrolling.css
		document.getElementById('scrolldiv2_slider').style.display='block';
		}
	}
}

var codesHexa="0123456789ABCDEF";
function codeHexa (octetDec) 	{
	// octet décimal ==> hexadécimal
	return (codesHexa.charAt(octetDec>>>4)+codesHexa.charAt(octetDec&15));
	}
function decodeHexa (octetHex) 	{
	// octet hexadécimal ==> décimal
	return ( (codesHexa.indexOf(octetHex.charAt(0))<<4) + codesHexa.indexOf(octetHex.charAt(1)) );
	}
	
//FONCTIONS DE CRYPTAGE
var clef="9Ajf0kDhD4GBwnuis1ys1d45br7uyZ"; // Vous pouvez modifier cette clef
/*function crypte (texte) {
	// texte en clair ==> texte crypté
	resultat="";
	l=texte.length;
	lc=clef.length;
	m=0;
	for (n=0;n<l;n++)
		{
		c=texte.charCodeAt(n);
		if (c<256) {
			// Uniquement les caractères ASCII
     			resultat+=codeHexa( c ^ clef.charCodeAt(m%lc) );
			m++;
			}
		}
	//alert(resultat);
	document.mailcode.mailcodee.value = resultat;
	//return resultat;
	}*/
function decrypte (texte) {
	// texte crypté ==> texte en clair
	resultat="";
	l=texte.length;
	lc=clef.length;
	m=0;
	for (n=0;n<l;n+=2)
		{
		c=decodeHexa(texte.substr(n,2));
		resultat+=String.fromCharCode( c ^ clef.charCodeAt(m%lc) );
		m++;
		}
		return resultat;
	}

	
function remplace_JS_contenus(div) {
//@author:yann ducrocq www.pix-l.fr
	for (var i=0; i<div.getElementsByTagName('SPAN').length;i++) {
	var span = div.getElementsByTagName('SPAN')[i];
	
		if (span.className=='contenu_js') {			
		var m=span.innerHTML.match(new RegExp(/^([^\:]*)\:(.*)/));				
		/* si c'est un mail à crypter, il faut un span de type :
		<span class="contenu_js">mail:565454d5f545s4f45ds4f</span> */
			if (m[1]=='mail') {
			var new_html='<a href="mailto:'+decrypte(m[2])+'">'+decrypte(m[2])+'</a>\n';
			span.innerHTML = new_html;
			}			
		}
	}
}



//-------------- fake scrolling ---------------------

var clock_scroll2;

function yanno_scroll_it(dir) {
var s=document.getElementById('scrolldiv2_content');
var posTop = parseInt(s.style.top.toString().replace(/px/, '')) + (5*dir);

var h = s.clientHeight;
	if (h==0) h = s.offsetHeight;
	
	if (isNaN(posTop) || posTop > 4 || posTop=='') posTop=4; 	
	else if (dir < 0 && h > 102) {
		if (posTop < -1 * (h - 92) ) posTop = -1 * (h - 92); //cf css de #scrolldiv2_content dans scrolling.css
	}
	
debug('cH: '+ h);
debug('posTop: ' + posTop + ' ' + (-1 * (s.clientHeight - 92)) );

s.style.top = posTop + 'px';
	
debug(posTop);
clock_scroll2=setTimeout("yanno_scroll_it("+dir+")",1);
}

function yanno_stop_scroll() {
clearTimeout(clock_scroll2);
clock_scroll2 = null;
}
					

window.onload = function() {	
var arDivs = new Array('scrolldiv_content');
	for (var i=0; i<arDivs.length; i++) {
		if (document.getElementById(arDivs[i]))
		remplace_JS_contenus(document.getElementById(arDivs[i]));
	}	
}