var ziel;

$(function(){

	$('.up, .down, #navigation ol, #nachoben').localScroll({
		onBefore: function(e,anchor,target){
			ziel = anchor.id;
			$(".sub a").removeClass("active");
			$(".sub a[href='#"+ziel+"']").addClass("active");
		}
	});

	$("#navigation .sub a").click(function(){
		$("#navigation .sub a").removeClass("active");
		$(this).addClass("active");
	});

	$('.scrolling').jScrollPane({
		autoReinitialise: true,
		verticalDragMaxHeight: 150
	});

	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'facebook',slideshow:2000, autoplay_slideshow: false});

	/*
	$("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
		custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>',
		changepicturecallback: function(){ initialize(); }
	});

	$("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
		custom_markup: '<div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>',
		changepicturecallback: function(){ _bsap.exec(); }
	});
	*/

	Cufon.replace("h1");

	var bildpfad;
	if(Modernizr.backgroundsize){
		// do nothing
	}else{
		$(".bild").each(function(){
			bildpfad = $(this).css("background-image");
			bildpfad = bildpfad.replace('url("','').replace('")','');
			$(this).attr("class","bild").prepend("<img src='"+bildpfad+"' alt='' />");
		});
		$('.bild > img').each(function(){
			iw = $(this).width();
			ih = $(this).height();
			iratio = iw/ih;

			if(iw >= ih){
				// landscape:
				var newHeight = w / iratio;
				if(ih<h){
					$(this).css({height:newHeight, width:w}); // fix this
					// use negative margin-left to show center?
				}else{
					$(this).css({height:newHeight, width:w});
					// set negative margin-top to show the center of the image
				};
			}else{
				// portrait:
				var newWidth = h * iratio;
				$(this).css({height:h, width:newWidth});
			};
		});
	};

	$(window).afterresize(function(){
		if($(".sub a[href='#"+ziel+"']").length > 0){
			$(".sub a[href='#"+ziel+"']").click();
		}else{
			$("#nachoben > a").click();
		};
	});

});
