// JavaScript Document
var x = 0;
var y = 0;

//if(document.getElementById) {
//    var Xli = 0;
//    var Yli = 0;
//    document.captureEvents(Event.MOUSEMOVE);
//    document.onmousemove = Pos_Souris;
//}
if(document.getElementById) {
	var Xli = 0;
	var Yli = 0;
	if(navigator.appName.substring(0,3) == "Net")
	{
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = Pos_Souris;
}
/*
function Pos_Souris(e) {
    if (e.pageX) {
        x = e.pageX;
    } else {
        x = event.x+document.body.scrollLeft;
    }
    if (e.pageY) {
        y = e.pageY;
    } else {
        y = event.y+document.body.scrollTop;
    }
    return x, y;
}
*/

function Pos_Souris(e) {
	x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
	y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
	return x, y;
}


var myParent;
var myNode;
var interv;
var Xcoord=0;
var Xwidth=0;
var Ycoord=0;
var Yheight=0;

// construction de la classe pays
function pays(name,cities) {
	this.name = name;
	this.cities = cities;
	this.writeIt = writeIt(name,cities)
}

// construction de la methode writeIt()
function writeIt(id,cities) {
    var myCities = '<blockquote>';
    for(ii=0; ii<cities.length; ii++) {
        myCities += cities[ii][0]+"<br>";
    }
    myCities += '</blockquote>';
    myNode.parentNode.childNodes[2].innerHTML = myCities;
}


function hitTest() {
    //alert(Xcoord + "<" + x + "<" + (Xcoord + Xwidth) + " - " + Ycoord + "<" + y + "<" + (Ycoord + Yheight));
    if ((x < Xcoord) || (x > (Xcoord + Xwidth))) {
        myNode.parentNode.childNodes[2].style.display='none';
        Xcoord=0;
        Xwidth=0;
        Ycoord=0;
        Yheight=0;
        clearInterval (interv);
    }
    if ((y < Ycoord) || (y > (Ycoord + Yheight))) {
        myNode.parentNode.childNodes[2].style.display='none';
        Xcoord=0;
        Xwidth=0;
        Ycoord=0;
        Yheight=0;
        clearInterval (interv);
    }
}


function test(id,countryIdx) {
    if ((x > Xcoord) && (x < (Xcoord + Xwidth)) && (y > Ycoord) && (y < (Ycoord + Yheight))) {
        // We are in the destination list : do not display new one because link is under the destination linst.
        return;
    }
    clearInterval (interv);
    myNode = document.getElementById(id);
    var cities = countriesTab[countryIdx];    
    var myCountry = new pays(id,cities);
    if (myNode.hasChildNodes() && myNode.parentNode.childNodes[2].style.display!='inline') {
        myNode.parentNode.childNodes[2].style.display='inline'
    } else {
        myNode.parentNode.childNodes[2].style.display='none';
    }
    if (myParent!=id && myParent!=null) {
        document.getElementById(myParent).parentNode.childNodes[2].style.display='none';
        myStatus=false;
    } else {
        myNode.parentNode.childNodes[2].style.display='inline';
        myStatus=true;
    }
    
    myParent=id;

    Xcoord = parseInt(myNode.parentNode.childNodes[2].offsetLeft);
    Ycoord = parseInt(myNode.parentNode.childNodes[2].offsetTop);
    Xwidth = parseInt(myNode.parentNode.childNodes[2].offsetWidth);
    Yheight = parseInt(myNode.parentNode.childNodes[2].offsetHeight);

    interv = setInterval ("hitTest()", 1000);
}

function autoresize(idLeft,idRight) {
	idLeftHeight = parseInt(document.getElementById(idLeft).offsetHeight);
	idRightHeight = parseInt(document.getElementById(idRight).offsetHeight);
	(idLeftHeight>idRightHeight) ? document.getElementById(idLeft).style.height=idRightHeight+'px' : document.getElementById(idLeft).style.height=idRightHeight+'px' ;
}
