addLoadEvent(function(){oZoom = new mapZoom()});
addLoadEvent(function(){buildMapSelect()});
addLoadEvent(function(){if(document.getElementById("prec")){
	document.getElementById("prec").onclick = function(){
		this.title = "opens is a new window";
		window.open(this.href);
		return false;
	};
}});
addLoadEvent(function(){if(document.getElementById("onlineLogin")){
	document.getElementById("onlineLogin").target = "_blank";
}});

addLoadEvent(function() {
	var oTitle = document.createElement("div");
	oTitle.id = "oTitle";
	document.body.appendChild(oTitle);
	oTitle = null;
	var aMaps = document.getElementsByTagName("area");
	for(var i=0; i<aMaps.length; i++){
		aMaps[i].sTitle = aMaps[i].title;
		aMaps[i].title = "";
		aMaps[i].alt = "";
		aMaps[i].onmouseover = function(e){
			document.getElementById("oTitle").innerHTML = this.sTitle;
			document.getElementById("oTitle").style.visibility = "visible";
			document.getElementById("oTitle").style.top = ((window.event)? parseInt(event.y):e.pageY ) + "px";
			document.getElementById("oTitle").style.left = ((window.event)? parseInt(event.x)+10:e.pageX + 10) + "px";
		};
		aMaps[i].onmouseout = function(){
			document.getElementById("oTitle").style.visibility = "hidden";
		};
	};
});

function mapZoom(){
	if(navigator.userAgent.toLowerCase().indexOf("safari") != -1){
		document.getElementById("originalmapImage").useMap = "#Map";
		return;
	};
	this.oTimer 	= null;
	this.oMoveTimer = null;
	var self 		= this;
	this.nZoom 		= 0;
	this.nPercent 	= 60;
	this.nDelay		= 20;
	this.nMoveDelay = 20;
	this.nStep 		= parseInt(this.nPercent / 20);
	document.getElementById("Map").setAttribute("name", "Map");
	this.sHTML 		= document.getElementById("originalmap").innerHTML;
	document.getElementById("Map").parentNode.removeChild(document.getElementById("Map"));
	
	var o = document.createElement("div");
	o.id = "zoommap";
	document.getElementById("wrapper").appendChild(o);
	o.innerHTML = this.sHTML;
	o.firstChild.id = "zoomimage";
	document.getElementById("zoomimage").useMap = "#Map";
	document.getElementById("zoomimage").style.left = "0";
	document.getElementById("zoomimage").style.top = "0";
	
	this.bOver = 0;
	this.nW = document.getElementById("zoomimage").offsetWidth;
	this.nH = document.getElementById("zoomimage").offsetHeight;
	
	window.onresize = 
	positionMap = function(){
		document.getElementById("zoommap").style.left 	= getPageOffsetLeft(document.getElementById("originalmap")) - 5 + "px";
		document.getElementById("zoommap").style.top 	= getPageOffsetTop(document.getElementById("originalmap")) + "px";
	};
	positionMap();
	
	document.getElementById("originalmap").style.visibility = "hidden";
	o = null;
	
	document.getElementById("zoommap").onmousemove = function(e){
		self.mousePosition(e);
	};
	document.getElementById("zoommap").onmouseover = function(){
		self.bOver = 1;
		self.zoom(1);
		self.mapPosition();
	};
	document.getElementById("zoommap").onmouseout = function(e){
		var oSrc = (window.event) ? event.toElement : e.relatedTarget;
		if(oSrc && oSrc.tagName != "IMG" && oSrc.tagName != "AREA"){
			self.zoom(0);
			self.bOver = 0;
		};
	};	
	
	this.zoom = function(bIn){
		clearTimeout(this.oTimer);
		if(bIn){
			if(this.nZoom < this.nPercent){
				this.nZoom += this.nStep;
				this.oTimer = setTimeout("oZoom.zoom(1)", this.nDelay);
			};
		}else{
			if(this.nZoom > 0){
				this.nZoom -= this.nStep;
				this.oTimer = setTimeout("oZoom.zoom(0)", this.nDelay);
			};
		};
		document.getElementById("zoomimage").style.width = this.nW * (100+this.nZoom)/100 + "px";
		document.getElementById("zoomimage").style.height = this.nH * (100+this.nZoom)/100 + "px";
		document.getElementById("zoommap").style.filter = "alpha(opacity=" + (80 + this.nZoom*2) + ")";
		document.getElementById("zoomimage").style.opacity = (80 + this.nZoom*2)/100;
	};
	
	this.mousePosition = function(e){
		this.nMouseX = ((window.event) ? event.x : e.pageX) - parseInt(document.getElementById("zoommap").style.left);
		this.nMouseY = ((window.event) ? event.y : e.pageY) - parseInt(document.getElementById("zoommap").style.top);
	};
	
	this.mapPosition = function(){
		clearTimeout(this.oMoveTimer);
		nTargetX = (this.bOver) ? ((this.nW/2 - this.nMouseX) *  this.nPercent * 2 / 100) : 0;
		nTargetY = (this.bOver) ? ((this.nH/2 - this.nMouseY) *  this.nPercent * 2 / 100) : 0;
		var nStepX = ((document.getElementById("zoomimage").offsetLeft) - nTargetX) / 10;
		var nStepY = ((document.getElementById("zoomimage").offsetTop) - nTargetY) / 10 ;
		document.getElementById("zoomimage").style.left = (parseInt(document.getElementById("zoomimage").offsetLeft) - nStepX) + "px";
		document.getElementById("zoomimage").style.top = (parseInt(document.getElementById("zoomimage").offsetTop) - nStepY) + "px";
		this.oMoveTimer = setTimeout("oZoom.mapPosition()", this.nMoveDelay);
	};
	
	var aCoords;
	var aAreas = document.getElementById("Map").getElementsByTagName("area");
	for(var i=0; i<aAreas.length; i++){
		aCoords = aAreas[i].coords.split(",");
		for(var j=0; j<aCoords.length; j++){
			aCoords[j] = parseInt(aCoords[j] * (100+this.nPercent) / 100);
		};
		aAreas[i].coords = aCoords.toString();
	};
};


document.write("<style>div#officeList{display:none}</style>");
function buildMapSelect(){
	var a = document.getElementById("officeList").getElementsByTagName("a");
	var s = "<label for=\"fOffice\">Contact an office</label>";
	s += "<select name=\"page\" id=\"fOffice\">";
	for(var i=0; i<a.length; i++){
		s += "<option value=\"" + a[i].href.split("page=")[1] + "\">" + a[i].firstChild.data + "</option>";
	};
	s += "</select>";
	s += "<input class=\"submit\" type=\"submit\" value=\"GO\" />";
	document.getElementById("officeList").innerHTML = s;
	document.getElementById("officeList").style.display = "block";
};


function getScrollAmount(){	
	if(!document.all) return 0;
	return document.documentElement.scrollTop || document.body.scrollTop;
} 
var ieBox = document.all && (document.compatMode == null || document.compatMode != "CSS1Compat");

function getInnerLeft(el) {
	if (el == null) return 0;
	if (ieBox && el == document.body || !ieBox && el == document.documentElement) return 0;
	return getPageOffsetLeft(el) //+ getBorderLeft(el);
};

function getPageOffsetLeft(el) {
	if (el == null) return 0;
	return el.offsetLeft + getInnerLeft(el.offsetParent);
};

function getInnerTop(el) {
	if (el == null) return 0;
	if (ieBox && el == document.body || !ieBox && el == document.documentElement) return 0;
	return getPageOffsetTop(el) //+ getBorderTop(el);
}

function getPageOffsetTop(el) {
	if (el == null) return 0;
	return el.offsetTop + getInnerTop(el.offsetParent);
};

function getBorderLeft(el) {
	return document.all ?
		el.clientLeft :
		parseInt(window.getComputedStyle(el, null).getPropertyValue("border-left-width"));
};

function getBorderTop(el) {
	return document.all ?
		el.clientTop :
		parseInt(window.getComputedStyle(el, null).getPropertyValue("border-top-width"));
};