var map;
var tour_buttons_enabled = false;

function scrollMeTo(elem) {
//  ss.smoothScrollJS(elem);
}

function t1() {
    tabs1.first();
}

function t2() {
    tabs2.first();
}

function enable_tour_buttons() {
    document.getElementById("pbInfos0").style.color = "#324159";
    document.getElementById("pbInfos").style.color = "#324159";
    document.getElementById("pbInfos0").style.cursor = "pointer";

    document.getElementById("pbService0").style.color = "#324159";
    document.getElementById("pbService").style.color = "#324159";
    document.getElementById("pbService0").style.cursor = "pointer";

    document.getElementById("pbGallery0").style.color = "#324159";
    document.getElementById("pbGallery").style.color = "#324159";
    document.getElementById("pbGallery0").style.cursor = "pointer";

    tour_buttons_enabled = true;
}

function toggleServices() {
  if(tour_buttons_enabled){
    if($("service").style.display=="") {
        $('gmap').style.visibility = "hidden";
        map.removeControl(typeCo);
//      beforeStart: function(o){scrollMeTo('stage');},
        Effect.BlindUp('service',{duration: 0.6, afterFinish: t1, queue: { position: "end", scope: "pageButtons" }});
        Element.setInnerHTML('pbService','Wetter, Karten &amp; GPS-Daten');
    } else {
        Effect.BlindDown('service',{duration: 0.6, afterFinish: initMap, queue: { position: "end", scope: "pageButtons" }});
        Element.setInnerHTML('pbService','- ausblenden -');
    }
  }
}

function toggleGallery() {
  if(tour_buttons_enabled){
    if($("gallery").style.display=="") {
        Effect.BlindUp('gallery',{duration: 1, beforeStart: function(o){scrollMeTo('stage');}, afterFinish: t2, queue: { position: "end", scope: "pageButtons" }});
        Element.setInnerHTML('pbGallery','Bilder, Videos &amp; Audio');
    } else {
        Effect.BlindDown('gallery',{duration: 1, queue: { position: "end", scope: "pageButtons" }});
        Element.setInnerHTML('pbGallery','- ausblenden -');
    }
  }
}

function blindDownMap() {
    window.setTimeout("blindDownMap1()", 1000);
}

function setMarkers() {
    var bounds = new GLatLngBounds();
    var image;
    if (GoogleCoords0 && GoogleCoords1) image = new Array("/de/huetten/gmapper/tourStart.png",50,64);
    else image = new Array("/de/wLayout/design/img/1px.gif",1,1);
    var point = new GLatLng(GoogleCoords0,GoogleCoords1);
    var marker = createMapMarker(point, image);
    map.addOverlay(marker);
    bounds.extend(point);
}

function initMap() {
    if(map==undefined) {
        initMapOnStart();
        setMarkers();
        //$('gmap').style.visibility = "visible";
    } else {
        map.checkResize();
        map.addControl(typeCo);
        setMarkers();
        map.setCenter(new GLatLng(GoogleCoords0,GoogleCoords1), 10);
    }
}

function LoadGPXFileIntoGoogleMap(map, filename) {
    // Remove any existing overlays from the map.
    map.clearOverlays();
    var request = GXmlHttp.create();
    request.open("GET", filename, true);
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
            parser = new GPXParser(request.responseXML, map);
            parser.SetTrackColour("#ff0000");                               // Set the track line colour
            parser.SetTrackWidth(2);                                        // Set the track line width
            parser.SetMinTrackPointDelta(0.001);                            // Set the minimum distance between track points
            var maptype = G_CYCLE_MAP;
            parser.CenterAndZoom(request.responseXML, maptype, 0);          // Center and Zoom the map over all the points.
            parser.AddTrackpointsToMap();                                   // Add the trackpoints
            parser.AddWaypointsToMap();                                     // Add the waypoints
            setMarkers();
        }
    }
    request.send(null);
}

function initMapOnStart() {
    if (GBrowserIsCompatible()) { 
		var copycycle1 = "&copy; Cloudmade: ";
		var copycycle2 = "<a href='http://www.cloudmade.com' target='_blank'>";
        var cycle = [new GTileLayer()];
		  
		  cycle[0].getTileUrl = function(a,b) {
		  return "http://tile.opencyclemap.org/cycle/" + b + "/" + a.x + "/" + a.y + ".png"; };
		  //return "http://andy.sandbox.cloudmade.com/tiles/cycle/" + b + "/" + a.x + "/" + a.y + ".png"; };
		  cycle[0].getCopyright = function(a,b) {
		  return {prefix:copycycle1, copyrightTexts:[copycycle2]}; }
		
		map = new GMap2($("gmap"), {mapTypes: [G_PHYSICAL_MAP,G_NORMAL_MAP,G_HYBRID_MAP,G_SATELLITE_MAP]});
		map.addOverlay(new GLayer("com.google.webcams"));
		//map.addControl(new GOverviewMapControl());
		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GScaleControl());
		map.disableScrollWheelZoom();    
    	map.setCenter(new GLatLng(0, 0), 0, G_HYBRID_MAP); 
    	map.enableDoubleClickZoom();
        typeCo = new GMapTypeControl();
        map.addControl(typeCo);
        scaleCo = new GScaleControl()
        map.addControl(scaleCo);
        largeCo = new GLargeMapControl();
        map.addControl(largeCo);
        map.setCenter(new GLatLng(GoogleCoords0,GoogleCoords1), 10);
        new GKeyboardHandler(map);
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        
		
		//var bounds = new GLatLngBounds();
		G_CYCLE_MAP = new GMapType(cycle, G_SATELLITE_MAP.getProjection(), "Map", {
		shortName: "Cycle-Map", alt: "",
		minResolution:0,maxResolution:27});
		map.setMapType(G_CYCLE_MAP);
		map.addMapType(G_CYCLE_MAP);
		if(!gpx.empty()) LoadGPXFileIntoGoogleMap(map, gpx);
    }
}

function bg(str) {
    if(str==1) {
        $('navMain').style.backgroundPosition = "left -47px";
        $('navSubShadow').style.visibility = "visible";
    } else {
        $('navMain').style.backgroundPosition = "left top";
        $('navSubShadow').style.visibility = "hidden";
    }
}


function toggleContentDesc(myElem,txtOff,txtOn) {
    myToggle = myElem;
    myLink = myElem+'Link';
    if($(myToggle).style.display == 'none'){
        new Effect.BlindDown(myToggle,{duration: 0.7, queue: { position: "end", scope: "myQueueToggle" }});
        Element.setInnerHTML(myLink,txtOn);
    } else {
        new Effect.BlindUp(myToggle,{duration: 0.7, queue: { position: "end", scope: "myQueueToggle" }});
        Element.setInnerHTML(myLink,txtOff);
    }
}

function toggleContent(myElem) {
    myToggle = myElem;
    if($(myToggle).style.display == 'none'){
        new Effect.BlindDown(myToggle,{duration: 0.7, queue: { position: "end", scope: "myQueueToggle" }});
    } else {
        new Effect.BlindUp(myToggle,{duration: 0.7, queue: { position: "end", scope: "myQueueToggle" }});
    }
}

function toggleContentMap(myElem) {
    myToggle = myElem;
    if($(myToggle).style.display == 'none'){
        new Effect.BlindDown(myToggle,{duration: 0.7, afterFinish: function(o){mapMe(1);}, queue: { position: "end", scope: "myQueueToggle" }});
    } else {
        new Effect.BlindUp(myToggle,{duration: 0.7, beforeStart: function(o){mapMe(0);},queue: { position: "end", scope: "myQueueToggle" }});
    }
}

function mapMe(stat) {
    if(stat==0) {
        $('gmap').style.visibility = "hidden";
    } else {
        map.checkResize();
        map.setCenter(new GLatLng(GoogleCoords0,GoogleCoords1), 10);
        $('gmap').style.visibility = "visible";
    }
}

FastInit.addOnLoad(initMapOnStart,tabs);

var upTab, downTab;

function tabs() {
    tabs1 = new Control.Tabs($('serviceTabs'),{
        animation: true,
        animationType: 'blind',
        animationDuration: '0.5'
    });
    tabs2 = new Control.Tabs($('galleryTabs'),{
        animation: true,
        animationType: 'blind',
        animationDuration: '0.5'
    });
}

//function showResponse (originalRequest) {
//    var newData = originalRequest.responseText;
//    $('testW').innerHTML = newData;
//    alert(newData);
//    return false;
//}
 
