$(document).ready(function() {

		$('.pagination').children('ul').css({
			'marginLeft':(($('.pagination').children('ul').width()/2)*(-1))-50+'px'
		});
		
		setInterval(function() {
			$('.pagination').children('ul').css({
				'marginLeft':(($('.pagination').children('ul').width()/2)*(-1))-50+'px'
			});
		}, 350);
		
		$('#core-login-name').live('click', function() {
				if($(this).val() == 'Benutzername') $(this).val('');
		});

		$('#core-login-pass').live('click', function() {
				if($(this).val() == 'Passwort') $(this).val('');
		});

		// Mainmenu
		/*$('li[id*="mm-item"]').hover(
  function() {
  	if($(this).attr('class').search(/active/) == -1) {
	  	$(this).children().stop()
	  		   .animate({'color':'#fff'}, 600, 'easeOutCubic').parent()
					 .animate({'backgroundColor':'#9bbc00'}, 400, 'easeOutCubic');
	}
  },
  function() {
  	if($(this).attr('class').search(/active/) == -1) {
	  	$(this).children().stop()
	  		   .animate({'color':'#9bbc00'}, 600, 'easeOutCubic').parent()
					 .animate({'backgroundColor':'#fff'}, 400, 'easeOutCubic');
  	}
  });
  
  // Submenu
  $('li[id*="sm-item"]').data('hover', false)

  $('li[id*="sm-item"]').hover(
  function() {
  	if($(this).attr('class').search(/active/) == -1) {
	  	$(this).children().stop()
	  		   .animate({'color':'#6d8126'}, 400, 'easeOutCubic');
	  		
	}
  },
  function() {
  	if($(this).attr('class').search(/active/) == -1) {
	  	$(this).children().stop()
	  		   .animate({'color':'#fff'}, 400, 'easeOutCubic');
  	}
  });*/
  
		// Metamenu
		$('li[id*="am-item"]').hover(
				function() {
						if($(this).attr('class').search(/active/) == -1) {
								$(this).stop()
						//.animate({'paddingLeft':'15px','backgroundPosition':'4px 7px'}, 800, 'easeOutCubic')
						//.children('a').stop().animate({'color':'#9e1622'}, 500);
						}
				},
				function() {
						if($(this).attr('class').search(/active/) == -1) {
								$(this).stop()
						//.animate({'paddingLeft':'0px','backgroundPosition':'-11px 7px'}, 800, 'easeOutCubic')
						//.children('a').stop().animate({'color':'#999'}, 500);
						}
				});

		if($('.core-textarea').val() == 'Bei Fragen und Bemerkungen, bitte hier Ihren Text eingeben ...')
		{
				$('.core-textarea').val('Bei Fragen und Bemerkungen, bitte hier Ihren Text eingeben ...').css({
						'color':'#9bbc00',
						'font-style':'italic'
				});
		}

		$('.core-textarea').focus(function() {
				if($(this).val() == 'Bei Fragen und Bemerkungen, bitte hier Ihren Text eingeben ...')
				{
						$(this).val('').css({
								'color':'#646566',
								'font-style':'normal'
						});
				}
				$('#coaching8').attr('checked', true);
		});
		// Weiterlesen-Buttons
		$('.readmore').hover(
				function() {
						$(this).animate({
								'width':'85px'
						}, 800, 'easeOutCubic');
				},
				function() {
						$(this).animate({
								'width':'65px'
						}, 800, 'easeOutCubic');
				});

		slide_width = $('#imageslide-container').children('ul').width();
		if(slide_width > 350)
		{
				count = 0;
				loop_count = Math.round(2000/slide_width);
				speed = Math.round(50*slide_width);
				for($i=1;$i<=loop_count;$i++)
				{
						$('#imageslide-container').children('ul').append($('#imageslide-container').children('ul').html().replace(/Saunaparadies_slideshow/g,'Saunaparadies_slideshow'+count));
						if($i==loop_count)
						{
								ani = setInterval("animateSlideshow()", speed);
								animateSlideshow();
						}
				}
				$('#imageslide').children('div').children('ul').children('li').hover(function() {
						margin = $(this).parent().css('marginLeft');
						$(this).parent().stop().css('marginLeft',margin);
						$(this).parent().children('li').stop().animate({
								'opacity':'0.4'
						},500);
						$(this).stop().animate({
								'opacity':'1'
						},300);
						clearInterval(ani);
				},function() {
						$(this).parent().children('li').stop().animate({
								'opacity':'1'
						},500);
						speed = speed*(1-((parseFloat($('#imageslide-container').children('ul').css('marginLeft').replace(/px/g,''))*(-1))/slide_width));
						animateSlideshow();
						speed = Math.round(60000/slide_width)*slide_width;
				});

				$('#imageslide').children('div').children('ul').children('li').live('click', function() {
						clearInterval(ani);
				});
		}

		Shadowbox.init({
				handleOversize: "drag",
				modal: false,
				overlayColor: "#fff",
				overlayOpacity: 0.20
		});

		if($('.map_open').length > 0)
		{
				$('#map_textlink').click(function() {
						Shadowbox.open({
								content:    "",
								player:			"html",
								title:      "Sauna Paradies Wettenberg - Anfahrt",
								height:     550,
								width:      750,
								options: {
										onFinish: function()
										{
												if (GBrowserIsCompatible()) {
														var map = new GMap2(document.getElementById(Shadowbox.playerId));
														map.setCenter(new GLatLng(50.6105, 8.643), 12);

														var blueIcon = new GIcon(G_DEFAULT_ICON);
														blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";

														// Marker
														marker = new GMarker(new GLatLng(50.6105, 8.643), {
																icon:blueIcon
														});
														map.addOverlay(marker);

														// Infofenster mit Routenberechnung
														marker.openRouteInfoWindow = getRouteInfoWindow;
														// Hier die Adresse des Markers eintragen
														marker.openRouteInfoWindow_targetName = "Am Augarten 5, 35435 Wettenberg";
														// Hier HTML eintragen, das oben im InfoFenster erscheinen soll.
														marker.openRouteInfoWindow_html = "<div class='googlemap-logo'></div>";
														// Infofenster �ffnen
														marker.openRouteInfoWindow();
														// Nach einem Klick auf Schlie�en kann man das Infofenster mit einem Klick auf den Marker wieder �ffnen
														GEvent.addListener(marker, "click", function()
														{
																marker.openRouteInfoWindow();
														});
												}
										}
								}
						});
				});
				$('.map_open').click(function() {
						Shadowbox.open({
								content:    "",
								player:			"html",
								title:      "Sauna Paradies Wettenberg - Anfahrt",
								height:     550,
								width:      750,
								options: {
										onFinish: function()
										{
												if (GBrowserIsCompatible()) {
														var map = new GMap2(document.getElementById(Shadowbox.playerId));
														map.setCenter(new GLatLng(50.6105, 8.643), 12);

														var blueIcon = new GIcon(G_DEFAULT_ICON);
														blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";

														// Marker
														marker = new GMarker(new GLatLng(50.6105, 8.643), {
																icon:blueIcon
														});
														map.addOverlay(marker);

														// Infofenster mit Routenberechnung
														marker.openRouteInfoWindow = getRouteInfoWindow;
														// Hier die Adresse des Markers eintragen
														marker.openRouteInfoWindow_targetName = "Am Augarten 5, 35435 Wettenberg";
														// Hier HTML eintragen, das oben im InfoFenster erscheinen soll.
														marker.openRouteInfoWindow_html = "<div class='googlemap-logo'></div>";
														// Infofenster �ffnen
														marker.openRouteInfoWindow();
														// Nach einem Klick auf Schlie�en kann man das Infofenster mit einem Klick auf den Marker wieder �ffnen
														GEvent.addListener(marker, "click", function()
														{
																marker.openRouteInfoWindow();
														});
												}
										}
								}
						});
				});
		}
});

function animateSlideshow()
{
		clearInterval(ani);
		$('#imageslide-container').children('ul').animate({
				'marginLeft':'-'+slide_width+'px'
		},speed,'linear').animate({
				'marginLeft':'0px'
		},0);
		ani = setInterval("animateSlideshow()", speed);
}

function initialize() {
		if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById(Shadowbox.playerId));
				map.setCenter(new GLatLng(50.6105, 8.643), 12);

				var blueIcon = new GIcon(G_DEFAULT_ICON);
				blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/green/blank.png";

				// Marker
				marker = new GMarker(new GLatLng(50.6105, 8.643), {
						icon:blueIcon
				});
				map.addOverlay(marker);

				// Infofenster mit Routenberechnung
				marker.openRouteInfoWindow = getRouteInfoWindow;
				// Hier die Adresse des Markers eintragen
				marker.openRouteInfoWindow_targetName = "Am Augarten 5, 35435 Wettenberg";
				// Hier HTML eintragen, das oben im InfoFenster erscheinen soll.
				marker.openRouteInfoWindow_html = "<div class='googlemap-logo'></div>";
				// Infofenster öffnen
				//marker.openRouteInfoWindow();
				// Nach einem Klick auf Schließen kann man das Infofenster mit einem Klick auf den Marker wieder öffnen
				GEvent.addListener(marker, "click", function()
				{
						marker.openRouteInfoWindow();
				});
		}
}

function getRouteInfoWindow(sAction)
{	// this ist marker
		var LatLong = this.getLatLng();

		var aDisplay = ["block", "none", "none"];
		if (sAction == "to") aDisplay = ["none", "block", "none"];

		var sTargetName = this.openRouteInfoWindow_targetName;
		var sHtml = this.openRouteInfoWindow_html;

		// Info Window: Route
		sHtml +=	'<div style="display:'+aDisplay[0]+';">' +
		'Am Augarten 5<br>35435 Wettenberg<br>' +
		'<a href="javascript:ShowRoute(\'to\');">Route berechnen</a>' +
		'</div>';

		// Info Window: Hierher
		sHtml += 	'<div style="display:'+aDisplay[1]+';">' +
		'Am Augarten 5<br>35435 Wettenberg<br>' +
		'<a href="javascript:ShowRoute(\'to\');">Route berechnen</a><br/>' +
		'Start:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
		'<input type="text" SIZE=17 MAXLENGTH=40 name="saddr" id="saddr" value="">' +
		'<input value="OK" TYPE="SUBMIT">';
		if (sTargetName != "")
				sHtml += '<input type="hidden" name="daddr" value="'+sTargetName+'">';
		else	sHtml += '<input type="hidden" name="daddr" value="'+LatLong.lat()+','+LatLong.lng()+'">';
		sHtml +=  '</form></div>';

		this.closeInfoWindow();
		this.openInfoWindow(sHtml);
}

function ShowRoute(sAction)
{
		marker.openRouteInfoWindow(sAction);
}
