function map_initMap(){
	map_initRegions();
	map_initIcons();
}
function map_initRegions(){
	
}
function map_initIcons(){
	var iconsholder = $('MapIconsHolder');
	var imgs = iconsholder.getElementsByTagName('IMG');
	var img;
	for(var i=0;i<imgs.length;i++){
		img = imgs[i];
		img.width = 56;
		img.height = 57;
		img.style.left = 1*(img.offsetLeft - Math.round(img.width/2)) + 'px';
		img.style.top = 1*(img.offsetTop - Math.round(img.width/2)) + 'px';
		newX = img.offsetLeft + Math.round((img.width-21)/2);
		newY = img.offsetTop + Math.round((img.height-21)/2);
		img.sx = newX;
		img.sy = newY;
		img.bx = img.offsetLeft;
		img.by = img.offsetTop;
		img.w = img.width;
		img.h = img.height;
		img.style.left = newX+'px';
		img.style.top = newY+'px';
		img.width = 21;
		img.height = 21;
		img.src = '/uploads/map/fiblogo_gray_small.gif';
		img.onmouseover = function (){map_popupIcon(this.id);};
		img.onmouseout = function (){map_popoutIcon(this.id);};
		img.onclick = function(){map_clickIcon(this.id);};
		img.OnTransformEnd = function(img){map_afterIconPop(img)};
		/*
		timeout = Math.round(Math.random()*1);
		time = 100 + Math.round(Math.random()*800);
		setTimeout("map_popoutIcon('"+img.id+"', "+time+");",timeout);
		*/
	}
}
function map_popupIcon(imgID, time){
	var img=$(imgID);
	if(img.selected){
		map_showCity(img);
		return;
	}
	img.popUp = true;
	if(!time) time=100;
	transGeoPos(img.id, '!', img.bx, '!', img.by, '!', img.w, '!', img.h,time);
}
function map_popoutIcon(imgID, time){
	var img=$(imgID);
	if(img.selected){
		 map_hideCity(img);
		 return;
	}
	img.popUp=false;
	div = $('MapCityHolder');
	div.style.display = 'none';
	if(!time) time=100;
	transGeoPos(img.id, '!', img.sx, '!', img.sy, '!', 21, '!', 21,time);
}
function map_clickIcon(imgID){
	var img = $(imgID);
	if(!img.selected){
		var cimg = $('MapIconsHolder').CurrentIcon;
		if(cimg){
			cimg.selected = false
			cimg.src = '/uploads/map/fiblogo_gray.gif';
			cimg.popUpOut = true;
			map_popupIcon(cimg.id);
		}
		img.src='/uploads/map/fiblogo.gif';
		map_popoutIcon(imgID);
		img.selected = true;
		$('MapIconsHolder').CurrentIcon = img;
		if(typeof(map_afterIconClick)=='function'){map_afterIconClick(imgID)}
		
	}else{
		img.selected = false;
		img.src='/uploads/map/fiblogo_gray.gif';
		map_popupIcon(imgID);
	}
}
function map_afterIconPop(img){
	if(img.popUp){
		if(img.selected) img.src='/uploads/map/fiblogo.gif';
		else img.src = '/uploads/map/fiblogo_gray.gif';
		if(img.popUpOut){
			img.popUpOut = false;
			map_popoutIcon(img.id);
		}else{
			map_showCity(img);
		}
	}else{
		if(img.selected) img.src='/uploads/map/fiblogo_small.gif';
		else img.src='/uploads/map/fiblogo_gray_small.gif';
	}
}
function map_showCity(aboveImg){
	var div = $('MapCityHolder');
	div.innerHTML = aboveImg.getAttribute('City');
	div.style.display = 'block';
	div.style.left = (aboveImg.offsetLeft - Math.round((div.offsetWidth-aboveImg.width)/2))*1 + 'px';
	div.style.top = (aboveImg.offsetTop + aboveImg.height)*1 + 'px';
}
function map_hideCity(){
	var div = $('MapCityHolder');
	div.style.display = 'none';
}
function map_showRegion(regID){
	var reg = $(regID);
	var map = $('BgMap');
	map_hideRegion(map.activeRegion);
	if(!reg) return;
	map.activeRegion = regID;
	reg.style.display = "block";
	
}
function map_hideRegion(regID){
	var reg = $(regID);
	if(!reg) return;
	reg.style.display = "none";
}
function map_clickRegion(regID){
	if(typeof(map_afterRegionClick)=='function'){map_afterRegionClick(regID)}	
}
function map_changeIndicatorState(show){

}
