$(function() {

	/* Customize Animation */
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};
	
	/* Callback for fadeToggle */
	function toggleText(elem) {
		if($(elem).text() == 'Weitere Fotos einblenden') {
			$(elem).text('Weitere Fotos ausblenden');
		} else {
			$(elem).text('Weitere Fotos einblenden');
		}
	}
	
	/* init hide */
	$('.hidecontent').hide();
	$('.hidecontentsmall').hide();
	
	$('.hidecontent').before('<p class="pt15"><a class="btn toggle" href="#">Weitere Fotos einblenden</a></p>');
	
	/* Toggle image views */
	$('a.toggle').click(function() {
		$('.hidecontent').fadeToggle('slow','', toggleText(this));
		return false;
	});
		
					
	/* cycle slideshow*/
	if ($(".slideshowthumbs")[0]) {
		$('.slideshowthumbs').cycle({ 
		    fx:    'scrollDown',
		    timeout: 2500,
		    easeIn: 'bounceout',
		    easeOut: 'bounceout', 
		    delay:  -1500
		});
	}
	
		
	if ($(".slideshow")[0]) {
		$(this).css('height','310px');
		$('.slideshow').cycle({
			fx: 'fade',
			speed: 2500,
                        delay: -2000,
			pause: false
		});
	}

		// append control links
		$('.slideshowthumbs, .slideshow').after('<p class="center"><img title="Pause" src="/src/images/icons/icon-pause.png" class="pause" alt="Play" /> <img title="Fortfahren" src="/src/images/icons/icon-resume.png" class="resume" alt="Fortfahren" /></p>');
				
		$('.pause','.cycle').click(function() {
			$('.slideshowthumbs, .slideshow').cycle('pause');
			return false;
		});
		$('.resume','.cycle').click(function() {
			$('.slideshowthumbs, .slideshow').cycle('resume');
			return false;
		});
	//}
	
	/* Icon hover */
	//if ($.browser.msie === false) {
		$('.iconbar a img, .pause, .resume').hover(
			function() {
                                o = $(this).attr('src');
				var s = o.slice(-4);
				var f = o.slice(0,-4);
				$(this).attr({src: f + '-active' + s});
				$(this).show();
			},
			function() {
				$(this).attr({src: o});
			}
		);
	//}
	
	/* Player Icon hover */
	/*$('.pause, .resume').hover(
		function() {
			o = $(this).attr('src');
			var s = o.slice(-4);
			var f = o.slice(0,-4);
			$(this).attr({src: f + '-active' + s});
			$(this).show();
		},
		function() {
			$(this).attr({src: o});
		}
	);*/
	
	/* fancybox */
	if ($("a.grow")[0]) {
		$("a.grow").fancybox({
			'zoomSpeedIn': 300,
			'zoomSpeedOut': 300,
			'overlayShow': true
		});
	}
	
	/* flowplayer */
	if ($("#player")[0]) {		
			// hide hint for no-javascript users first
			$('.playersubstitute').hide();
			
			flowplayer("player", "/src/flash/flowplayer-3.1.5.swf", {
			canvas: {
				backgroundColor: '#333333'
				},
			clip: {
				autoPlay: false,
                                autoBuffering: false
			},
			plugins: {
			   controls: {
                              volumeSliderColor: '#466F96',
			      buttonOverColor: '#555555',
			      borderRadius: '0px',
			      sliderGradient: 'none',
			      buttonColor: '#466F96',
			      timeColor: '#efefef',
			      timeBgColor: '#555555',
			      bufferGradient: 'none',
			      sliderColor: '#466F96',
			      durationColor: '#ffffff',
			      progressGradient: 'medium',
			      progressColor: '#466F96',
			      bufferColor: '#ffffff',
			      volumeSliderGradient: 'none',
			      backgroundGradient: 'none',
			      tooltipTextColor: '#ffffff',
			      tooltipColor: '#466F96',
			      backgroundColor: '#d0d0d0',
			      height: 24,
			      opacity: 1.0,
				  tooltips: {
				    buttons: true,
					fullscreen: 'Film bildschirmfüllend anzeigen',
					play: 'Film starten',
					pause: 'Pause',
					mute: 'Ton abschalten',
					unmute: 'Ton anschalten'
				  }
			   }
			}
		});
	}

	/* flowplayer audio */
	if ($(".audio")[0]) {
			//$('.audiosubstitute').hide();

                        flowplayer("a.audio", "/src/flash/flowplayer-3.1.5.swf", {
			clip: {
				autoPlay: false,
                                onBeforeBegin: function() { 
                                //$f(".audio").close(); 
					 $f("*").each(function () {
		       				this.stop();
		     			})
                           }
			},
			plugins: {
			   controls: {
                              fullscreen: false,
                              time: false,
                              volumeSliderColor: '#466F96',
			      buttonOverColor: '#555555',
			      borderRadius: '0px',
			      sliderGradient: 'none',
			      buttonColor: '#466F96',
			      bufferGradient: 'none',
			      sliderColor: '#466F96',
			      durationColor: '#ffffff',
			      progressGradient: 'none',
			      progressColor: '#466F96',
			      bufferColor: '#ffffff',
			      volumeSliderGradient: 'none',
			      backgroundGradient: 'none',
			      backgroundColor: '#ebebeb',
			      height: 24,
			      opacity: 1.0,
				  tooltips: {
				    buttons: false
				  }
			   }
			}
		});
	}

});
