$(document).ready(function() {
	$('body').addClass('fx');
	DetectImageState.init(WFD_STATIC_COMMON + 'img/blank.gif', disableImages);

	$('.expandable-text').each(function() {
		var expandableText = $(this);
		var height = expandableText.height();
		expandableText.css({height: '10.5em'});
		if (expandableText.height() > height) {
			expandableText.css({
				height: height + 'px'
			});
		} else {
			$(this).after('<p class="view-more">... <a href="#">' + messageViewMore + '</a></p>');
			$(this).after('<p class="view-less"><a href="#">' + messageViewLess + '</a></p>');
			var viewMoreLink = $(this).parent().find('.view-more a');
			var viewLessLink = $(this).parent().find('.view-less a');
			viewMoreLink.click(function() {
				viewMoreLink.parent().hide();
				expandableText.animate({
					height: height + 'px'
				}, 3000);
				viewLessLink.parent().show();
				return false;
			});
			viewLessLink.click(function() {
				viewLessLink.parent().hide();
				expandableText.animate({
					height: '10.5em'
				}, 3000);
				viewMoreLink.parent().show();
				return false;
			});
			viewLessLink.click();
		}
	});

	$('a.zoom').fancybox({
		speedIn: 200,
		speedOut: 200,
		changeSpeed: 200
	});

	$('.fx-rolle').each(function() {
		var rolleDiv = $(this);
		var textDiv = rolleDiv.find('.text');
		if (textDiv.text().length > 200) {
			var textContents = textDiv.html('<div>' + textDiv.html() + '</div>').children(':last').hide();
			var link = textDiv.prepend('<a style="cursor: pointer" class="link">' + rolleZusammengeklappt + '</a>').children(':first');
			link.click(function() {
				link.remove();
				textContents.slideDown();
			});
		}
	})
	
	$(window).load(function() {
		$('.produktion2011 #stage').each(function () {
		
			var stage = $(this);
			var produktionHeadings = $('#stage .produktion-headings');
			var produktionIntro = $('#stage .produktion-intro');
			
			stage.height((Math.max(produktionHeadings.height(), produktionIntro.height()) + 30) + 'px');
			
		});
	});

	$(window).load(function() {
		$('object').each(function() {
			var object = $(this);
			var parent = object.parent();

			var objectWidth = object.width();
			var parentWidth = parent.width();
			if (objectWidth > parentWidth) {
				var objectHeight = object.height();
				object.width(parentWidth + 'px');
				object.height(
					objectHeight / (objectWidth / parentWidth)
				);
			}
		});
	})
});

function disableImages(bDisabled) {
	if( bDisabled ){
		$('body').removeClass('img-enabled');
	}
}
