$(function(){
	$('.toggle-list-container .list-item').each(function(){
		var content = $('.item-content', this).hide() ;
		$('.toggler', this).click(function(){
			if (!content.is(':visible')) {
				$(this).closest('.list-item').addClass('active') ;
			}
			
			var toggleFunc = $(this).closest('.toggle-list-fade').length > 0 ? 'fadeToggle' : 'slideToggle' ;
			content[toggleFunc]('slow', function(){
				var elem = $(this) ;
				if (!elem.is(':visible')) {
					elem.closest('.list-item').removeClass('active') ;
				}
			}) ;
			return false ;
		}) ;
	}) ;
	
	if ($(location.hash).length > 0) {
		$(location.hash).find('h2').click() ;
	}
	
	
	// Submenu
	$('#menu ul ul').not(':has(li)').remove() ;
	$('#menu ul ul').hide() ;
	$('#menu ul li').mouseenter(function(){
		$('ul', this).fadeIn() ;
	}) ;
	$('#menu ul li').mouseleave(function(){
		$('ul', this).fadeOut() ;
	}) ;
	
	// Videothek
	$('.videos a').click(function(){
		//NonverBlaster.swf?mediaURL=/fileadmin/spot/jacques_britt_spot_30sekunden.flv&autoPlay=true&controlColor=0xfcf4d2&controlBackColor=0x000000&buffer=5&scaleIfFullScreen=true&showScalingButton=true&showTimecode=true&allowSmoothing=true&loop=false
		
		if (window.location.search.indexOf('test') != -1) {
			var videofile = this.href ;
			$.fancybox({
				//'type': 'inline',
				'content': '<div id="fancy_div" style="width:640px;height:360px"></div>',
				'width': 640,
				'height': 360,
				'padding': 15,
				'autoScale': false,
				'transitionIn': 'none',
				'transitionOut': 'none',
				'onComplete': function(){
				 	player = $f("fancy_div",'fileadmin/templates/flowplayer/flowplayer-3.2.7.swf',{
						//play:{opacity:0},
						clip:{
							autoPlay:true,
							autoBuffering:true,
							url:videofile+'',
							scaling:'orig',
							/*onStart: function(clip){
								var wrap=jQuery(this.getParent());
								var clipwidth = clip.metaData.width;
								var clipheight= clip.metaData.height;
								var pos = $.fn.fancybox.getViewport();
								$("#fancy_outer").css({width:clipwidth,height:clipheight});
								$("#fancy_outer").css('left',((clipwidth + 36)> pos[0]?pos[2]:pos[2]+Math.round((pos[0]-clipwidth-36)/2)));
								$("#fancy_outer").css('top',((clipheight + 50)> pos[1]?pos[3]:pos[3]+Math.round((pos[1]-clipheight-50)/2)));
							},
							onFinish:function(){
								$('#fancy_close').trigger('click');
							},*/
							'foo':'foo'
						}
					});
					player.load();
					/*$('#fancy_close').click(function(){
						$("#fancy_div_api").remove();
					});*/
				},
				'onClosed': function(){
					$("#fancy_div").remove();
				}
			}) ;
		}
		else {
		
		$.fancybox({
			'width': 640,
			'height': 480,
			'padding': 15,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			//'overlayOpacity':	0.7,
			//'overlayColor':	'#000',
			//'scrolling':	'no',
			'type': 'swf',
			'href' : 'typo3conf/ext/nonverblaster_flashplayer/res/player/NonverBlaster.swf', //this.href
			'swf': {
				menu: "false",
				allowFullScreen: "true",
				allowScriptAccess: "always",
				wmode: "",
				flashVars: "mediaURL="+this.href+'&'+jQuery.param({
					//teaserURL: "uploads/tx_nonverblasterflashplayer/",
					//indentImageURL: "uploads/tx_nonverblasterflashplayer/",
					allowSmoothing: "true",
					autoPlay: "true",
					buffer: "5",
					showTimecode: "true",
					loop: "false",
					controlColor: "0xffffff",
					controlBackColor: "0x5a5651",
					scaleIfFullScreen: "true",
					showScalingButton: "true",
					defaultVolume: "100",
					crop: "false"
				})
			}
		});
		
		}
		
		return false ;
	}) ;
}) ;
