function attachEventListener(target, eventType, functionRef, capture) {
  if (typeof target.addEventListener != "undefined") {
    target.addEventListener(eventType, functionRef, capture);
  } else if (typeof target.attachEvent != "undefined") {
    target.attachEvent("on" + eventType, functionRef);
  } else {
    eventType = "on" + eventType;
    if (typeof target[eventType] == "function") {
      var oldListener = target[eventType];
      target[eventType] = function(){oldListener();return functionRef();};
    } else {
      target[eventType] = functionRef;
    }
  }
  return true;
}
function getScrollingPosition() {
  var position = [0, 0];
  if(typeof window.pageYOffset != 'undefined') {
    position = [window.pageXOffset,window.pageYOffset];
  }
  if(typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
    position = [document.documentElement.scrollLeft,document.documentElement.scrollTop];
  }
  else if(typeof document.body.scrollTop != 'undefined') {
    position = [document.body.scrollLeft,document.body.scrollTop];
  }
  return position;
}
function initMap(){
	var mapVars = function() {
		var normmap;
		var pic;
		var mapImg;
		var areas = null;
		var flagDiv = null;
	}
	var flagFollow = function(event) {
		var event = (typeof event != "undefined")?event:window.event;
		var scrollingPosition = getScrollingPosition();
		var cursorPosition = [0, 0];

		if (typeof event.pageX != "undefined" && typeof event.x != "undefined") {
			cursorPosition[0] = event.pageX;
			cursorPosition[1] = event.pageY;
		} else {
			cursorPosition[0] = event.clientX + scrollingPosition[0];
			cursorPosition[1] = event.clientY + scrollingPosition[1];
		}
		mapVars.flagDiv.style.left = cursorPosition[0] - Math.floor(mapVars.flagDiv.offsetWidth/2) + "px";
		mapVars.flagDiv.style.top = cursorPosition[1] - 25 + "px";
		mapVars.flagDiv.style.display = "block";
		return true;
	}
	function MakeMapListener(i,alt) {
		attachEventListener(mapVars.areas[i], "mouseover", function(){mapVars.mapImg.src=mapVars.pic[i].src;mapVars.flagDiv.innerHTML = alt;mapVars.areas[i].onmousemove = flagFollow;}, false);
		attachEventListener(mapVars.areas[i], "mouseout", function(){mapVars.mapImg.src=mapVars.normmap;mapVars.flagDiv.style.display="none";}, false);
	}
	var init = function() {
		var flag = document.createElement("div");
		flag.setAttribute("id", "rollover");
		document.getElementById("mapDiv").appendChild(flag);
		mapVars.mapImg = document.getElementById('mapImg');
		mapVars.flagDiv = flag;
		mapVars.normmap = mapVars.mapImg.src;
		mapVars.areas = document.getElementById('map').getElementsByTagName('area');
		mapVars.pic = [];
		for(var i=0;i < mapVars.areas.length;i++) {
			mapVars.pic[i] = new Image();
			mapVars.pic[i].src = mapVars.normmap.substring(0,mapVars.normmap.lastIndexOf("/")+1) + mapVars.areas[i].alt.replace(/ /g,"_").toLowerCase() + '_over.gif';			
			MakeMapListener(i,mapVars.areas[i].alt);
			mapVars.areas[i].removeAttribute("title");
			mapVars.areas[i].removeAttribute("alt");
		}

		var country_selecter=document.getElementById("country_select");
		if(country_selecter){
			attachEventListener(country_selecter, "change", function(){if(country_selecter.options[country_selecter.selectedIndex].value != ''){document.location.href=country_selecter.options[country_selecter.selectedIndex].value;return false;}}, false);
		}
		var region_selecter=document.getElementById("region_select");
		if(region_selecter){
			attachEventListener(region_selecter, "change", function(){if(region_selecter.options[region_selecter.selectedIndex].value != ''){document.location.href=region_selecter.options[region_selecter.selectedIndex].value;return false;}}, false);
		}
	}
	init();
}
addDOMLoadEvent(initMap);
