$(function() {

	$('#nav a[href$="/immobilien.htm"]').attr({ href: 'index.php?sp=de&id=301&sok=1' });
	

	// Karten
	if($('#map_canvas').length) { 
		var Lat = $('input#Lat').val();
		var Lng = $('input#Lng').val();
		var zoomLevel = parseInt($('input#zoomLevel').val());
		var map = new GMap2($("#map_canvas")[0]);
		var point = new GLatLng(Lat, Lng);
		map.setCenter(point, zoomLevel, G_HYBRID_MAP);
		map.addControl(new GSmallMapControl());
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		map.addOverlay(new GMarker(point));
	};

	// Shadowbox
	if($('a[rel^="shadowbox"]').length) {
		Shadowbox.init({ 
			handleOversize: "resize",
			overlayOpacity: 0.8
		});
	};
	
	// Immobilien
	$('.ajaxinfobox:gt(0)').hide();
	$('.projektnav li a:not(.nojs)').click(function() { 
		var ziel = $(this).attr('href');
		$('.ajaxinfobox:not('+ziel+')').fadeOut(500);
		$('.ajaxinfobox'+ziel).delay(500).fadeIn(500);
		$('#preise table')
			.removeAttr('border')
			.removeAttr('cellpadding')
			.removeAttr('cellspacing');
		return false;
	});

	if(window.location.hash == "#kontakt") { 
		$('.ajaxinfobox:not(#kontakt)').fadeOut(500);
		$('.ajaxinfobox#kontakt').delay(500).fadeIn(500);
	};
	
	

    $('div.ajaxinfobox table tr:odd').addClass('odd');
    $('div.ajaxinfobox#preise table').delegate('td', 'mouseover mouseleave', function(e) {
        if (e.type == 'mouseover') {
          $(this).parent().addClass('hover');
        } else {
          $(this).parent().removeClass("hover");
        }
    });
	
	// Galerie
	$('div.bilder ul.bildnav li a').live('click', function() { 
		var klasse = $(this).parent().attr('class');
		var href = $(this).attr('href');
		var alt = $('div.bilder img').attr('alt');
		var speed = 800;
		
		$.get(href, function(html) { 
			var content = $(html).find('div.galerie').html();
			var bild = $(html).find('div.bilder img').attr('src');
			if(klasse == 'forward') { 
				var wert1 = '-684px';
				var wert2 = '684px';
			} else if (klasse == 'back') { 
				var wert1 = '684px';			
				var wert2 = '-684px';			
			};			
			
			$('body').animate({ opacity: '+=0' }, 200, function() {
			$('div.bilder img').animate({ left: wert1 }, speed);			
			$('<img alt="'+alt+'" src="'+bild+'" />')
				.appendTo('div.bilder')
				.css({ left: wert2 })
				.animate({ left: '0px' }, speed, function() { 
					$('div.galerie').html(content);
					if($('a[rel^="shadowbox"]').length) {
						Shadowbox.setup();
						Shadowbox.init({ 
							handleOversize: "resize"
						});
					};
					$('#subnav li ul li.aktiv').removeClass('aktiv');
					$('#subnav li ul li a[href="'+href+'"]').parent().addClass('aktiv');
					$('.galerie .bilder img:first').click(function() { 
						$('a[rel^="shadowbox"]:first').trigger('click');
						return false;
					});
				});
			});
		});
		return false;
	});
	
	$('.galerie .bilder img:first').click(function() { 
		$('a[rel^="shadowbox"]:first').trigger('click');
		return false;
	});
	

	// IE-Transparenz
	if($.browser.msie) { 
		$('div.kopfbild div.border').css({ opacity: 0.7 });
	};

	// Navigation
	$('#nav li:first a').css({ paddingLeft: '15px' });
	$('#nav').lavaLamp({
		speed: 300
	});
	$('body.start #nav li.back').css({ left: '-150px' });	
	
	
	// Höhenanpassungen für Footer-Boxen
	var maxheight = 0;
	$('#footer .fbox').each(function() { 
		var height = $(this).height();
		if (maxheight < height) { 
			maxheight = height;
		}
	});
	$('#footer .fbox').height(maxheight+'px');
	
	// Grauer BG
 	if($('#footer .fbox.grau img.boxhintergrund').length) { 
		$('#footer .fbox.grau').addClass('weisseschrift');
		$('#footer .fbox.grau img.boxhintergrund').css({ opacity: 0.3 });
		$('#footer .fbox.grau:has(img.boxhintergrund)')
			.addClass('innerbox3')
 			.hover(function() { 
				$(this)
					.find('img.boxhintergrund')
					.stop()
					.animate({ opacity: 1 }, 400);
			}, function() { 
				$(this)
					.find('img.boxhintergrund')
					.stop()
					.animate({ opacity: 0.3 }, 400);			
			});	
	}
	
	// Weißer BG
	if($('#footer .fbox:not(.grau) img.boxhintergrund').length) { 
		$('#footer .fbox:not(.grau)').each(function() { 
			$(this)
				.addClass('innerbox')
				.wrapInner('<div class="innerbox2"></div>')
				.find('img.boxhintergrund')
				.prependTo(this)
				.css({ opacity: 0.4 });
			$(this).hover(function() { 
				$(this)
					.find('img.boxhintergrund')
					.stop()
					.animate({ opacity: 1 }, 400);
			}, function() { 
				$(this)
					.find('img.boxhintergrund')
					.stop()
					.animate({ opacity: 0.4 }, 400);			
			});	
		});			
	}

});

/* Captcha-Bild aktualisieren */
function newCaptcha() {
	document.getElementById('captcha').src = 				
	'func/modul_captcha/securimage/securimage_show.php?sid=' + Math.random(); 
	return false;
}