

/**
 * image slide soest
 *
 * Marc Schieferdecker, Citkomm Services GmbH
 */
var autoSwitchSeconds = 5;
var topImageCount = 4;
var atImage = 1;
var lastImage = 1;
var effect_running = false;
var targetCoordX = 0;
var targetCoordY = 0;
var sourceCoordX = 0;
var sourceCoordY = 0;
var userClickedRotator = false;
Event.observe(window, 'load', function() {
	if( topImageCount > 1 )
	{
		if( $('topimage1') )
		{
			targetCoordX = parseInt( $('topimage1').getStyle( 'left' ) );
			targetCoordY = parseInt( $('topimage1').getStyle( 'top' ) );
			sourceCoordX = targetCoordX + parseInt( $('topimage1').getWidth() );
			sourceCoordY = targetCoordY;
			for( var i = 2; i <= topImageCount; i++ )
			{
				$('topimage'+i).removeClassName('hide');
				if( $('topimage'+i) )
				{
					$('topimage'+i).hide();
					$('topimage'+i).setStyle( {left:sourceCoordX+'px', top:sourceCoordY+'px'} );
				}
			}
			if( autoSwitchSeconds )
				setTimeout( imagerotator, autoSwitchSeconds * 1000 );
		}
	}
});
function choose_image( num, userclick )
{
	if( num != atImage && effect_running == false )
	{
		if( userclick )
			userClickedRotator = true;
		effect_running = true;
		lastImage = atImage;
		if( $('topimage'+num) )
		{
			atImage = num;
			$('topimage'+lastImage).setStyle( {zIndex:80} );
			$('topimage'+lastImage).fade( {duration:1.5} );

			$('topimage'+num).setStyle( {zIndex:100} );
			new Effect.Move('topimage'+num, { x: targetCoordX, y: targetCoordY, mode: 'absolute', duration:1.2, transition:Effect.Transitions.sinoidal });
			$('topimage'+num).appear( {duration:1.2, afterFinish:function() {
				for( var i = 1; i <= topImageCount; i++ )
				{
					if( i != atImage )
					{
						$('topimage'+i).setStyle( {zIndex:10} );
						$('topimage'+i).hide();
						$('topimage'+i).setStyle( {left:sourceCoordX+'px', top:sourceCoordY+'px'} );
						$('topimage'+i+'button').removeClassName('active');
					}
				}
				$('topimage'+num+'button').addClassName('active');
				effect_running = false;
			}
			});
		}
	}
}
function imagerotator() {
	if( userClickedRotator == false )
	{
		if( atImage == topImageCount )
			choose_image( 1, false );
		else
			choose_image( atImage + 1, false );
		if( autoSwitchSeconds )
			setTimeout( imagerotator, autoSwitchSeconds * 1000 );
	}
}

/**
 * Social media links
 */
function goto_fratzenbuch()
{
	site_title = document.title;
	site_url = location.href;
	mywindow = window.open('http://www.facebook.de/sharer.php?u=' + escape( site_url ) + '&t=' + escape( site_title ), 'Facebook', 'width=700,height=600,left=100,top=200' );
	mywindow.focus();
}
function goto_twitter()
{
	var site_title = document.title;
	var site_url = location.href;
	var params = { status: site_title + ': ' + site_url };
	mywindow = window.open('https://twitter.com/timeline/home/?status=' + escape( 'Ich lese: "' + site_title + '" - ' + site_url ), 'Twitter', 'width=1000,height=600,left=100,top=200');
	mywindow.focus();
}
function goto_rss()
{
	location.href = '/aktuelles/?rss=1';
}

/**
 * GoogleMaps integration
 */
var counter = 0;
var points = [];
var markers = [];
var marker_html = [];
var zooms = [];
var to_htmls = [];
var from_htmls = [];
var icon = Array();
var map = null;

var baseIcon = new GIcon();
baseIcon.iconSize=new GSize(32,32);
baseIcon.shadowSize=new GSize(56,32);
baseIcon.iconAnchor=new GPoint(16,32);
baseIcon.infoWindowAnchor=new GPoint(16,0);

icon[10] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon2.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon2s.png");
icon[20] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon3.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon3s.png");
icon[30] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon21.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon21s.png");
icon[40] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon48.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon48s.png");
icon[50] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon50.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon50s.png");
icon[60] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon32.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon32s.png");
icon[70] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon19.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon19s.png");
icon[80] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon18.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon18s.png");
icon[90] = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon55.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon55s.png");

function createMarker(point, title, html, n, zoom, url) {

	var marker = new GMarker(point, icon[n]);

	to_htmls[counter] = html;
	to_htmls[counter] += '<form class="gmapDir" id="gmapDirTo" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">';
	to_htmls[counter] += '<p class="gmapDirHead" id="gmapDirHeadTo">Wegbeschreibung:<br/><strong>Hierher</strong> - <a href="javascript:fromhere(' + counter + ')">Von hier aus</a></p>';
	to_htmls[counter] += '<p class="gmapDirItem" id="gmapDirItemTo"><label for="gmapDirSaddr" class="gmapDirLabel" id="gmapDirLabelTo">Start-Adresse:<br /></label><input type="text" size="40" maxlength="40" name="saddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" /></p>';
	to_htmls[counter] += '<p class="gmapDirBtns" id="gmapDirBtnsTo"><input value="Wegbeschreibung anzeigen" type="submit" class="gmapDirButton" id="gmapDirButtonTo" /></p>';
	to_htmls[counter] += '<input type="hidden" name="daddr" value="' + point.y + ', ' + point.x + '(' + title + ')' + '" /></form>';

	from_htmls[counter] = html;
	from_htmls[counter] += '<form class="gmapDir" id="gmapDirFrom" style="white-space: nowrap;" action="http://maps.google.com/maps" method="get" target="_blank">';
	from_htmls[counter] += '<p class="gmapDirHead" id="gmapDirHeadFrom">Wegbeschreibung:<br/><a href="javascript:tohere(' + counter + ')">Hierher</a> - <strong>Von hier aus</strong></p>';
	from_htmls[counter] += '<p class="gmapDirItem" id="gmapDirItemFrom"><label for="gmapDirDaddr" class="gmapDirLabel" id="gmapDirLabelFrom">Ziel-Adresse:<br /></label><input type="text" size="40" maxlength="40" name="daddr" class="gmapTextBox" id="gmapDirSaddr" value="" onfocus="this.style.backgroundColor = \'#e0e0e0\';" onblur="this.style.backgroundColor = \'#ffffff\';" /></p>';
	from_htmls[counter] += '<p class="gmapDirBtns" id="gmapDirBtnsFrom"><input value="Wegbeschreibung anzeigen" type="submit" class="gmapDirButton" id="gmapDirButtonFrom" /></p>';
	from_htmls[counter] += '<input type="hidden" name="saddr" value="' + point.y + ',' + point.x + '(' + title + ')' + '" /></form>';

	if( url )
		html += '<br/><a href="' + url + '">Mehr Informationen aufrufen</a><br/>';
	html += '<br /><div id="gmapDirHead" class="gmapDir" style="white-space: nowrap;">Wegbeschreibung:<br/><a href="javascript:tohere(' + counter + ')">Hierher</a> - <a href="javascript:fromhere(' + counter + ')">Von hier aus</a></div>';
	GEvent.addListener(marker, "click", function() { map.centerAndZoom(point, zoom); marker.openInfoWindowHtml(html); });

	points[counter] = point;
	markers[counter] = marker;
	marker_html[counter] = html;
	zooms[counter] = zoom;
	counter++;

	return marker;
}

function click_sidebar(idx) {
	markers[idx].openInfoWindowHtml(marker_html[idx]);
}

function showInfoWindow(idx,html) {
	map.centerAndZoom(points[idx], zooms[idx]);
	//map.centerAtLatLng(points[idx]);
	markers[idx].openInfoWindowHtml(html);
}

function tohere(idx) {
	markers[idx].openInfoWindowHtml(to_htmls[idx]);
}

function fromhere(idx) {
	markers[idx].openInfoWindowHtml(from_htmls[idx]);
}

/* Alte Funktionen (email de/crypt) */
function decryptCharcode(n,start,end,offset)	{

	n = n + offset;

	if (offset > 0 && n > end)	{

		n = start + (n - end - 1);

	} else if (offset < 0 && n < start)	{

		n = end - (start - n - 1);

	}

	return String.fromCharCode(n);

}

function decryptString(enc,offset)	{

	var dec = "";

	var len = enc.length;

	for(var i=0; i < len; i++)	{

		var n = enc.charCodeAt(i);

		if (n >= 0x2B && n <= 0x3A)	{

			dec += decryptCharcode(n,0x2B,0x3A,offset);	// 0-9 . , - + / :

		} else if (n >= 0x40 && n <= 0x5A)	{

			dec += decryptCharcode(n,0x40,0x5A,offset);	// A-Z @

		} else if (n >= 0x61 && n <= 0x7A)	{

			dec += decryptCharcode(n,0x61,0x7A,offset);	// a-z

		} else {

			dec += enc.charAt(i);

		}

	}

	return dec;

}

function linkTo_UnCryptMailto(s)	{

	location.href = 'mailto:'+decryptString(s,-1);

}

function printMail(s) {
	document.write(decryptString(s,-1));
}

