 $(document).ready(function(){
	if($('#slideshow').length>0)
	{
		$('#slideshow').cycle({
			fx: 'fade',
			timeout: 6000,
			speed: 2000
		});
	}
	if($('#slideshow2').length>0)
	{
		function slideshowBefore(){
			var num = parseInt($(this).find("img").attr("src").replace(/img\/umgebung/,"").replace(/\.jpg/,""));
			$("#nav-num").html(num);
		}
		
		var startslide = window.location.search != "" ? window.location.search.substr(4,1) : 1;
		console.log(window.location.search);
		console.log(startslide);
		$('#slideshow2').cycle({
			fx: 'fade',
			timeout: 6000,
			speed: 2000,
			next:   '#next', 
			prev:   '#prev',
			pager:  '#nav', 
			pagerAnchorBuilder: function(idx, slide) { 
				// return selector string for existing anchor 
				return '#nav li:eq(' + idx + ') a'; 
			},
			startingSlide: parseInt(startslide)-1,
			before: slideshowBefore
		});
		
		
		$('#stopButton').hide();
		$('#slideshow2').cycle('pause'); 
		
		$('#startButton').click(function() { 
			$('#slideshow2').cycle('resume');
			$(this).hide();
			$('#stopButton').show();
		});
		$('#stopButton').click(function() { 
			$('#slideshow2').cycle('pause'); 
			$(this).hide();
			$('#startButton').show();
		});
	}
	
	$("ul.wohnungsliste li").hover(
		function(){
			var id = $(this).attr("id").replace(/gr/,'');
			var top = -(382*(parseInt(id)));
			$("div#grundriss").css('backgroundPosition','0 '+top+'px');
			if (id==4) {
				$(this).addClass("over");
				$("li#wohn-"+id+" a").css("color","#ff3300");
				//window.setTimeout(function(){},500);
			}
		},
		function(){
			var id = $(this).attr("id").replace(/gr/,'');
			$("div#grundriss").css('backgroundPosition','0 0');
			if (id==4) {
				$(this).removeClass("over");
				$("li#wohn-"+id+" a").css("color","#666");
				//window.setTimeout(function(){},500);
			}
		}
	);	
	
	$("ul.wohnungsliste li").click(function(){
		var id = $(this).attr("id").replace(/gr/,'');
			if (id==4) window.location.href = ($(this).find("span.link a").attr("href"));
	});
	
	$("ul#subnavigation-wohnungen li a").hover(
		function(){
			var id = $(this).parents("li").attr("id").replace(/wohn-/,'');
			var top = -(382*(parseInt(id)));
			$("div#grundriss").css('backgroundPosition','0 '+top+'px');
			if (id==4) {
				$("ul.wohnungsliste li#gr"+id).addClass("over");
				//window.setTimeout(function(){},500);
			}
		},
		function(){
			var id = $(this).parents("li").attr("id").replace(/wohn-/,'');
			$("div#grundriss").css('backgroundPosition','0 0');
			if (id==4) {
				$("ul.wohnungsliste li#gr"+id).removeClass("over");
				//window.setTimeout(function(){},500);
			}
		}
	);	
	
 });
