// JavaScript Document


var	initGoogle = false;
var theMap;
var gmarkers;
var htmls;
var flashstatus;
var standorte;

window.onload = function () {
		init();
}

function init() {
	//googleMap wird geladen
	//alert(navigator.userAgent.indexOf("MSIE 6"));
	if(navigator.userAgent.indexOf("MSIE 6") > -1)return;
	theMap = document.getElementById("theMap");
	standorte = document.getElementById("standorte");
	standorte.innerHTML = '<img id="buttonstandorte" src="http://www.rosier.de/fileadmin/template/blank.gif" onclick="displayMap()" />'
}


function destroy() {
	//googleMap wird entladen
	GUnload();
}


// This function picks up the click and opens the corresponding info window
function myclick(i) {
	gmarkers[i].openInfoWindowHtml(htmls[i]);
	return false;
}


function mapIT() {
    if (GBrowserIsCompatible()) {
      // this variable will collect the html which will eventually be placed in the side_bar
      var side_bar_html = "";
    
      // arrays to hold copies of the markers and html used by the side_bar
      // because the function closure trick doesnt work there
      gmarkers = [];
      htmls = [];
      var i = 0;

      // This icon uses the same shape as the default Google marker
      // So we can use its details for everything except the image
      var rosierIcon = new GIcon();
      rosierIcon.image = "/fileadmin/template/r_ohne_schatten.png";
      rosierIcon.shadow = "/fileadmin/template/r_schatten.png";
      rosierIcon.iconSize = new GSize(20, 34);
      rosierIcon.shadowSize = new GSize(38, 34);
      rosierIcon.iconAnchor = new GPoint(10, 29);
      rosierIcon.infoWindowAnchor = new GPoint(15, 9);
      rosierIcon.infoShadowAnchor = new GPoint(24, 34);
      rosierIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";


      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point, rosierIcon);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        htmls[i] = html;
        // add a line to the side_bar html
        side_bar_html += '<a onclick="return myclick(' + i + ')" href="#">' + name + '</a> ';
        i++;
        return marker;
      }


      // create the map
      var map = new GMap2(document.getElementById("googleRosierMap"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(52.448478623663355, 9.14259765625), 7);


      // Read the data from example3.xml
      var request = GXmlHttp.create();
      //request.open("GET", "/fileadmin/google/rosier.xml", true);
      request.open("GET", "index.php?id=213", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = request.responseXML;
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // create the marker
            var marker = createMarker(point,label,html);
            map.addOverlay(marker);
          }
          // put the assembled side_bar_html contents into the side_bar div
          document.getElementById("googleRosierBar").innerHTML = side_bar_html;
        }
      }
      request.send(null);
    }

    else {
      alert("Google Maps API is not compatible with this browser");
    }
	initGoogle = true;
}

function openCKlasse () {
		open("http://formula-c.mercedes-benz.com/web/", "window", "width=1000, height=565");
}
function displayMap() {
	if(theMap.style.display != "block") {
		theMap.style.display = "block";
		//urchinTracker('/unserestandorte/googlemaps');
		if(!initGoogle)mapIT();
	}
	else {
		theMap.style.display = "none";
	}
}


function showCompany(id) {
		window.location.href = "http://www.rosier.de/index.php?id="+id;
}


function topFlash(s) {
	var flashstatus=s;
	var date = new Date();
	var time = 10; //date.getTime();
	//f�r die entwicklung bitte l�schen
	//time = 5;
	document.open();
	document.write('<object class="thebar" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1000" height="150">	<param name="movie" value="http://www.rosier.de/fileadmin/flash/topbar/_topbar_0000000015.swf?img='+flashstatus+'&time='+time+'"> <param name="wmode" value="transparent"> 	<param name="quality" value="high">	<param name="scale" value="noscale" />	<param name="salign" value="lt" />	<embed class="thebar" src="http://www.rosier.de/fileadmin/flash/topbar/_topbar_0000000015.swf?img='+flashstatus+'&time='+time+'" scale="noscale" salign="lt" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1000" height="150"  wmode="transparent"></embed></object>');
	document.close();
	
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  loc=selObj.options[selObj.selectedIndex].value;
  open(loc, "window", "width=900, height=700, scrollable=yes, resizable=yes, scrollbars=yes");
  if (restore) selObj.selectedIndex=0;
}