/*
Datei: scriptmain.js
Datum: 27.01.2011
Autor: AOD-Media Inhaber Andre Friedrich
Beschreibung: stellt die Funktionen der Seite zur Verfuegung
*/
var svgueberblick, svgDoc, svgWin,svgRoot, rect;
var Width, Height,wd,ht;
var kachel_b = 200, kachel_h = 100;
var karte_b = 20000, karte_h = 20000;
var map_width, map_height;
var touren, akt_tour = null;
var ueb_width = 250, ueb_height = 265;
var zindex = 0.8;
var imgs = new Array();
var firstload = true;
var faktor = 80;
var panActive = false;
var cleanXY = false;
var vk,vb;
var bg_path = "../gfx/map/bg/";
var isIE = Prototype.Browser.IE;
var IEver = (isIE) ? parseFloat(navigator.appVersion.split("MSIE")[1]) : 99;
var scrollY;
var nId = null;
var myJsProgressBar;

if (!is_admin) var is_admin = false;
if (!tour_empf) var tour_empf = 0;
if (!weg_empf) var weg_empf = 0;
if (!anb_cx) var anb_cx = 0;
if (!newsId) var newsId = '';

window.onerror = function () {
 return true;
}

function initSVG() {
	if (IEver<7) alert('Ihr Browser scheint veraltet zu sein. Diese Webseite wird nur von aktuellen Browsern korrekt dargestellt, bitte aktualisieren Sie ihr System!');
	isSVG = (IEver<9) ? isSVGControlInstalled() : true;
if (isSVG==true) {
	if (!iframe||is_admin) svgueberblick = getSVG( "ueberblick" );
	svgDoc = getSVG( "map" );
	svgRoot = (isIE) ? $s('svgroot') : svgDoc.getElementsByTagName('svg')[0];
	svgWin = (isIE) ? svgDoc.parentWindow : svgDoc.defaultView;
	vb = getViewBox();
	map_height = $('kartenausschnitt').offsetHeight;
	map_width = $('kartenausschnitt').offsetWidth;
	if (!iframe || is_admin) initRect();

	if (tour_empf > 0 && !iframe) tour(tour_empf);
	if (weg_empf > 0 && !iframe) radwege(weg_empf);
	if (anb_cx != 0) {
		zentrieren(anb_cx,anb_cy,0);
		vis = svgDoc.createAttribute("style");
		vis.nodeValue = "visibility:visible";
		svgDoc.getElementById(anb_id).setAttributeNode(vis);
	}
	if (newsId != ''&& !iframe) {
		showNews(newsId[0],newsId[1],newsId[2],newsId[3],newsId[4]);
	}

	if (!iframe||is_admin) {
		preloader();
		svgDoc.getElementById("navi").setAttributeNS(null, "transform", eval('"translate('+vb[0]+','+vb[1]+') scale(0.7)"') );
	}
	if ( is_admin==true && !isIE ) Event.observe($s('karte'), 'click', newObject);
}
}

var step = 0;
function preloader() {
	if ( is_admin == true ) {
		firstload = false;
		ladeHintergrund();
		return;
	}
	x1 = Math.floor(vb[0]/kachel_b)*kachel_b;
	y1 = Math.floor(vb[1]/kachel_h)*kachel_h;
	anzX = Math.ceil(vb[2]/kachel_b) + 1;
	anzY = Math.ceil(vb[3]/kachel_h) + 1;
	if (is_admin) anzY += 3;
	var i = 0;
	for ( y=0; y<anzY; y++ ) {
		for ( x=0; x<anzX; x++ ) {
			bildx = Math.floor(x1 / kachel_b + x);
			bildy = Math.floor(y1 / kachel_h + y);
			imgs[i] = 'gfx/map/bg/' + bildy + "-" + bildx + ".png";
			i++;
		}
	}
    imgObjects(imgs);
}

function checkBrowserName(name){
   var agent = navigator.userAgent.toLowerCase();
   if (agent.indexOf(name.toLowerCase())>-1) {
     return true;
   }
   return false;
 }

function preloadIMG() {
	var arr = document.getElementsByTagName('img');
	//alert(arr[0].src);
	for (i=0; i<arr.length; i++) {
		imgs[i] = arr[i].src;
	}
	imgObjects(imgs);
}

var elements = 0;
function imgObjects(imgs2) {
	if(typeof imgs2 != 'object' || !imgs2.length) return;
	elements += imgs2.length;
	if (window.opera||checkBrowserName('safari')) step = 100/elements;
	else step = 50/elements;
	var img = new Array();
    for (i=0; i<elements; i++) {
        img[i] = new Image();
        img[i].onload = progress;
        img[i].onerror = progress;
        img[i].src = imgs2[i];
    }
}

var percent=0;
function progress() {
	if (isIE&&IEver<9&&percent==0) prepareIE('100%', 'hidden', 'hidden', 'none');
	percent += step;
	var p = Math.round(percent);
	if (p>100) p = 100;
	$("percentImage").style.backgroundPosition 	= "" + (-120 + 1.2 * p) + "px";
	$("percentText").update("" + p + "%");
    if(p>=95) {
		$('plOverlay').style.display = 'none';
		$('plContainer').style.display = 'none';
		$('Flash_Banner').style.visibility = 'visible';
		$('uebersicht').style.display = 'block';
		ladeHintergrund();
		if (isIE&&IEver<9) prepareIE('auto', 'auto', 'visible', 'block');
	}
}

function delay(prmSec) {
	prmSec *= 1000;

	var eDate = null;
	var eMsec = 0;

	var sDate = new Date();
	var sMsec = sDate.getTime();

	do {
		eDate = new Date();
		eMsec = eDate.getTime();

	} while ((eMsec-sMsec)<prmSec);
}


function $s(id) {
	return svgDoc.getElementById(id);
}

function showNews(nid,x,y,subj,txt) {
	zentrieren(x,y,1);
    vis = svgDoc.createAttribute("style");
    vis.nodeValue = "visibility:visible";
    nId = "news"+nid;
    var nIda = nId+'a';
    $s(nId).setAttributeNode(vis);
    Tip('<div>'+txt+'</div>',TITLE,subj,WIDTH,300,DURATION,30000, CLOSEBTN,true, FIX,calcNewsPos(x,y), STICKY,true, DELAY, 3000);
	return true;
}

function ladeHintergrund() {
	vb = getViewBox();
	x1 = Math.floor(vb[0]/kachel_b)*kachel_b;
	y1 = Math.floor(vb[1]/kachel_h)*kachel_h;
	anzX = Math.ceil(vb[2]/kachel_b) + 1;
	anzY = Math.ceil(vb[3]/kachel_h) + 1;
	if (is_admin) anzY += 3;
	i = 0;
	for ( y=0; y<anzY; y++ ) {
		ywert = y1 + y * kachel_h;
		for ( x=0; x<anzX; x++ ) {
			element = "k_" + x + "_" + y;
			kachel = $s(element);
			if (kachel) {
				xwert = (x1 + x * kachel_b)-0.5;
				kachel.setAttributeNS(null, "x",xwert + "px");
				kachel.setAttributeNS(null, "y",ywert + "px");
				/*if ( firstload == true ) {
					src = imgs[i];
					i++;
				}
				else {*/
					bildx = Math.floor(x1 / kachel_b + x);
					bildy = Math.floor(y1 / kachel_h + y);
					src = bg_path+bildy + "-" + bildx + ".png";
				//}
				kachel.setAttributeNS('http://www.w3.org/1999/xlink', "href", src);
			}
		}
	}
	if ( firstload == true ) firstload = false;
	//$s("blind").setAttributeNS(null, "x",x1 + "px");
	//$s("blind").setAttributeNS(null, "y",y1 + "px");
}

function initRect() {
	rect = svgueberblick.getElementById('pan_rect');
	pan_width = parseInt(map_width / 15);
	pan_height = parseInt(map_height / 15);
	rect.setAttributeNS(null, 'width', eval('"'+pan_width+'px"') );
	rect.setAttributeNS(null, 'height', eval('"'+pan_height+'px"') );
	setze_rechteck(vb[0],vb[1]);
}

function setze_rechteck( x, y ) {
	x = x / (karte_b/ueb_width);
	y = y / (karte_h/ueb_height);
	rect.setAttributeNS(null,"transform","translate(0)");
	rect.setAttributeNS(null, 'x', eval ( '"'+x+'"') );
	rect.setAttributeNS(null, 'y', eval ( '"'+y+'"') );
	cleanXY = true;
}

function zentrieren(cx,cy,set) {
	if (set==1) vb = getViewBox();
	vb[0] = Math.round( (cx - vb[2]/2)/kachel_b ) * kachel_b;
	vb[1] = Math.round( (cy - vb[3]/2)/kachel_h) * kachel_h;
	if (set==1) {
		setViewBox( vb[0], vb[1], vb[2], vb[3] );
		ladeHintergrund();
		if (!iframe) setze_rechteck( vb[0], vb[1] );
	}
	else {
		viewBoxneu = vb[0]+" "+vb[1]+" "+vb[2]+" "+vb[3];
		svgRoot.setAttributeNS(null, "viewBox",viewBoxneu);
	}
}

function pCoord(a,w,h) {
if (a=="x") return (isIE) ? Math.ceil(document.body.clientWidth/2 - w/2 + document.body.scrollLeft) : Math.ceil(window.innerWidth/2 - w/2 + window.pageXOffset);
else return (isIE) ? Math.ceil(document.body.clientHeight/2 + h/2 + document.body.scrollTop) : Math.ceil(window.innerHeight/2 + h/2 + window.pageYOffset);
}

function getSVG ( id ) {
var svgdoc = null;
var object = document.getElementById(id);
if (object != null) {
	if (object.contentDocument != null) {
		svgdoc = object.contentDocument;
		}
	else if (typeof object.getSVGDocument() != 'undefined') {
		svgdoc = object.getSVGDocument();
		}
	}
if ( navigator.appName.indexOf("Explorer") != -1 && IEver<9 && svgdoc == null )
	svgdoc = document.embeds[id].getSVGDocument();
return svgdoc;
}

// Ebenen ein- und ausblenden
function ebene( id ) {
eb = $s( eval('"E'+id+'"') );
el = "ebene"+id;
if ( eb.style.getPropertyValue('visibility') == "visible" ) {
	eb.setAttributeNS(null, 'style', 'visibility:hidden');
	document.symbol.elements[el].checked = false;
	}
else {
	eb.setAttributeNS(null, 'style', 'visibility:visible');
	document.symbol.elements[el].checked = true;
	}
}

function getViewBox() {
	viewb = new String(svgRoot.getAttribute("viewBox"));
	v = viewb.split(' ');
	return new Array( parseInt(v[0]), parseInt(v[1]), parseInt(v[2]), parseInt(v[3]) );
}

function setViewBox( x, y, w, h ) {
	x = Math.floor( x / kachel_b ) * kachel_b;
	y = Math.floor( y / kachel_h ) * kachel_h;
	//if (w/h<1.4) h = w* 1.4;
	viewBoxneu = x + " " + y + " " + w + " " + h;
	svgRoot.setAttributeNS(null, "viewBox",viewBoxneu);
	scale = 0.58 * (2-zindex);
	$s("navi").setAttributeNS(null,  "transform", eval('"translate('+x+','+y+') scale('+scale+')"') );
}

function verschiebe(dir) {
vb = getViewBox();
var x = vb[0];
var y = vb[1];
breite = kachel_b;// * (2-zindex);
hoehe = kachel_h;// * (2-zindex);

switch (dir) {
	case "links": x = x - breite; break;
	case "rechts": x = x + breite; break;
	case "oben": y = y - hoehe; break;
	case "unten": y = y + hoehe; break;
	}
if ( (dir == "links" && vb[0] > 0) || (dir == "oben" && vb[1] > 0) || (dir == "rechts" && vb[0] < 20000) || (dir == "unten" && vb[1] < 20000) ) {
	setViewBox(x,y,vb[2],vb[3]);
	ladeHintergrund();
	setze_rechteck(x,y);
	}
}

// Klick auf Uebersichtskarte waehlt Kartenausschnitt
function pansprung(Event) {
if ( panActive == false ) {
	vb = getViewBox();
	posx = document.all ? window.event.clientX : Event.pageX;
	posy = document.all ? window.event.clientY : Event.pageY;
	rect_width = parseInt(rect.getAttribute("width").match( /\d+/ ));
	rect_height = parseInt(rect.getAttribute("height").match( /\d+/ ));
	rect_x = posx - rect_width / 2;
	rect_y = posy - rect_height / 2;

	x_max = ueb_width - rect_width;
	y_max = ueb_height - rect_height;
	if ( rect_x < 0 ) rect_x = 0;
	if ( rect_y < 0 ) rect_y = 0;
	if ( rect_x > x_max ) rect_x = x_max;
	if ( rect_y > y_max ) rect_y = y_max;

	x_neu = parseInt( (rect_x * (karte_b / ueb_width)/kachel_b) ) * kachel_b;
	y_neu = parseInt( (rect_y * (karte_h / ueb_height)/kachel_h) ) * kachel_h;

	setViewBox( x_neu, y_neu, vb[2], vb[3] );
	ladeHintergrund();
	setze_rechteck( x_neu, y_neu );
	}
}

function pansprung2(transX,transY) {
	var cx=null,cy=null;
if ( panActive == true ) {
	vb = getViewBox();
	rect_x = Math.round(rect.getAttribute("x").match( /\d+/ ))+transX;
	rect_y = Math.round(rect.getAttribute("y").match( /\d+/ ))+transY;

	x_neu = Math.round( ( rect_x * faktor ) / kachel_b) * kachel_b;
	y_neu = Math.round( ( rect_y * faktor ) / kachel_h) * kachel_h;

	setViewBox( x_neu, y_neu, vb[2], vb[3] );
	ladeHintergrund();
	x = x_neu / faktor - transX;
	y = y_neu / faktor - transY;
	rect.setAttributeNS(null, 'x', eval ( '"'+x+'"') );
	rect.setAttributeNS(null, 'y', eval ( '"'+y+'"') );
	}
}

function tour(t_id) {
	if (hideAltTours==true&&tour_alt!=null) {
		hideTour(tour_alt);
		tour_alt = null;
		hideAltTours=false;
	}
	if (t_id!=undefined && t_id>0) tour_id = eval("'tour"+t_id+"'");
	else if (document.forms['routeplaner']) tour_id = document.forms['routeplaner'].elements['route'].value;

ort_id = document.forms[1].elements['ort'].value;
if (ort_id!='null'&&ort_id!=undefined&&ort_id!=null) {
	o_id = ort_id.match( /\d+/ );
	cx = parseInt(ort_x[o_id]);
	cy = parseInt(ort_y[o_id]);
}

if ( is_admin == true ) {
	clearInfo();
	$('tour_btn').style.display = 'block';
	$('wege_btn').style.display = 'none';
	document.forms['routeplaner'].elements['wege'].value = 'null';
}

if ( tour_id==null || !tour_id || tour_id==undefined || tour_id=='null' ) {
	if ( is_admin == true ) {
		$('tour_btn').style.display = 'none';
	}
	else {
		if ( akt_tour != null ) {
			showTour(akt_tour);
			akt_tour = null;
		}
	}
}
else {
	showTour(tour_id,0);
	akt_tour = tour_id;
	if (t_id==undefined) t_id = String(tour_id).match( /\d+/ );
	cx = parseInt(tour_x[t_id]);
	cy = parseInt(tour_y[t_id]);
	if ( is_admin == false ) {
		writeTourInfos(t_id);
		if (t_id>0) tour_stats(t_id);
	}
	if (tour_alt&&tour_alt!=null) {
		hideAltTours = true;
		showTour(tour_alt,1);
	}
}
if (cx!=null&&cy!=null) zentrieren(cx,cy,1);
}

function showTour(id,alt) {
	if (!String(id).match(/tour/)) id = eval("'tour"+id+"'");
	if ($s(id)) {
		$s(id).style.setProperty('stroke', (alt==1?'#0f5205':'#ff0000'), '');
		$s(id).style.setProperty('visibility', 'visible', '');
		if (alt==0) {
			start = id+'_start';
			ziel = id+'_ziel';
			if ( $s(start) != null ) $s(start).style.setProperty('visibility', 'visible', '');
			if ( $s(ziel) != null ) $s(ziel).style.setProperty('visibility', 'visible', '');
		}
		if ( akt_tour != null && alt==0 ) {
			hideTour(akt_tour);
		}
	}
}

function showAltTour(id) {
	tid = eval("'tour"+id+"'");
	if (tour_alt!=null) {
		str = $('aPDF').href;
		neu = '&a='+id;
		$('aPDF').href = str.replace(/&a=\d+/,neu);
		hideTour(tour_alt);
	}
	else $('aPDF').href = $('aPDF').href+'&atour='+id;
	showTour(tid,1);
	tour_alt = id;
	hideAltTours = true;
}

var hideAltTours = false;
var tour_alt = null;
function hideTour(id) {
	if (!String(id).match(/tour/)) id = eval("'tour"+id+"'");
	$s(id).style.setProperty('visibility', 'hidden', '');
	start = id+'_start';
	ziel = id+'_ziel';
	if ( $s(start) != null ) $s(start).style.setProperty('visibility', 'hidden', '');
	if ( $s(ziel) != null ) $s(ziel).style.setProperty('visibility', 'hidden', '');
}

var tourLB = null;
var anschl = null;
var akarte = null;
function writeTourInfos(t_id) {
	var jetzt = new Date();
	$('aTourinfo').href = URL_ROOT+'inc/tourBeschr.php?tour='+t_id;
	$('aTourinfo').className = "lbOn";
	setActiveStyleSheet('tour');
	if (tourLB==null) tourLB = new lightbox($('aTourinfo'));
	else tourLB.content = URL_ROOT+'inc/tourBeschr.php?tour='+t_id;
	$('aAnschl').href = URL_ROOT+'inc/altTour.php?tour='+t_id;
	$('aEmpf').href = URL_ROOT+'empfehlung.php?tour='+t_id;
	$('aEmpf').className = "lb";
	$('aPDF').href = URL_ROOT+'pdf.php?tour='+t_id;
	$('aPDF').className = "lb";
	$('aFacebook').href = 'http://www.facebook.com/sharer.php?u='+URL_ROOT+'index.php%3Ftour='+t_id+'%26fb=1';
	$('aFacebook').className = "lb";
	new Ajax.Request('inc/tourInfos.php', {
			method:'get',
			parameters: {tour: t_id,t: jetzt.getTime()},
			onSuccess: function(transport){
				var data = eval('(' +transport.responseText + ')');
				$('hErklaerung').innerHTML = data.titel;
				$('erklaerung').innerHTML = data.beschr;
				if (data.alt==1) {
					$('aAnschl').className = "lbOn"
					if (anschl==null) anschl = new lightbox($('aAnschl'));
					else anschl.content = URL_ROOT+'inc/altTour.php?tour='+t_id;
				}
				else {
					$('aAnschl').className = "none";
					$('aAnschl').href = "";
				}
				if (data.map==1) {
					$('aKarte').href = URL_ROOT+'inc/maps.php?tour='+t_id;
					$('aKarte').className = "lbOn";
					if (akarte==null) akarte = new lightbox($('aKarte'));
					else akarte.content = URL_ROOT+'inc/maps.php?tour='+t_id;
				}
				else {
					$('aKarte').className = "none";
					$('aKarte').href = "";
				}
			}
	});
}


function lokalInfo( table, id ) {
	open( eval('"../../info.php?tab='+table+'&id='+id+'"') ,"Informationen","dependent=yes,scrollbars=yes,directories=no,location=no,menubar=no,resizable=yes,status=no,toolbar=no,width=500,height=420,screenX=300,screenY=200");
}

function getInfos(art,id) {
	new Ajax.Request('inc/getInfos.php', {
		method:'get',
		parameters: {art: art, id: id},
		onSuccess: function(transport,art){
			wd=350; ht=250;
			m = String(transport.responseText).match(/title="(.*)"/);
			title = m[1] ? m[1] : '';
			Tip(transport.responseText, TITLE,title, SHADOW,true, CLOSEBTN,true, STICKY,true, FIX,[pCoord('x',wd,ht),pCoord('y',wd,ht)], DURATION,0);
		}
	});
}

var myLightbox;
function showSight(table,id) {
	setActiveStyleSheet('mini');
	var a = $('infoContainer');
	a.href = eval('"'+URL_ROOT+'inc/sight.php?tab='+table+'&id='+id+'"');
	myLightbox = new lightbox(a);
	$('dummyBtn').click();
	sym_stats(id,'vi');
}

function showGallery(id) {
	setActiveStyleSheet('galerie');
	var a = $('infoContainer');
	a.href = eval('"'+URL_ROOT+'gallery.php?id='+id+'"');
	myLightbox = new lightbox(a);
	$('dummyBtn').click();
	sym_stats(id,'ga');
}

function showVideo(id) {
	sheet = isIE?'video_ie':'video';
	setActiveStyleSheet(sheet);
	var a = $('infoContainer');
	a.href = eval('"'+URL_ROOT+'inc/video.php?id='+id+'"');
	myLightbox = new lightbox(a);
	$('dummyBtn').click();
	sym_stats(id,'vi');
}

function tour_stats(id) {
	new Ajax.Request('inc/tourStats.php', { method:'get', parameters: {tour: id} });
}

function weg_stats(id) {
	new Ajax.Request('inc/wegStats.php', { method:'get', parameters: {weg: id} });
}

function sym_stats(id,tab) {
	new Ajax.Request('inc/symStat.php', { method:'get', parameters: {id: id,tab: tab} });
}

function delay(prmSec) {
  prmSec *= 1000;
  var eDate = null;
  var eMsec = 0;
  var sDate = new Date();
  var sMsec = sDate.getTime();

  do {
      eDate = new Date();
      eMsec = eDate.getTime();

  } while ((eMsec-sMsec)<prmSec);
}

function calcNewsPos(symX,symY) {
	vb = getViewBox();
	divX = $('kartenausschnitt').offsetLeft;
	divY = $('kartenausschnitt').offsetTop;
	x = divX + symX - vb[0] +50;
	y = divY - $('map').height + symY - vb[1];
	return new Array('kartenausschnitt',x,y);
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function deactivateLB() {
	$('overlay').style.display = 'none';
	$('lightbox').style.display = 'none';
	Element.remove($('lbContent'));
	delete lightbox;
	if (isIE){
		setScroll(0,scrollY);
		prepareIE("auto", "auto", "visible", 'block');
	}
}

function getScroll() {
	if (self.pageYOffset) {
		scrollY = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		scrollY = document.documentElement.scrollTop;
	} else if (document.body) {
		scrollY = document.body.scrollTop;
	}
}

function setScroll(x, y){
	window.scrollTo(x, y);
}

function prepareIE(height, overflow, visibility, display){
	bod = document.getElementsByTagName('body')[0];
	bod.style.height = height;
	bod.style.overflow = overflow;
	selects = document.getElementsByTagName('select');
	for(i = 0; i < selects.length; i++) {
		selects[i].style.visibility = visibility;
	}
	$('Flash_Banner').style.visibility = visibility;
	$('uebersicht').style.display = display;
}

function hideNews() {
	if (nId!=null) $s(nId).style.setProperty('visibility', 'hidden', '');
}

function radwege(id) {
	weg = $s( eval('"weg'+id+'"') );
	el = "weg"+id;
	start = el+'_start';
	ziel = el+'_ziel';
	if ( weg.style.getPropertyValue('visibility') == "visible" ) {
		weg.setAttributeNS(null, 'style', 'visibility:hidden');
		document.symbol.elements[el].checked = false;
		$('aKarte').className = "none";
		$('aTourinfo').href = "";
		$('aTourinfo').className = "none";
		$('aPDF').href = "";
		$('aPDF').className = "none";
		$('aFacebook').className = "none";
		$('aFacebook').href = "";
		$('aEmpf').className = "none";
		$('aEmpf').href = "";
		if ( $s(start) != null ) $s(start).style.setProperty('visibility', 'hidden', '');
		if ( $s(ziel) != null ) $s(ziel).style.setProperty('visibility', 'hidden', '');
	}
	else {
		if (is_admin==false) weg_stats(id);
		weg.setAttributeNS(null, 'style', 'visibility:visible');
		if (document.symbol.elements[el]) document.symbol.elements[el].checked = true;
		if ( $s(start) != null ) $s(start).style.setProperty('visibility', 'visible', '');
		if ( $s(ziel) != null ) $s(ziel).style.setProperty('visibility', 'visible', '');
		var jetzt = new Date();
		$('aTourinfo').href = URL_ROOT+'inc/tourBeschr.php?weg='+id;
		$('aTourinfo').className = "lbOn";
		setActiveStyleSheet('tour');
		if (tourLB==null) tourLB = new lightbox($('aTourinfo'));
		else tourLB.content = URL_ROOT+'inc/tourBeschr.php?weg='+id;
		$('aAnschl').href = "";
		$('aAnschl').className = "none";
		$('aEmpf').href = URL_ROOT+'empfehlung.php?weg='+id;
		$('aEmpf').className = "lb";
		$('aPDF').href = 'http://www.spreekapitaen.de/fileserver.php?id='+id;
		$('aPDF').className = "lb";
		$('aFacebook').href = 'http://www.facebook.com/sharer.php?u='+URL_ROOT+'index.php%3Fweg='+id+'%26fb=1';
		$('aFacebook').className = "lb";
		new Ajax.Request('inc/tourInfos.php', {
				method:'get',
				parameters: {weg: id,t: jetzt.getTime()},
				onSuccess: function(transport){
					var data = eval('(' +transport.responseText + ')');
					if (data.map==1) {
						$('aKarte').href = URL_ROOT+'inc/maps.php?weg='+id;
						$('aKarte').className = "lbOn";
						if (akarte==null) akarte = new lightbox($('aKarte'));
						else akarte.content = URL_ROOT+'inc/maps.php?weg='+id;
					}
					else {
						$('aKarte').className = "none";
						$('aKarte').href = "";
					}
				}
		});
		//if (weg_empf=0||id!=empf_weg)
		wegZentrieren(id);
	}
}

function wegZentrieren(id) {
	vb = getViewBox();
	Mx = parseInt(vb[0]+vb[2]/2);
	My = parseInt(vb[1]+vb[3]/2);
	new Ajax.Request('inc/pathDistance.php', {
				method:'get',
				parameters: {id: id,Mx:Mx,My:My},
				onSuccess: function(transport){
					var data = eval('(' +transport.responseText + ')');
					//alert(transport.responseText);
					zentrieren(data.minX,data.minY,true);
				}
		});

	/*weg = $s( eval('"weg'+id+'"') );
	pfade = weg.getElementsByTagNameNS('http://www.w3.org/2000/svg','path');
	var dmin = 100000;
	var Xmin=0;
	var Ymin=0;
	vb = getViewBox();
	Mx = parseInt(vb[0]+vb[2]/2);
	My = parseInt(vb[1]+vb[3]/2);
	for (i=0; i<pfade.length; i++) {
		for (j=0; j<parseInt(pfade[i].getTotalLength()); j+=50) {
			x = pfade[i].getPointAtLength(j).x;
			y = pfade[i].getPointAtLength(j).y;
			d = Math.sqrt( Math.pow(Mx-x,2) + Math.pow(My-y,2) );
			if (d<dmin) {
				dmin = d;
				Xmin = x;
				Ymin = y;
			}
		}
	}
	if (Xmin>0&&Ymin>0) zentrieren(Xmin,Ymin,true);*/
}

