CM.IMAGE_ROOT = cfgCentral + "/img";

function Bo(t,n,info,pos,ad,level) {
	this.t = t; // type
	this.n= n; // name
	this.info = info;
	this.pos = pos; // position
	this.ad = ad; // adresse
	this.level = level; // werbelevel
}

// clickbusiness
function ClB(id) {
//	map.setCenter(bl[id].pos,15);
//	disp(bl[id].n,bl[id].ad);
	window.location.href=bl[id].ad;
}

var icons = new Array();

for(var i=0; i<=11; i++) {
	var icn = new CM.Icon();
	icn.image = cfgCentral + "/ic/"+i+".png";
	icn.iconSize = new CM.Size(33,36);
	icn.iconAnchor = new CM.Point(16, 34);
	icons.push(icn);
}


var iconYou = new CM.Icon();
iconYou.image = cfgCentral + "/ic/youarehere.png";
iconYou.iconSize = new CM.Size(68, 75);
iconYou.iconAnchor = new CM.Point(0,0);

var iconWe = new CM.Icon();
iconWe.image = cfgCentral + "/ic/wearehere.png";
iconWe.iconSize = new CM.Size(60, 53);
iconWe.iconAnchor = new CM.Point(18,52);

function printlist(level) {
	var out = "";
	for (var i in bl) {
		if (bl[i].level == level) {
			if (out != "")
				out = out + ", ";
			  out = out +
			   '<a href="javascript:ClB('+i+')">'+ bl[i].n + '</a>';
		}
	}
	document.write(out);

}

function disp(head,detail) {
	document.getElementById('popup').display = true;
	document.getElementById('popuph').innerHTML = head;
	document.getElementById('popupi').innerHTML = detail;
}




// use geocode and show icons
function showIcons(icon_no,qry) {
	var geocoder = new CM.Geocoder('BC9A493B41014CAABB98F0471D759707');

	geocoder.getLocations(qry+' near Addis Ababa', function(response) {
	var southWest = new CM.LatLng(response.bounds[0][0], response.bounds[0][1]),
		northEast = new CM.LatLng(response.bounds[1][0], response.bounds[1][1]);
	
//		map.zoomToBounds(new CM.LatLngBounds(southWest, northEast));
		for (var i = 0; i < response.features.length; i++) {
			var coords = response.features[i].centroid.coordinates,
				latlng = new CM.LatLng(coords[0], coords[1]);
		putIcon(latlng, response.features[i].properties.name, icons[icon_no]);
//			var marker = new CM.Marker(latlng, {
//				title: response.features[i].properties.name
//			});
//			map.addOverlay(marker);
		}
	});

}

function mapinit(center,zoom) {


//	map = new CM.Map('md',{
//		rootUrl: cfgTiles ,
/*		subdomains: "abc",
		key: '675ed89b2b5155e38df42347df7f4454',
		styleId: 1,
		siteUrl: 'http://www.addismap.com',
		copyrightText : '<a href="#copyright">Copyright</a>'
	});
*/



  cloudmade = new CM.Tiles.CloudMade.Web({key: '675ed89b2b5155e38df42347df7f4454'});
	map = new CM.Map('md', cloudmade);


	map.setCenter(center, zoom);

	map.enableScrollWheelZoom();
	map.enableDoubleClickZoom();
	map.enableShiftDragZoom();
		
	var topLeft = new CM.ControlPosition(CM.ANCHOR_TOP_LEFT, new CM.Size(5,5));		
	map.addControl(new CM.SmallMapControl());
	map.addControl(new CM.ScaleControl());
	markersp(-1);
//	CM.addCustomEvent(map, 'zoomend', function() {
//		markers();
//		window.alert("You have zoomed the map to " + map.getZoom());
//	});


}

// which type is the "current one" ?

function markersp(type) {
	markerstype = type;
  markers(type);
}



function reset_markers(type) {
  markers(markerstype);
}



function putIcon(where,title,theIcon) {
        var marker;
        marker = new CM.Marker(where, {
                title: title,
                clickable: false,
                icon: theIcon
        })
        map.addOverlay(marker);
}

function putMarker(i) {

		marker = new CM.Marker(bl[i].pos, {
//			title: bl[i].n,  // kein tooltip
			clickable: true,
			icon: icons[bl[i].t]
		})
		map.addOverlay(marker);
		CM.Event.addListener(marker,"click",  new Function("","ClB("+i+")"));
// new cloudmade: customevent geht nicht mehr??
//		CM.addCustomEvent(marker,"click",  new Function("","ClB("+i+")"));

// hier geht auch was nicht mehr
//		if(CM.BrowserEngine.isIE) {
//		marker.element.onmouseover = new Function("" ,"fixedtooltip('<b>"+bl[i].n+"</b><br>"+bl[i].info+"', this, event, '150px')");
//		marker.element.onmouseout = delayhidetip;
//		} else {
//window.alert(marker);

//CM.DomEvent.addListener(marker, "onmouseover", "fixedtooltip('<b>"+bl[i].n+"</b><br>"+bl[i].info+"', this, event, '150px')");

		marker._image.setAttribute("onmouseover","fixedtooltip('<b>"+bl[i].n+"</b><br>"+bl[i].info+"', this, event, '150px')");
		marker._image.setAttribute("onmouseout","delayhidetip()");
//		}
}

function clear_markers() {
  if(typeof(map._overlays) != "undefined")
    while(map._overlays.length> 0) {
      map.removeOverlay(map._overlays[0]); 
	  }
}

function markers(type) {
  clear_markers();
	// add markers on the map
	for (var i in bl) {
		if (type == -1) {
			if (bl[i].level == "poi") continue;
		} else {
			if (bl[i].t != type) continue;
		}
		putMarker(i);
	}
}

function search(qry) {
	var answer = document.getElementById("answer");

	if (qry == "") {
		answer.innerHTML="";
		reset_markers();
		return;
  }

  var regex = new RegExp(".*"+qry+".*","i");
  clear_markers();

	var count = 0;
	for (var i in bl) {
    if ( regex.test(bl[i].n)) {
			putMarker(i);
			count++;
    }
	}



 answer.innerHTML=count+" places";

}




function switchlang(lang) {
 var tds = document.getElementsByTagName("span");
   for (var i=0;i<tds.length;i++) {
      if ( tds[i].className=="de" || tds[i].className=="am" || tds[i].className=="en" ) {
         if (lang == tds[i].className) {
				 tds[i].style.display="block";
				 } else {
				 tds[i].style.display="none";
					}
      }
   }
}


function activate(newactive) {
 var tds = document.getElementsByClassName("bizactive");
tds[0].className="biz";
newactive.className="bizactive";
}

// tooltip

/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth='350px' //default tooltip width
var tipbgcolor='lightyellow'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="-25x" //horizontal offset of tooltip from anchor link
var horizontal_offset="+39px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}
