//Initialize variables

	// 
	var checkProximity_flag, checkDistance_flag;
	var theGlobalObj;
	// browser type - we do assume version 4 or better

		
	// cursor position (absolute)
	var mouseX, mouseY;

	// position of the Luxembourg map (absolute)
	var mapShiftX = 230;   var mapShiftY = 200;

	// cursor position (relative to map)
	var mapRelX;   var mapRelY;
	
	// tracker size and position variables
	// ***** MAY GET REMOVED BECAUSE OF OVERHEAD ****
	var trackerOffsetX = 0;  var trackerOffsetY = 0;
	var trackerCenterX = 15; var trackerCenterY = 15;

	// basic map variables
	var mapMultiplier = 0.37;  //scaling variable for 1 pixel
	var mapTrigger = 75;       //pixel distance for showing a city

	// position of Luxemborg(=Aubange) and Windhoff
	var luxX = 237;  var luxY = 262;
	var windX = 255; var windY = 237;  

// Cities Array
var city = new Array();
var cityX = new Array();
var cityY = new Array();
var cityV = new Array();

city[0] ="arlon";          cityX[0] =231;  cityY[0] =236;  cityV[0] =0;
city[1] ="bastogne";       cityX[1] =202;  cityY[1] =137;  cityV[1] =0;
city[2] ="bertrix";        cityX[2] =119;  cityY[2] =190;  cityV[2] =0;
city[3] ="bettembourg";    cityX[3] =292;  cityY[3] =281;  cityV[3] =0;
city[4] ="bitburg";        cityX[4] =366;  cityY[4] =137;  cityV[4] =0;
city[5] ="brey";           cityX[5] =275;  cityY[5] =379;  cityV[5] =0;
city[6] ="clervaux";       cityX[6] =263;  cityY[6] =120;  cityV[6] =0;
city[7] ="daun";           cityX[7] =437;  cityY[7] =59;  cityV[7] =0;
city[8] ="diekirch";       cityX[8] =299;  cityY[8] =170;  cityV[8] =0;
city[9] ="dudelange";      cityX[9] =288;  cityY[9] =295;  cityV[9] =0;
city[10]="echternach";     cityX[10]=351;  cityY[10]=187;  cityV[10]=0;
city[11]="esch";           cityX[11]=265;  cityY[11]=291;  cityV[11]=0;
city[12]="ettelbruck";     cityX[12]=286;  cityY[12]=178;  cityV[12]=0;
city[13]="gouvy";          cityX[13]=243;  cityY[13]=81;  cityV[13]=0;
city[14]="grevenmacher";   cityX[14]=352;  cityY[14]=225;  cityV[14]=0;
city[15]="havange";        cityX[15]=281;  cityY[15]=338;  cityV[15]=0;
city[16]="konz";           cityX[16]=382;  cityY[16]=223;  cityV[16]=0;
city[17]="libramont";      cityX[17]=138;  cityY[17]=168;  cityV[17]=0;
city[18]="longwy";         cityX[18]=224;  cityY[18]=286;  cityV[18]=0;
city[19]="luxembourg";     cityX[19]=293;  cityY[19]=251;  cityV[19]=0;
city[20]="marche";         cityX[20]=128;  cityY[20]=71;  cityV[20]=0;
city[21]="mersch";         cityX[21]=293;  cityY[21]=208;  cityV[21]=0;
city[22]="merzig";         cityX[22]=399;  cityY[22]=299;  cityV[22]=0;
city[23]="metz";           cityX[23]=312;  cityY[23]=401;  cityV[23]=0;
city[24]="petange";        cityX[24]=241;  cityY[24]=274;  cityV[24]=0;
city[25]="pont";           cityX[25]=293;  cityY[25]=463;  cityV[25]=0;
city[26]="prum";           cityX[26]=341;  cityY[26]=68;  cityV[26]=0;
city[27]="remich";         cityX[27]=340;  cityY[27]=272;  cityV[27]=0;
city[28]="saarbrucken";    cityX[28]=474;  cityY[28]=353;  cityV[28]=0;
city[29]="saarburg";       cityX[29]=375;  cityY[29]=242;  cityV[29]=0;
city[30]="saarlouis";      cityX[30]=424;  cityY[30]=330;  cityV[30]=0;
city[31]="stavelot";       cityX[31]=240;  cityY[31]=10;  cityV[31]=0;
city[32]="stavold";        cityX[32]=422;  cityY[32]=394;  cityV[32]=0;
city[33]="stvith";         cityX[33]=282;  cityY[33]=46;  cityV[33]=0;
city[34]="thionville";     cityX[34]=307;  cityY[34]=330;  cityV[34]=0;
city[35]="trier";          cityX[35]=391;  cityY[35]=206;  cityV[35]=0;
city[36]="verdun";         cityX[36]=160;  cityY[36]=401;  cityV[36]=0;
city[37]="vianden";        cityX[37]=302;  cityY[37]=149;  cityV[37]=0;
city[38]="virton";         cityX[38]=177;  cityY[38]=275;  cityV[38]=0;
city[39]="wasserbillig";   cityX[39]=363;  cityY[39]=213;  cityV[39]=0;
city[40]="wittlich";       cityX[40]=432;  cityY[40]=135;  cityV[40]=0;

//digits array
var imgDigArr = new Array();
imgDigArr[0]  = new Image();  imgDigArr[0].src = "../img/0.gif";
imgDigArr[1]  = new Image();  imgDigArr[1].src = "../img/1.gif";
imgDigArr[2]  = new Image();  imgDigArr[2].src = "../img/2.gif";
imgDigArr[3]  = new Image();  imgDigArr[3].src = "../img/3.gif";
imgDigArr[4]  = new Image();  imgDigArr[4].src = "../img/4.gif";
imgDigArr[5]  = new Image();  imgDigArr[5].src = "../img/5.gif";
imgDigArr[6]  = new Image();  imgDigArr[6].src = "../img/6.gif";
imgDigArr[7]  = new Image();  imgDigArr[7].src = "../img/7.gif";
imgDigArr[8]  = new Image();  imgDigArr[8].src = "../img/8.gif";
imgDigArr[9]  = new Image();  imgDigArr[9].src = "../img/9.gif";
imgDigArr[10] = new Image();  imgDigArr[10].src = "../img/10.gif";


//
// Start of Standard Utility Functions
//
var isNav, isIE, isW3C;

if ((navigator.appName == "Netscape") && (navigator.appVersion.substring(0,3) < 5)) {
	isNav = true;     var layerRef = "document.layers[";      var styleSwitch = "]";
	isIE=false; 
	isW3C=false;
} else {
	if (navigator.appName.indexOf("Expl") != -1) {	
		isIE = true;      var layerRef = "document.all(";         var styleSwitch = ").style";
		isNav = false; 
		isW3C = false;
	} else {
		isW3C = true;	var layerRef = "document.getElementById("; var styleSwitch = ").style";
		isIE=false; 
		isNav=false;
	}
}

function getObject(obj) {

	var theObj;
	if (typeof obj == "string") {
		var theFString = layerRef  + '"' + obj + '"' + styleSwitch;
		theObj = new Object;
		theObj = eval(theFString);
	} else {
		theObj = obj;
	}
	return theObj;
}

function tric (theObj, toggle) {
	var sign = ((toggle)?"+":"-");
	var value = ((toggle)?"'visible'":"'hidden'");

	var toeval1 = "theObj.zIndex " + sign + "= '100';" ;
	var toeval2 = "theObj.visibility = " + value + ";" ;

	eval(toeval1); 
	eval(toeval2);
}

// Retrieving the x coordinate of a positionable object
function getObjectLeft(obj)  {
	var theObj = getObject(obj)
	if (isNav) {
		return theObj.left;
	} else {
		if (isIE) {
			return theObj.pixelLeft;
		} else {
			var theCoordinate = theObj.left;
			return parseInt(theCoordinate);
		}
	}
}

// Retrieving the y coordinate of a positionable object
function getObjectTop(obj)  {
	var theObj = getObject(obj)
	if (isNav) {
		return theObj.top;
	} else {
		if (isIE) {
			return theObj.pixelTop;
		} else {
			var theCoordinate = theObj.top;
			return parseInt(theCoordinate);
		}
	}
}

function showLayer(layerName) {
	var theObj = getObject(layerName);
	if (theObj) {
		if (isW3C) {
			theGlobalObj = theObj;
			setTimeout("tric(theGlobalObj, 1);", 80);
		} else {
			theObj.visibility = "visible";
		}
	}
}

function hideLayer(layerName) {
	
	var theObj = getObject(layerName);
	if (theObj) {
		if (isW3C) {			
			tric(theObj, 0);
		} else {
			theObj.visibility = "hidden";
		}
	}
}

function positionLayer(layerName, x, y) {
	var theObj = getObject(layerName);
	if (isNav) {
		theObj.moveToAbsolute(x,y);
	} else {
		if (isIE) {
			theObj.pixelLeft = x;
			theObj.pixelTop = y;
		} else {
			theObj.left = x + "px";
			theObj.top = y + "px";
		}
	}
}


function moveLayer(layerName, x, y) {
	if (isNav) {
		theObj.moveBy(x,y);
	} else {
		if (isIE) {
			theObj.pixelLeft += x;
			theObj.pixelTop += y;
		} else {
			theObj.left += x + "px";
			theObj.top += y + "px";
		}
	}
}


//
// End of Standard Utility Functions
//

//
// Start of Other Utility Functions
//

function distanceXY(x1,y1,x2,y2) {
	return Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
}

//
// End of Other Utility Functions
//

//
// MAIN PROGRAM
//


function init() {

	// initialise event capture in Netscape
	if (isNav) {
		document.captureEvents(Event.MOUSEMOVE);
	}
	
	// set mouse trap
	document.onmousemove = followcursor;

	//call proximitycheck - it's recursive and will repeat twice a second
	checkProximity();

	//call distancecheck - it's recursive and will repeat twice a second
	checkDistance();
	
}


function followcursor(evt) {

	// read mouse position	
	if (isNav) {
		mouseX = evt.pageX;
		mouseY = evt.pageY;
	} else {
		if (isIE) {
			mouseX = window.event.clientX + document.body.scrollLeft - 4;
			mouseY = window.event.clientY + document.body.scrollTop - 2;
		} else {
			//self.onerror = function () { return true; }
			//alert(evt.pageX.toString());
			mouseX = evt.pageX;
			mouseY = evt.pageY;
		}	
	}

	// set mouse position relative to map
	mapRelX = mouseX - mapShiftX;
	mapRelY = mouseY - mapShiftY;
	
	// move the crosshair
	// ELIMINATED TO MAKE THINGS FASTER
	// positionLayer('myFloatingLayer', mouseX - trackerOffsetX - trackerCenterX, mouseY - trackerOffsetY - trackerCenterY);

	//checkDistance();
	checkDistance_flag = 1;
	
	//checkProximity();
	checkProximity_flag = 1;
		
	return true;
}


function checkDistance() {

	if (checkDistance_flag == 1) {

	// DEBUG FUNCTION ***********************
	// indicate position
	//zabaza = getObjectTop("myLocationLayer");
	//zabaza = document.body.scrollTop;
	//updatePosition('xpos', zabaza, 3);
	//updatePosition('xpos', mouseX, 3);
	//updatePosition('ypos', mouseY, 3);	

	// distance to Luxembourg and Windhof
	distanceLux = mapMultiplier*distanceXY(mapRelX, mapRelY, luxX + trackerOffsetX, luxY + trackerOffsetY);
	updatePosition('lux', distanceLux, 3);		
	distanceWind = mapMultiplier*distanceXY(mapRelX, mapRelY, windX + trackerOffsetX, windY + trackerOffsetY);
	updatePosition('wind', distanceWind, 3);		

	checkDistance_flag = 0;
	
	}
	
	setTimeout("checkDistance();",150);

	return true;

}


//check whether any cities need to be shown
function checkProximity() {

	if (checkProximity_flag == 1) {
	
	for(count=0; count<city.length; count++) {
		if (distanceXY(mapRelX, mapRelY, cityX[count] + trackerOffsetX, cityY[count] + trackerOffsetY) < mapTrigger) {
			if (cityV[count] == 0) { cityV[count] = 1; showLayer(city[count]); }
		} else {
			if (cityV[count] == 1) { cityV[count] = 0; hideLayer(city[count]); }
		}
	}

	checkProximity_flag = 0;
	
	}
	
	setTimeout("checkProximity();",150);

	return true;
				
}



function updatePosition(imageName, inputNumber, imageDigits) {

	inputNumber = Math.floor(inputNumber);
	inputDigits = Math.floor(Math.log(inputNumber + 0.5)*Math.LOG10E) + 1;

	if ( (inputNumber < 0) || (inputDigits > imageDigits) ) {
		for(count = 0; count < imageDigits; count++) {		
			imageNameDigit = imageName + "_" + count;
			document.images[imageNameDigit].src = imgDigArr[10].src;
		}
	} else {
		inputNumber = inputNumber + "";
		for(count = 0; count < imageDigits; count++) {		
			imageNameDigit = imageName + "_" + count;
			currentdigit = 0;
			if (count < inputDigits) {
				//currentdigit = inputNumber.substr(- 1 - count, 1) - 0;  //fails in IE4
				currentdigit = inputNumber.substring(inputDigits-count-1,inputDigits-count);
			}
			document.images[imageNameDigit].src = imgDigArr[currentdigit].src;
		}
	}

	return true;
}

