
var rpdGalleryStatus = 'active';

$(document).ready(function() {

	/* Some Effects */
	/*
	$('input.primaryButton, a.primaryButton, button.primaryButton').each(function(e){
		$(this).wrap('<span class="primaryButton"></span>');
	});
	*/

	$('ul.error').hide().slideDown(400).find('li:empty').remove();

	$('#stageHeader #contentTitle').each(function(){
		var content = $(this).html().length;

		if(content == 0) {
			$('#stageHeader').remove();
		}
	});

	/* Navigationsmenü animieren
	if($.browser.msie && ($.browser.version == '6.0')) {
	} else {
		$('#subNavi ul').hide().fadeIn(1000);
	}
	*/

	/*******************************************/

	$('#teamDetail').height('228px');

	$('#teamList li a').click(function(){
		$('#teamList li a').removeClass('active');
		$(this).addClass('active');

		var boxNumber    = $(this).attr('rel');
		var boxHeight    = $('#teamDetail').height();
		var sliderHeight = ((boxNumber * boxHeight) - boxHeight);

		$('#teamDetailWrapper').animate({
    		marginTop: '-' + sliderHeight + 'px'
    	}, 500);

		return false;
	});

	/*******************************************/

	$('#addressField').hide();
	$('a.toggleAddressField').toggle(function(){
		$('#addressField').slideDown();
		$('#broschuere').attr('checked', 'ckecked');
		/*window.location.href='#addressField';*/
	}, function(){
		$('#addressField').slideUp();
		$('#broschuere').removeAttr('checked');
	});

	/*******************************************/

	/* Gallery */
	$('#rpdGallery').css('height', '300px').css('overflow', 'hidden').cycle({
		fx:            'scrollHorz',
		startingSlide: 0,
		sync:          1,
		speed:         500,
		delay:         2000,
		height:        'auto',
		timeout:       3000,
		fit:           1,
		prev:          '#rpdGalleryPrev',
		next:          '#rpdGalleryNext'
	});

	/* Start und Stop fpr die Gallery */
	$('a#rpdGalleryPause, #rpdGalleryStart').livequery('click', function(){
		if (rpdGalleryStatus == 'active') {
			$('#rpdGallery').cycle('pause');
			$(this).attr('id', 'rpdGalleryStart').find('span').text('Start');
			rpdGalleryStatus = 'paused';
		} else {
			$('#rpdGallery').cycle('resume');
			$(this).attr('id', 'rpdGalleryPause').find('span').text('Pause');
			rpdGalleryStatus = 'active';
		}

		return false;
	});

	/* ermöglicht bei den Teaserboxen mehrere Bilder anzugeben */
	$('#teaserBoxes div.textboxImage').each(function(){
		var countImages = $(this).find('a').length;
		$('#teaserBoxes div.textboxCaption').remove();

		if(countImages > 1) {
			/* Entfernt das onclick-Gedöns von Typo */
			var targetFirstElement = $(this).find('a:first').attr('href');
			$(this).find('a').removeAttr('onClick').attr('href', targetFirstElement);

			$(this).cycle({
				fx:      'fade',
				/*fx:      'scrollUp',*/
				speed:   700,
				timeout: 6000
			});
		}
	});
	
	/*******************************************/

	/* Newsliste Startseite */
	$('ul.simpleNewsList').cycle({
		fx:      'scrollLeft',
		speed:   300,
		timeout: 6000
	});

	/*******************************************/

	/* Wenn die ContentBar (Links neben dem Content) größer als der Content selbst ist, content vergrößern. */
	$('#content').each(function(){
		var contentHeight    = $(this).height();
		var contentBarHeight = $(this).find('div.contentBar').height();

		if(contentBarHeight > contentHeight) {
			$(this).css('min-height', contentBarHeight + 'px');
		} else if(contentHeight > contentBarHeight) {
			$('div.contentBar').css('min-height', contentHeight + 'px');
		}
	});

	/*******************************************/

	/* MediaGallery */
	$('#mediaGallery li div.mediaGalleryCover').bind('click mouseover', function(){
		var imageFile = $(this).find('img').attr('src');
		var imageInfo = $(this).prev().html();

		$('#mediaGalleryFirstMask').css('background', 'url(' + imageFile + ') no-repeat 35px 15px');
		$('#mediaGalleryFirstTitle').html(imageInfo);

		return false;
	});

	/*******************************************/
	
	$('#jobs').css('top', '69px').find('h2').css('cursor', 'pointer');
	$('#jobs h2').toggle(function(){
		$('#jobs').animate({top: 0}, 500);
	}, function(){	
		$('#jobs').animate({top: '69px'}, 800);
	});
});