$(document).ready(function(){
    /* SLIDESHOW***************************************************/ 
	if ($('.slideshow img').length > 1) {
		$('.slideshow').cycle({
			fx: 'fade', 		
			timeout: 4000		
		});		
	}
	/* TEASER SLIDER***********************************************/
  	if ($('li.teaser_item .inner').length > 1) {  
		$('li.teaser_item').css('background-image', 'url(fileadmin/style/images/teaser_col_bg_blue.gif)');
		$('li.teaser_item').css('background-repeat', 'no-repeat');
		$('li.teaser_item').wrapInner('<div class="teaserSlideshow" />');
		$("li.teaser_item a:empty").remove();
		$('.teaserSlideshow:has(.inner)').cycle({
			fx: 'fade', 		
			timeout: 5000		
		}); 	
	}
	/* FANCYIMAGE***************************************************/ 
    $("a.fancyimage").fancybox({
        'hideOnContentClick'	: true,
        'overlayShow'			: true,
		'overlayOpacity' 		: 0.3,
		'overlayColor'			: '#666',
		'overlayOpacity'		: 0.8,
		'scrolling'				: 'overflow',
		'showCloseButton'		: true,
		'autoScale'				: true,
		'autoDimensions'		: true,
        'transitionIn'			: 'none',
		'transitionOut'			: 'none',
		'type' 					: 'image'
    });

    $("a.fancyvideo").fancybox({
        'hideOnContentClick'	: true,
        'overlayShow'			: true,
        'width'					: 490,
        'height'				: 380,
		'href'					: 'http://www.ivgservice.de/_cavernsfilmstream_2009-04-17/index.html',
		'type'					: 'iframe'
    });

	$('.tx-gmfaccordion-pi1-text').find('img[clickenlarge]').each(function(index){
		$(this).css({'cursor': 'pointer'});
	    $(this).click(function() {
			$.fancybox({
		        'hideOnContentClick': true,
		        'overlayShow':    true,
		        'zoomSpeedIn':    0, 
		        'zoomSpeedOut':    0,
				'href'			: this.src
			});
			return false;			
		});
	});
	
	// add the alt text as caption to every image within an accordion 
	$('.tx-gmfaccordion-pi1 img').each( function(index, element){
		
		var jElement = $(element);
		
		if (jElement.attr('alt') != '' ){
			
			var elemStyle = jElement.attr('style');
			var elemAltText = jElement.attr('alt');
			
			var imageWidth = jElement.css('width');
			
			var elemParent = element.parentNode;
			
			if (elemParent.tagName.toUpperCase() == 'A') {
				jElement = $(elemParent);
			}
			
			//jElement.wrap('<div />')
			jElement.wrap('<div style="display:inline;'+ elemStyle +'" />')
			//jElement.wrap('<div style="width:'+ imageWidth +'px" />')
				.parent()
				.wrap('<div style="float:left" />')
				.parent()
				.append('<br /><div class="accordionImgCaption" style="display:block;width:'+ imageWidth +'" >'+ elemAltText +'</div>')
				.parent()
				.css('clear' , 'both');
			
		}
		
	});

	
});
