var this_categorie=0;
var this_rubrique=0;

var top=50;
var wait=0;

function byId(name) { return document.getElementById(name); }

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop]; 
}	

function findPos2(obj) {
	obj=byId(obj);
	return [obj.style.left,obj.style.top];
}	

function scroll_rail() {
	if(top%50==0) {
		wait++;
		if (wait<400) return;
		else wait=0;
	}
	top-=2;
	if(top<=-249) top=98;
	if(byId('rail_annonces'))
		byId('rail_annonces').style.marginTop=top+'px';
}

var gauche=0;
var haut=0;

if(navigator.appName.substring(0,3) == "Net") document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = deplacerCurseur;

function afficherCurseur(x, y) {
	this.gauche = x;
	this.haut = y;
	move_tooltip();
}

function deplacerCurseur(e) {
	if (navigator.appName.substring(0,3) == "Net") {
		x = e.pageX;
		y = e.pageY;
	} else {
		if(window.opera) {
			x=event.x+document.body.scrollLeft;
			y=event.y+document.body.scrollTop;
		} else
		if (document.body) {
			x = event.x+document.body.scrollLeft+document.documentElement.scrollLeft;
			y = event.y+document.body.scrollTop+document.documentElement.scrollTop;
		} else {
			x = event.x+document.documentElement.scrollLeft;
			y = event.y+document.documentElement.scrollTop;
		}
	}
	byId('tooltip').style.left=''+(x+5)+'px';
	byId('tooltip').style.top=''+(y+3)+'px';
} 

setInterval("scroll_rail();", 10);

function move_tooltip() {
	byId('tooltip').style.left=''+(this.gauche+5)+'px';
	byId('tooltip').style.top=''+(this.haut+3)+'px';
}

function show_tooltip(texte) {
	byId('tooltip').innerHTML=texte;
	byId('tooltip').style.display='block';
}

function hide_tooltip() {
	byId('tooltip').style.display='none';
}

var menu_bg_highlighted='#383E7C';
var menu_bg='#70a4c5';
var categorie_timeout=null;
var rubrique_timeout=null;

function develop_categorie(categorie_id) {
	if (categorie_id==this_categorie && categorie_timeout) {
		clearTimeout(categorie_timeout);
		return;
	}

	if(byId('rubriques_'+this_categorie))
		byId('rubriques_'+this_categorie).style.display='none';

	if(this_categorie!=0)
		byId('categorie_'+this_categorie).style.backgroundColor=menu_bg;

	byId('categorie_'+categorie_id).style.backgroundColor=menu_bg_highlighted;
	
	if(byId('rubriques_'+categorie_id)) {
		byId('rubriques_'+categorie_id).style.top=''+(findPos(byId('categorie_'+categorie_id))[1]+byId('categorie_'+categorie_id).offsetHeight-1)+'px';
		byId('rubriques_'+categorie_id).style.left=''+findPos(byId('categorie_'+categorie_id))[0]+'px';
		byId('rubriques_'+categorie_id).style.display='block';
	}

	if(categorie_timeout)
		clearTimeout(categorie_timeout);
	this_categorie=categorie_id;
}

function remove_highlight_categorie(categorie_id) {
	if(byId('rubriques_'+categorie_id))
		byId('rubriques_'+categorie_id).style.display='none';
	byId('categorie_'+categorie_id).style.backgroundColor=menu_bg;
	this_categorie=0;
}

function retract_categorie(categorie_id) {
	categorie_timeout=setTimeout('remove_highlight_categorie('+categorie_id+');', 1000);
}

function develop_rubrique(rubrique_id) {
	if (this_rubrique==rubrique_id && rubrique_timeout) {
		clearTimeout(rubrique_timeout);
		return;
	}
	remove_highlight_rubrique();
	byId('rubrique_'+rubrique_id).style.backgroundColor=menu_bg_highlighted;

	if(byId('sous_rubriques_'+rubrique_id) && byId('rubrique_'+rubrique_id)) {
		byId('sous_rubriques_'+rubrique_id).style.top=''+byId('rubrique_'+rubrique_id).offsetTop+'px';
		byId('sous_rubriques_'+rubrique_id).style.left=''+(byId('rubrique_'+rubrique_id).offsetLeft + byId('rubrique_'+rubrique_id).offsetWidth + 1)+'px';
		byId('sous_rubriques_'+rubrique_id).style.display='block';
	}

	if(rubrique_timeout)
		clearTimeout(rubrique_timeout);
	this_rubrique=rubrique_id;
}

function remove_highlight_rubrique() {
	if(byId('sous_rubriques_'+this_rubrique))
		byId('sous_rubriques_'+this_rubrique).style.display='none';
	if(byId('rubrique_'+this_rubrique))
		byId('rubrique_'+this_rubrique).style.backgroundColor=menu_bg;
	this_rubrique=0;
}

function retract_rubrique(rubrique_id) {
	rubrique_timeout=setTimeout('remove_highlight_rubrique();',1000);
}

function highlight_sous_rubrique(sous_rubrique_id) {
	byId('sous_rubrique_'+sous_rubrique_id).style.backgroundColor=menu_bg_highlighted;
}

function remove_highlight_sous_rubrique(sous_rubrique_id) {
	byId('sous_rubrique_'+sous_rubrique_id).style.backgroundColor=menu_bg;
}
