$(function(){
	// open links in new window
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});

	$('a.zoomvideo').fancybox({
		'hideOnContentClick':false,
		'swf':{'allowfullscreen':'true'},
		'type':'inline',
		'padding':2,
		"overlayColor":"#000000",
		"overlayOpacity":0.75,
		'scrolling':'no'
	});

	// show/hide guest book editor
	$('#postingeditor').css({ 'display':'none' });
	$('#postingeditorshow').attr('id','postingeditor');
	$('#writeposting').click( function() { $('#postingeditor').slideToggle(500); });

	$('.foldhead,.foldheadhigh').click( function() {
		var me=$(this);
		if (me.attr('class')=='foldhead') {
			// AUFKLAPPEN
			// alle anderen Titel ausgeklappter Inhalte deselektieren
			$('.foldheadhigh').removeClass('foldheadhigh').addClass('foldhead');
			// alle anderen sichtbaren Inhalte zuklappen
			$('.foldbody:visible').slideUp(350);

			// geklickten Titel anschalten
			me.removeClass('foldhead').addClass('foldheadhigh');
			me.parent().children('.foldbody:hidden').slideDown(350);
		} else {
			// ZUKLAPPEN
			me.removeClass('foldheadhigh').addClass('foldhead');
			me.parent().children('.foldbody:visible').slideUp(350);
		}
	})

	$('div.pics').parents('.ctcol9').css({'margin-bottom':0});

	// keyboard navigation for subpages
	var l1 = $('.next').attr('href'), l2 = $('.prev').attr('href'), l3 = $('.back').attr('href');
	if (l1 || l2 || l3) {
		$(document).bind('keydown.fb', function(e) {
			if (l3 && e.keyCode==27) { window.location = l3; }
			if (l2 && e.keyCode==37) { window.location = l2; }
			if (l1 && e.keyCode==39) { window.location = l1; }
		});
	}

	if ( $('#lowinner').width()>720 ) {
		var cptscroll=false, cptlines=240;
		function cptupdate() {
			cptscroll=false;
			if (parseInt($('#lowinner').css('margin-left'))<=-cptlines) {
				$('#cptup').show();
			} else {
				$('#cptup').hide();
			}
			if ( parseInt($('#lowinner').css('margin-left')) + $('#lowinner').width() - $('#lowmenu').width() >=cptlines ) {
				$('#cptdown').show();
			} else {
				$('#cptdown').hide();
			}
		}
		$('#lowmenu').after('<div id="lownavi"><div class="bottombox"><a href="javascript:void()"id="cptup">back<br/></a><a href="javascript:void()" id="cptdown">more</span></div></div>');
		cptupdate();
		$('#cptup').click(function(){
			if (parseInt($('#lowinner').css('margin-left'))<=-cptlines) {
				if ( cptscroll==false ) {
					cptscroll = true;
					$('#lowinner').animate({'margin-left':'+='+cptlines},{ duration:350,complete:function(){ cptupdate(); } });
				}
			}
		});
		$('#cptdown').click(function(){
			if ( parseInt($('#lowinner').css('margin-left')) + $('#lowinner').width() - $('#lowmenu').width() >=cptlines ) {
				if ( cptscroll==false ) {
					cptscroll = true;
					$('#lowinner').animate({'margin-left':'-='+cptlines},{duration:350,complete:function(){ cptupdate(); } });
				}
			}
		});
	}

});

