 
jQuery(document).ready(function() {

	// **** infocard gallery ****
	jQuery(".scrollable").scrollable({circular: true}).navigator();
	jQuery(".container-thumb .browse").hover(
		function () {
			jQuery(this).addClass("hover");
		},
		function () {
			jQuery(this).removeClass("hover");
		}
	);

	// **** fancybox: gallery ****	
	// common settings
	var myLang = window.location.href.match(/\/en\//) ? 'en' : 'de'; // @note better: jQuery('html').attr('lang')
	if (myLang == 'de') {
		var locallang = {
			'loadingplayer' : 'Player wird geladen ...',
			'close' : 'Schließen',
			'showmoreinformation': 'Mehr Informationen anzeigen',	
			'showlessinformation': 'Weniger Informationen anzeigen',
			'saalplan': 'Saalplan'
		};
	} else {
		var locallang = {
			'loadingplayer' : 'Loading the player ...',
			'close' : 'Close',
			'showmoreinformation': 'Show more information',	
			'showlessinformation': 'Show less information',
			'saalplan': 'Seating Plan'
		};
	}
	
	var config = {
		'overlayColor': '#000',
		'titleShow': false,
		'hideOnContentClick': false,
		'cyclic': true,
		'onComplete': function() {
			jQuery('#fancybox-close').html('').html(locallang['close']);
		}
	};
	jQuery(".fancy-gallery").each(function() {

		var myConfig = jQuery.extend({}, config);
		
		// video settings
		if (this.href.match(/(\.flv|\.mp4)$/) || this.href.match(/youtube/)) {
			var uniqueid = new Date().getTime();
			var idjw = 'idjw' + uniqueid;
			myConfig['content'] = 
				  '<div class="se-fancybox-container se-fancybox-video">'	
				+	'<div id="jwplayer-' + idjw + '">' + locallang['loadingplayer'] + '</div>'
				+	'<script>jwplayer("jwplayer-' + idjw + '").setup({'
	
						// options jwplayer
						+	'flashplayer:"/typo3conf/ext/setbevents/Resources/Public/jwplayer/player.swf",'
						+	(jQuery(this).hasClass('fancy-autoplay') ? 'autostart:"true",' : '')
						+	'file:"' + this.href + '",'
						+	'backcolor:"' + (jQuery('body').hasClass('pagebar') ? 'b78f4f' : '812383') + '",'
						+	'frontcolor:"ffffff",' 
						+	'lightcolor:"ffffff",' 
						+	'height:400,'
						+	'width:600'
				
				+	'});</script>'				
				+ '</div>'
				;
		
		// image settings
		} else {
			myConfig['type'] = 'image';
		}
		
		jQuery(this).fancybox(myConfig);
	});	
	
	
	// **** fancybox: tickets ****
	jQuery(".fancy-tickets").each(function() {
		
		var myConfig = jQuery.extend({}, config);		
		var urlSaalplan = jQuery(this).next(".tool-saalplan").attr('href');
		myConfig['autoDimensions'] = true;
		myConfig['content'] = 
			  '<div class="se-fancybox-container se-fancybox-container-ticktes">'
			+	'<h1>' + this.title + '</h1>'
			+   ((urlSaalplan != null && urlSaalplan != '') ? '<p><strong><a href="' + urlSaalplan + '" target="saalplan">' + locallang['saalplan'] + '</a></strong></p>' : '')
			+	'<iframe style="width:700px;height:620px;" src="' + this.href + '" />'
			+ '</div>'
			;
		
		jQuery(this).fancybox(myConfig);		
	});

	
	// **** accordion ****
	// via http://designreviver.com/tutorials/jquery-examples-horizontal-accordion/
	var maxWidth = 406;
	var minWidth = 63;
	var duration = 400;
	jQuery(".se-accordion").each(function(){
		
		var lastBlock = jQuery('li:first', this);
		jQuery(this).children('li').each(function(){
			
			// init li attributes
			var moreUri = jQuery('a:first', this).attr('href');
			var moreTitle = jQuery('a:first', this).attr('title');
			jQuery(this).click(function(){ window.location.href = moreUri; });
			jQuery(this).attr('title', moreTitle);

			// init animation
			jQuery(lastBlock).animate({width: maxWidth + "px" }, { queue: false, duration: duration });
			jQuery(this).hover(
				function(){
					jQuery(lastBlock).animate({width: minWidth + "px" }, { queue: false, duration: duration });
					jQuery(this).animate({width: maxWidth + "px" }, { queue: false, duration: duration });
					lastBlock = this;
				}
			);
		});
	});
	
	
	// **** seriesitem: show more/less ****
	jQuery('.toolbar-show-lessmore').each(function(){
		jQuery(this).click(function(){
			
			var offsetFixedHeader = -217;
			
			if (jQuery(this).hasClass('show-more')) {
				
				// close all open detail view
				jQuery('.seriesitem-contentdetail').each(function(){
					if (jQuery(this).next('.toolbar-show-lessmore').hasClass('show-less')) {
						jQuery(this).hide();
						jQuery(this).next('.toolbar-show-lessmore').removeClass('show-less').addClass('show-more');
						jQuery(this).next('.toolbar-show-lessmore').children(':first').replaceWith('<span>' + locallang['showmoreinformation'] + '</span>');
					}
				});
				
				// open detailview above toolbar
				jQuery(this).prev().show();
				jQuery(this).removeClass('show-more').addClass('show-less');
				jQuery('span:first', this).replaceWith('<span>' + locallang['showlessinformation'] + '</span>');
				jQuery('html, body').animate({scrollTop: jQuery(this).parent().offset().top + offsetFixedHeader}, 500);
			} else {
				jQuery(this).prev().hide();
				jQuery(this).removeClass('show-less').addClass('show-more');
				jQuery('span:first', this).replaceWith('<span>' + locallang['showmoreinformation'] + '</span>');
				jQuery('html, body').animate({scrollTop: jQuery(this).parent().offset().top + offsetFixedHeader}, 500);
			}
		});
	});
	
	jQuery('.goto-seriesitemdetail').each(function(){
		jQuery(this).click(function(){
			
			var offsetFixedHeader = -217;
						
			// close all open detail view
			jQuery('.seriesitem-contentdetail').each(function(){
				if (jQuery(this).next('.toolbar-show-lessmore').hasClass('show-less')) {
					jQuery(this).hide();
					jQuery(this).next('.toolbar-show-lessmore').removeClass('show-less').addClass('show-more');
					jQuery(this).next('.toolbar-show-lessmore').children(':first').replaceWith('<span>' + locallang['showmoreinformation'] + '</span>');
				}
			});
			
			// open targeted detailview
			var targetId = this.href.match(/seriesitem-id\d+/);
			jQuery('#' + targetId + ' .seriesitem-contentdetail').show();
			jQuery('#' + targetId + ' .toolbar-show-lessmore').removeClass('show-more').addClass('show-less');
			jQuery('#' + targetId + ' .toolbar-show-lessmore span:first').replaceWith('<span>' + locallang['showlessinformation'] + '</span>');
			jQuery('html, body').animate({scrollTop: jQuery('#' + targetId).offset().top + offsetFixedHeader}, 500);
			return false;
		});
	});

	// **** css-fixes ****
	jQuery('.container-content').each(function(){
		if (jQuery('h2', this).height() > 40) {
			jQuery('p', this).height('54px');
		}
	});
	
});


