var images = new Array("christian_schmidt", "rachel_schmidt", "rudolf_leopold", "maria_bader_kubizek", "livia_sellin", "manuel_hofer", "thomas_grandpierre", "stefan_dohr", "paul_gulda", "stephanie_grandpierre", "stephan_koncz", "thomas_selditz", "raphael_bell");

var map;
var gdir;
var geocoder = null;
var addressMarker;

function loadMap() {

  var garage_icon = new GIcon();
  garage_icon.image = "http://www.musikabendegraz.at/img/garage.gif";
  garage_icon.shadow = "";
  garage_icon.iconSize = new GSize(17, 17);
  garage_icon.shadowSize = new GSize(0, 0);
  garage_icon.iconAnchor = new GPoint(9, 9);
  garage_icon.infoWindowAnchor = new GPoint(9, 9);
  garage_icon.infoShadowAnchor = new GPoint(0, 0);

  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    map.enableContinuousZoom();
    map.enableDoubleClickZoom();
    map.addControl(new GLargeMapControl());
    gdir = new GDirections(map);
    GEvent.addListener(gdir, "error", handleErrors);
    point = new GLatLng(47.069581, 15.437636);
    map.setCenter(point, 15);
    //marker = new GMarker(point, def_icon);
    marker = new GMarker(point);
    map.addOverlay(marker);
    if (language == 'en') {
      marker.openInfoWindowHtml("<strong>Congress Graz</strong><br/><br/>Sparkassenplatz 1<br/>8010 Graz");
    } else {
      marker.openInfoWindowHtml("<strong>Grazer Congress</strong><br/><br/>Sparkassenplatz 1<br/>8010 Graz");
    }

    garage1 = new GMarker(new GLatLng(47.06919, 15.43613), garage_icon);
    map.addOverlay(garage1);
    GEvent.addListener(garage1, "click",
      function() {
    	if (language == 'en') {
    	  garage1.openInfoWindowHtml("<strong>Underground Parking<br/>Andreas Hofer Platz</strong><br/><br/>Mon-Sun 0-24h<br/>&euro; 4,00 per hour");
    	} else {
    	  garage1.openInfoWindowHtml("<strong>Tiefgarage<br/>Andreas Hofer Platz</strong><br/><br/>Mo-So 0-24h<br/>&euro; 4,00 pro Stunde");	
    	}
      }
    );
    garage2 = new GMarker(new GLatLng(47.06802, 15.43427), garage_icon);
    map.addOverlay(garage2);
    GEvent.addListener(garage2, "click",
      function() {
    	if (language == 'en') {
    	  garage2.openInfoWindowHtml("<strong>Citygarage Weitzer</strong><br/><br/>Mon-Sun 6-23h<br/>&euro; 1,50 per hour");
      	} else {
      	  garage2.openInfoWindowHtml("<strong>Citygarage Weitzer</strong><br/><br/>Mo-So 6-23h<br/>&euro; 1,50 pro Stunde");
      	}
      }
    );
    garage3 = new GMarker(new GLatLng(47.07164, 15.43580), garage_icon);
    map.addOverlay(garage3);
    GEvent.addListener(garage3, "click",
      function() {
    	if (language == 'en') {
    	  garage3.openInfoWindowHtml("<strong>Underground Parking<br/>Kastner&amp;&Ouml;hler</strong><br/><br/>Mon-Sun 0-24h<br/>&euro; 1,70 per 30 min.");
      	} else {
      	  garage3.openInfoWindowHtml("<strong>Tiefgarage<br/>Kastner&amp;&Ouml;hler</strong><br/><br/>Mo-So 0-24h<br/>&euro; 1,70 pro 30 Min.");
      	}
      }
    );
    garage4 = new GMarker(new GLatLng(47.07117, 15.43411), garage_icon);
    map.addOverlay(garage4);
    GEvent.addListener(garage4, "click",
      function() {
    	if (language == 'en') {
    	  garage4.openInfoWindowHtml("<strong>Underground Parking Kunsthaus</strong><br/><br/>Mon-Sun 0-24h<br/>&euro; 0,90 per 30 min.");
      	} else {
      	  garage4.openInfoWindowHtml("<strong>Tiefgarage Kunsthaus</strong><br/><br/>Mo-So 0-24h<br/>&euro; 0,90 pro 30 Min.");
      	}
      }
    );
  }
}

function toggleValues(field) {
	if (language == 'en') {
	  if (field.value == "Your Location (Str Nr ZIP Town)") field.value = "";
	  else if (field.value == '') field.value = 'Your Location (Str Nr ZIP Town)';
	} else {
 	  if (field.value == "Ihr Standort (Str Nr PLZ Ort)") field.value = "";
      else if (field.value == '') field.value = 'Ihr Standort (Str Nr PLZ Ort)';
	}
}

function setDirections(fromAddress) {
  toAddress = "Sparkassenplatz 1, 8010 Graz";
  locale = "de";
  map.clearOverlays();
  gdir.load("from: " + fromAddress + ", at to: " + toAddress, { "locale": locale });
}
function handleErrors(){
  if (language = 'en') {
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) 
      alert("The address you entered could not have been found.");
    else
      alert("Please enter a more precise address.");
  } else { 
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)  
	  alert("Die eingegebene Adrese konnte leider nicht gefunden werden.");
	else       
	  alert("Bitte geben Sie eine genauere Adresse ein.");
  }
}

function preloadImages()
{
  var sum = images.length;
  var loadedImages = new Array();
  for (i = 0; i < images.length; i++) {
    //loadedImages[i] = new Image();
    //loadedImages[i].src = "/img/musicians/"+images[i]+"_light.png";
    loadedImages[i] = new Image();
    loadedImages[i].src = "/img/musicians/"+images[i]+"_rgb.png";
  }
  return;
}

function switchImage(el)
{
  if (el.src.indexOf('rgb') > 0) {
    el.src = el.src.replace(/rgb/, "light");
    if(document.getElementById("a_"+el.id)) document.getElementById("a_"+el.id).style.textDecoration = "none";
  } else {
    if(document.getElementById("a_"+el.id)) document.getElementById("a_"+el.id).style.textDecoration = "underline";
    el.src = el.src.replace(/light/, "rgb");
  }
  return;
}

function showImage(el, musician)
{
  document.getElementById(el).src = "/img/musicians/"+musician+"_rgb.png";
  document.getElementById(el).style.display = "block";
  return;
}

function hideImage(el) 
{
  document.getElementById(el).style.display = "none";
  return;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
