// Damit ein SyntaxHighlighting vorhanden ist
// <script type="text/javascript">

// Marker erzeugen
function AddPin(p){
	if(typeof(adressmarker[p.k])=='undefined'){
		adressmarker[p.k] = new GMarker(new GLatLng(p.b,p.l), {icon:eval(p.it), title:p.t});
		eval('GEvent.addListener(adressmarker["'+p.k+'"], "click", function() { open_marker("'+p.k+'","'+p.c+'"); });');
		if(p.it){
      map.addOverlay(adressmarker[p.k]);
      if(p.i!=0) adressmarker[p.k].setImage(p.i);
    }
	}
}

function AddOrt(p){
	if(typeof(ortmarker[p.k])=='undefined'){
		ortmarker[p.k] = new GMarker(new GLatLng(p.b,p.l), {icon:ort_big, title:p.t});
		eval('GEvent.addListener(ortmarker['+p.k+'], "click", function() { open_marker_ort("'+p.k+'"); });');
		map.addOverlay(ortmarker[p.k]);
	}
}

function AddContentID(p){
	if(typeof(contentmarker[p.k])=='undefined'){
		contentmarker[p.k] = new GMarker(new GLatLng(p.b,p.l), {icon:p.it, title:p.t});
		eval('GEvent.addListener(contentmarker['+p.k+'], "click", function() { open_marker_content("'+p.k+'"); });');
		map.addOverlay(contentmarker[p.k]);
	}
}

// HighlightPolyline
function HlPl(name, key, w, c, force){

  is_open = rc(map_id+"marker_open");
  if(is_open=='w'+key && !force){
    return false;
  }
  first = polylineKeys[key][0];
  last  = polylineKeys[key][1];
  for(i=first; i <= last; i++){
    eval(name+i+'.setStrokeStyle({weight: '+w+', color: \''+c+'\'});');
  }
}


// Funktion gibt den Query mit den aktuellen Grenzen zurueck
function bounds_query(as_str) {
	if(typeof(map)!='undefined'){
		var zoom = map.getZoom();
		var eckdaten = map.getBounds();
		var sw = eckdaten.getSouthWest();
		var ne = eckdaten.getNorthEast();
		
		var bounds = new Array;
		bounds['l_min'] = sw.x;
		bounds['l_max'] = ne.x;
		bounds['b_min'] = sw.y;
		bounds['b_max'] = ne.y;
		if(as_str==1) return 'lgrad_min='+bounds['l_min']+'&lgrad_max='+bounds['l_max']+'&bgrad_min='+bounds['b_min']+'&bgrad_max='+bounds['b_max']+'&zoom='+zoom;
		else return bounds;
	}else{
		return '';
	}
}

// Funktion die die aktuelle Kartenposition im Cookie speichert
function map_save_position() {
	sc(map_id+"zoom",map.getZoom());
	sc(map_id+"bgrad",map.getCenter().lat());
	sc(map_id+"lgrad",map.getCenter().lng());
	sc(map_id+"maptype",map.getCurrentMapType().getUrlArg());
	
	bounds = bounds_query(0);
	sc(map_id+"lgrad_min",bounds['l_min']);
	sc(map_id+"lgrad_max",bounds['l_max']);
	sc(map_id+"bgrad_min",bounds['b_min']);
	sc(map_id+"bgrad_max",bounds['b_max']);
}


// Oeffnet einen Marker
function open_marker(id,cluster,wait) {
	if(adressmarker[id] != undefined) {
		if(wait!=1 && wait!=2){ // falls wir auf das Fenster warten müssen
			// Fuer Media fixe Fenstergroeße
			if(id.substring(0,1)=='m'){
				width = 330;
				height = 270;
			}else{
				width = '350';
				height = '200';
			}
			map.openInfoWindowHtml(adressmarker[id].getPoint(),'<div id="openmarker" style="width:'+width+'px;height:'+height+'px;"><img src="/layout/loader.gif" alt="" /></div>');
			sc(map_id+"marker_open",id);
		}
		
		if(!get_element("openmarker")){
			setTimeout("open_marker('"+id+"','"+cluster+"','1');",200);
			return;
		}
		
		if(wait!=2){ // falls wir auf das Fenster warten müssen
			// Wegline entfernen
			for(var key in weglinie) map.removeOverlay(weglinie[key]);
			weglinie = new Array;
	
			// Weg-Linie anzeigen
			if(id.substring(0,1)=='w'){
        var weg_id = id.substring(1); 
        if(polylineKeys[weg_id] != undefined){
          HlPl("pPl", weg_id, 5, "#CC0000", true);
        }else{
          create_element('/timm/interaktive_karte/show_weg.php?id='+id+'&maps_id='+map_id+'&db='+db);
        }
			}
		}
		
		var query = gm_query();
		query = '&'+query;
		query += '&id='+id;
		query += '&cluster='+cluster;
		query += '&maps_id='+map_id;
		query += '&db='+db;
		
		if(typeof jQuery == "function"){
			$('#openmarker').load('/timm/interaktive_karte/ajax_show_marker.php', { postdata : query }, 
				function(){
					if(id.substring(0,1)=='m'){
						create_element('/timm/interaktive_karte/show_video.php?id='+id);
					}
				});
			
		}else{
			var ajax = createRequest();
			ajax.open('post','/timm/interaktive_karte/ajax_show_marker.php',true);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			ajax.send(query);
			
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(!get_element("openmarker")){
						setTimeout("open_marker('"+id+"','"+cluster+"','2');",200);
						return;
					}
					get_element("openmarker").innerHTML = ajax.responseText;
					// Video starten
					if(id.substring(0,1)=='m'){
						create_element('/timm/interaktive_karte/show_video.php?id='+id);
					}
				}
			};
		}
	}
}

function open_marker_2(id,gps_lgrad,gps_bgrad) {
	marker_found = 0;
  document.getElementById("map").scrollIntoView(true);
	for(var i in visible_marker){
		if(visible_marker[i].k==id || visible_marker[i].cluster.indexOf(id)>=0){
			open_marker(visible_marker[i].k,visible_marker[i].cluster);
			marker_found = 1;
			marker_to_open = 0;
			break;
		}
	}

	// Wenn der gesuchte Marker auserhalb der Anzeige ist
	if(!marker_found && gps_bgrad && gps_lgrad){
		marker_to_open = id;
		bounds = bounds_query(0);
		offset = (bounds['b_max']-bounds['b_min'])/4;
		map.closeInfoWindow();
		map.panTo(new GLatLng(gps_bgrad+offset,gps_lgrad));
	}
}


// Oeffnet eine Adresse
function open_adresse(id) {
	if(adresse[id] != undefined) {
		map.openInfoWindowHtml(adresse[id].getPoint(),'<div id="openmarker_small" style="width:250px;height:160px;"><img src="/layout/loader.gif" alt="" /></div>');
					
		if(typeof jQuery == "function"){
			$('#openmarker_small').load('/timm/interaktive_karte/ajax_show_adresse.php?id='+id, {});
		
		}else{
			var ajax = createRequest();
			ajax.open('get', '/timm/interaktive_karte/ajax_show_adresse.php?id='+id,true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					get_element("openmarker_small").innerHTML = ajax.responseText;
				}
			};
			ajax.send(null);
		}
	}
}

// Oeffnet einen Ort Marker
function open_marker_ort(id,wait){
	if(ortmarker[id] != undefined) {
    if(wait!=1){ // falls wir auf das Fenster warten müssen
      map.openInfoWindowHtml(ortmarker[id].getPoint(),'<div id="openmarker" style="width:350px;height:200px;"><img src="/layout/loader.gif" alt="" /></div>');
		}

    if(!get_element("openmarker")){
			setTimeout("open_marker_ort('"+id+"','1');",200);
			return;
		}

		if(typeof jQuery == "function"){
			$('#openmarker').load('/timm/interaktive_karte/ajax_show_ort.php?id='+id, {});
		
		}else{
			var ajax = createRequest();
			ajax.open('get', '/timm/interaktive_karte/ajax_show_ort.php?id='+id,true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					get_element("openmarker").innerHTML = ajax.responseText;
				}
			};
			ajax.send(null);
		}
	}
}

// Brauchen wir bei VE
function open_marker_ort_2(str){
	vars = str.split(',');
	open_marker_ort(vars[0]);
}

// Oeffnet einen Content Marker
function open_marker_content(id,wait){
	if(contentmarker[id] != undefined) {
    if(wait!=1){ // falls wir auf das Fenster warten müssen
      map.openInfoWindowHtml(contentmarker[id].getPoint(),'<div id="openmarker" style="width:350px;height:200px;"><img src="/layout/loader.gif" alt="" /></div>');
    }

    if(!get_element("openmarker")){
			setTimeout("open_marker_content('"+id+"','1');",200);
			return;
		}

		if(typeof jQuery == "function"){
			$('#openmarker').load('/timm/interaktive_karte/ajax_show_content.php?id='+id, {});

		}else{
			var ajax = createRequest();
			ajax.open('get', '/timm/interaktive_karte/ajax_show_content.php?id='+id,true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					get_element("openmarker").innerHTML = ajax.responseText;
				}
			};
			ajax.send(null);
		}
	}
}

// Loescht den Marker
function DelPin(p) {
  if(typeof(adressmarker[p.k])!='undefined'){
    map.removeOverlay(adressmarker[p.k]);
    delete adressmarker[p.k];
  }
}

// Loescht alle Marker und Linien von der Karte
function DelAllPins() {
	map.clearOverlays()
	adressmarker = new Array;
	weglinie = new Array;
}

function google_max(box_id) {

	var groesse    = BigImg.getPageSize();
	var scrollwert = BigImg.getScrollPosition();
	
	/*
	var objBody = document.getElementsByTagName("body").item(0);

	var Hintergrund = d.createElement("div");
	Hintergrund.setAttribute('id','MAP_Background');
	Hintergrund.style.position = 'absolute';
	Hintergrund.style.top = '0';
	Hintergrund.style.left = '0';
	Hintergrund.style.zIndex = '9999998';
	Hintergrund.style.width = '100%';
	Hintergrund.style.height = groesse[3]+'px';

	objBody.insertBefore(Hintergrund, objBody.firstChild);
	*/
	
	var e=get_element("write_google_maps_box_"+box_id);
	var map_div=get_element("map");
	var a=get_element("gm_ansichtsoptionen_1");
	
	var m_top = scrollwert-138;
	var m_left = -164;
	var m_width = groesse[2]-6-6-6-234-6-6;
	var m_height = groesse[3]-30;

	
	var a_top = m_top;
	var a_left = groesse[2]-6-234-234-6-526;
	var a_width = 234;
	
	a_css   = 'position:absolute;display:block;z-index:999999999;left:'+a_left+'px;top:'+a_top+'px;width:'+a_width+'px;';
	a.style.cssText = a_css;
	
	map_css = 'position:absolute;display:block;z-index:999999999;left:'+m_left+'px;top:'+m_top+'px;width:'+m_width+'px;height:'+m_height+'px;';
	map_div.style.cssText = map_css;

	map.size = new GSize(m_width,m_height);
	//alert(m.style.width);
	//alert(e.style.width);

}