$(document).ready(function() {
	
	/**
	 * FLAPS
	 */
	$('#flap .content').width(0).hide();
	$('#flap').width(30);
	$('#flap').toggle(
		function(){
			$(this).find('.arrow').removeClass('arrow-grey-left').addClass('arrow-grey-right');
			$(this).find('.content').animate({width: '570px'}, 'fast', function(){$(this).show()});
			$(this).find('.content *').fadeIn();
			$(this).find('#flap-close').show();
			$(this).width(700);
		}, 
		function(){
			$(this).find('.arrow').removeClass('arrow-grey-right').addClass('arrow-grey-left');
			$(this).find('.content *').fadeOut();
			$(this).find('#flap-close').hide();
			$(this).find('.content').animate({width: 0}, 'fast', function(){
				$(this).hide();
				$('#flap').width(30);
			});
		}
	);
	$('<a id="flap-close" href="#">X schlie&szlig;en</a>')
		.bind('click', function() {
			$('#flap').click();
			return false;
		})
		.appendTo('#flap .content');
	
	$('#flap a.anchor').text('');
	$('#flap iframe').attr('scrolling', 'no');
	$('<span class="arrow arrow-grey-left"></span>').appendTo('#flap a.anchor');
	$('<span class="shadow shadow-top"></span>').appendTo('#flap a.anchor');
	$('<span class="shadow shadow-bottom"></span>').appendTo('#flap a.anchor');
//	
	/**
	 * Clean Page Nav
	 */
	$('#page-nav li:first-child').addClass('first');

	
	/**
	 * Set up Thickbox Link on Preview Image
	 */
	$('.grundriss-box').each(function (){
		var href = $(this).find('.image-big img').attr('src');
		$(this).find('.image-wrapper img').wrap('<a href="' + href + '" class="lightbox" />');
	});
	$('.grundriss-box .lightbox').each(function(){
			$(this).lightBox({singleItem: true});
	})
	
	/**
	 * Seite empfehlen Links as Thickbox Link
	 */
	$('#topnav a').each(function(i){
		if ($.trim($(this).text()).match(/^Seite empfehlen$/)) {
			$(this).addClass('thickbox');
			$(this).attr('href', $(this).attr('href') + '?KeepThis=true&TB_iframe=true');
		}
	});
	
	
	/**
	 * erase Border for IFrame
	 * Slideshow Lightboxes
	 * Remove TYPO3 onClick for opening in Popup and make a lightbox link
	 */
	$('iframe').each(function() {
		$(this).attr('frameborder', 0);
		$(this).attr('border', 0);
		
	});
	$('a[target=thePicture]').each(function() {
		$(this).removeAttr('onClick');
		$(this).removeAttr('onclick');
		var href = $(this).attr('href');
		href = href.substr(href.indexOf('file='));
		href = href.substr(0, href.indexOf('&'));
		href = href.replace(/file=/, '');
		href = href.replace(/%2F/g, '/');
		$(this).attr('href', href);
	}).lightBox();
	
	//tb_init('.thickbox');
});


