var animation_time = 300;

jQuery(function(){

	jQuery("body").removeClass("no-js");
			
	var enable = jQuery('.coda-slider .panel').length > 1;

	var settings = {
		autoSlide : jQuery('.coda-slider DIV.panel').length > 1,
		autoSlideInterval : 3000,
		autoSlideStopWhenClicked : false,
		autoSlidePauseWhenMouseOver : true,
		dynamicArrows : true,
		dynamicArrowLeftText : '<img src="/fileadmin/templates/global/img/arrow-left.png" width="25" height="25">',
		dynamicArrowRightText : '<img src="/fileadmin/templates/global/img/arrow-right.png" width="25" height="25">',
		dynamicTabs : false,
		continous : true,
		crossLinking : false
	};

	document.sliders = jQuery('.coda-slider').codaSlider(settings);

	// fade in/out function 
	var fader = function(opacity, duration) {
		var left = jQuery(".coda-nav-left a",this);
		var right = jQuery(".coda-nav-right a",this);
		if(left) left.stop(true, false);
		if(right) right.stop(true, false);
		if(left) left.animate({ opacity:opacity }, duration);
		if(right) right.animate({ opacity:opacity }, duration);
	}

	fader.call(this, 0, 0);

	if(enable) { jQuery("div.coda-slider-wrapper").hover(
		// fade navigation in and out on hover
		function() { fader.call(this, 0.7, animation_time); },
		function() { fader.call(this, 0, animation_time); }
	); } else {
		// disable navigation elements if only a single slide
		jQuery("div.coda-slider-wrapper").find('.coda-nav-left a, .coda-nav-right a').hide();
	}

	var titleFormat = function(title, currentArray, currentIndex, currentOpts) {
		if (!title) return false;
		html = '<span id="fancybox-title-wrap">';
		html +=  '<span id="fancybox-title-left"></span>';
		html +=  '<span id="fancybox-title-main">';
		html +=   title;
		html +=  '</span>';
		html +=  '<span id="fancybox-title-right"></span>';
		html += '</span>';
	return html; }

	var selector = 'DIV.gallery TABLE.gallery-thumbnail TR TD A';

	if (jQuery.fn.colorbox) {
	
		jQuery(selector).colorbox({
			rel : 'gallery',
			slideshow : true,
			slideshowAuto : false,
			slideshowStart : 'Slideshow Starten',
			slideshowStop : 'Slideshow Stoppen',
			current : '{current} von {total}',
			close : 'Schliessen',
			previous : 'Zurück',
			next : 'Vorwärts',
			preloading : true,
			scalePhotos : true,
			maxWidth : "100%",
			maxHeight : "100%"
		});

	} else if (jQuery.fn.fancybox) {

		jQuery(selector).fancybox({
			cyclic : true,
			speedIn : 400, 
			speedOut : 200, 
			transitionIn : 'fade',
			transitionOut : 'fade',
			easingIn : 'easeOutBack',
			easingOut : 'easeInBack',
			titleFormat : titleFormat,
			titlePosition : 'outside',
			overlayShow : true,
			showNavArrows : true,
			hideOnContentClick: true,
			enableEscapeButton : true
		});

	} else if (jQuery.fn.lightBox) {

		jQuery(selector).lightBox({
			overlayBgColor: '#FFFFFF',
			overlayOpacity: 0.6,
			imageLoading: '/fileadmin/templates/global/img/lightbox/loading.gif',
			imageBtnClose: '/fileadmin/templates/global/img/lightbox/close.gif',
			imageBtnPrev: '/fileadmin/templates/global/img/lightbox/prev.gif',
			imageBtnNext: '/fileadmin/templates/global/img/lightbox/next.gif',
			imageBlank: '/fileadmin/templates/global/img/lightbox/blank.gif',
			containerResizeSpeed: 350,
			containerBorderSize: 10,
			keyToClose: 'x',
			keyToPrev: 'p',
			keyToNext: 'n',
			txtImage: 'Bild Nr.',
			txtOf: 'von'
		});

	}
	
});
