// Calques
function findObj(theObj, theDoc)
{
	var p, i, foundObj;  
	if(!theDoc) theDoc = document;
/*	// cas des frames
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);}*/
	// IE5 et 6, NN 6-7 et autres
	if(document.getElementById)
		foundObj = document.getElementById(theObj);
	// IE4
	else if(!(foundObj = theDoc[theObj]) && theDoc.all) // enlever else pour tester Document.all sous IE
		foundObj = theDoc.all[theObj];
/*	// cas des forms
	for (i=0; !foundObj && i < theDoc.forms.length; i++)
		foundObj = theDoc.forms[i][theObj];*/
	// NN4
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
		foundObj = findObj(theObj,theDoc.layers[i].document);
	return foundObj;
}
function dumpobj(obj){
	result="",i="";
	for (i in obj){result+=i+" = "+obj[i]+"-----";}
	return result;
}
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-1); i+=2){
    if ((obj = findObj(args[i])) != null){
      visStr = args[i+1];
      if (obj.style){
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';}
      obj.visibility = visStr;}
  }
}

function showcalq(calque){
	var i,visi,obj;
	for(i=0; i<calq.length; i++){
		visi=calq[i]==calque?'show':'hide';
	    if ((obj = findObj(calq[i])) != null){
	      	if (obj.style){
    	    	obj = obj.style;
				visi=calq[i]==calque?'visible':'hidden';}
			obj.visibility=visi;
		}
	}
}

function setLayerTop(calque,y)
{
	var obj;
	if ((obj = findObj(calque)) != null){
		if (obj.style) obj = obj.style;
		if (document.layers) obj.top=y;
		else obj.top = y+'px';
	}
}
function moveLayer(calque,x,y)
{
	var obj;
	if ((obj = findObj(calque)) != null){
		if (obj.style) obj = obj.style;
		if (document.layers) {obj.top=y;obj.left=x;}
		else {obj.top = y+'px';obj.left = x+'px';}
	}
}
function changeLayer(calque,txt)
{
	var x,i, contenu="";
	if (document.getElementById){
		x = document.getElementById(calque);
		x.innerHTML = '';
		x.innerHTML = txt;
	}else if (document.all){
		x = document.all[calque];
		x.innerHTML = txt;
	}else if (document.layers){
		x = document.layers[calque];
		x.document.open();
		x.document.write('<p class="starstxt">'+txt+'</p>');
		x.document.close();
	}
}

var animtimeid=scrambletimeid=null;
var animflag=0;
var i=0;
var mousx=0;mousy=0;
var vill_on=besti=-2;
var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

	// init et démarrage


	animtimeid=setTimeout('periodique()',500);

function MouseBouge(e){
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){
		mousx = e.pageX;
		mousy = e.pageY;
	}else if (e.clientX || e.clientY){
		mousx = e.clientX;
		mousy = e.clientY;
		if (isIE){
			if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)){
				mousx += document.documentElement.scrollLeft;
				mousy += document.documentElement.scrollTop;
			}
			else if (document.body){
				mousx += document.body.scrollLeft;
				mousy += document.body.scrollTop;
			}
		}
	}
}
	if(document.layers){ //ns4
		window.captureEvents(Event.MOUSEMOVE);
		window.onMouseMove=MouseBouge;
	}else document.onmousemove=MouseBouge;

function showvill(numvil)
{
	if (numvil!= vill_on ){
		var largeur=noms[numvil].length;
		moveLayer('pointrouge',vilx[numvil]-7,vily[numvil]-7);
		if (largeur*7+vilx[numvil]+40 > x2){
			changeLayer('nomvillage',"&nbsp;"+noms[numvil]);
			moveLayer('nomvillage',x2-largeur*8-20,vily[numvil]+10);
		}
		else{
			changeLayer('nomvillage',"&gt;&nbsp;"+noms[numvil]);
			moveLayer('nomvillage',vilx[numvil]+10,vily[numvil]-9);
		}
		showHideLayers('pointrouge','show','nomvillage','show');
		vill_on=numvil;
	}
}
function hidevill()
{
	if (vill_on!=-1 ){	
		showHideLayers('pointrouge','hide','nomvillage','hide');
		vill_on=-1;
	}
}
function periodique()
{
	if (!animflag++) {
		if (mousx>x1 && mousx <x2 && mousy>y1 && mousy<y2){
			bestdelta=9999;
			for (i=0;i<vilx.length;i++){
				deltax=mousx-vilx[i];
				if (deltax<0) deltax=-deltax;
				deltay=mousy-vily[i];
				if (deltay<0) deltay=-deltay;
				if (deltax+deltay<bestdelta){
					bestdelta=deltax+deltay;
					besti=i;
				}
			}
			if (bestdelta < 16 && noms[besti]) showvill(besti); else hidevill();
		}
		animtimeid=setTimeout('periodique()',200);
		animflag=0;
	}
}
function showgrandcru()
{
	hidevill();
	showHideLayers('grandcru','show','premiercru','hide');
}
function showpremcru()
{
	hidevill();
	showHideLayers('grandcru','hide','premiercru','show');
}
function rien(){}
