var clipTop = 0;
var clipWidth = 427;
var clipBottom = 311;
var topper = 0;
var lyrheight = 311;
var time,amount,theTime,theHeight,DHTML;
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");

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 initScrolling()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj('scrollarea');
	if (document.layers)
	{
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if (document.getElementById || document.all)
	{
		lyrheight = x.obj.offsetHeight;
		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
	}
	if (window.addEventListener) {
	  window.addEventListener('DOMMouseScroll', wheel, false);
	}
	window.onmousewheel = document.onmousewheel = wheel;
}


function wheel(event)
{

var delta = 0;

if (!event)
{
event = window.event;
}

if (event.wheelDelta)
{
delta = event.wheelDelta/120;
if (window.opera)
{
delta = -delta;
}
}

else if (event.detail)
{
delta = -event.detail/3;
}

if (delta)
{
if (delta < 0)
{
scrollayer('scrollarea',10,100);
stopscroll();
scrollayer('scrollarea',10,100);
stopscroll();
}
else
{
scrollayer('scrollarea',-10,100);
stopscroll();
scrollayer('scrollarea',-10,100);
stopscroll();
}
}
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		if (clipTop < 0) {
		  document.getElementById("up_img").src = "/img/up_inactive.gif";
		} else if (clipBottom > lyrheight) {
		  document.getElementById("down_img").src = "/img/down_inactive.gif";
		}

	  clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}

	document.getElementById("up_img").src = "/img/up.gif";
	document.getElementById("down_img").src = "/img/down.gif";

	time = setTimeout('realscroll()',theTime);
}

function stopscroll()
{
	if (time) clearTimeout(time);
}

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];
  }
}
