 $(document).ready(function(){
		
	function slideSwitch() {
	    var $active = $('.polaroids .stage-1 img.active');
	
	    if ( $active.length == 0 ) $active = $('.polaroids .stage-1 img:last');
	
	    var $next =  $active.next().length ? $active.next()
	        : $('.polaroids .stage-1 img:first');
	
	    $active.addClass('last-active');
	
	    $next.css({opacity: 0.0})
	        .addClass('active')
	        .animate({opacity: 1.0}, 1500, function() {
	            $active.removeClass('active last-active');
	        });
	    /* tmp_img++;
	    if (tmp_img==anzahlBilder+1){
	    	tmp_img=1;
	    } */
	}
	
	/*$(function() {
	    setInterval(slideSwitch, 5000 );
	});*/
	
	/*--------------------------------- PALLMANN CODE ---------------------------------*/
	
	window.changeSlide = function(stage, slide) {
		window.clearTimeout(window['stageTimeout' + stage]);
		var s = $('#stage-' + stage);
		if ($('#stage-' + stage).data('state') != 'init') {
			$('#stage-' + stage).find('.bg').removeClass('bg');
			$('#slide-' + stage + '-' + s.data('current_slide')).removeClass('fg').addClass('bg');
		} 
		else {
			$('#stage-' + stage).data('state', 'normal');
		}
		
		tmp = $('#stage-' + stage).data('current_slide');
		tmp++;
		if (tmp > $('#stage-' + stage).data('count_slides') - 1) tmp = 0;
		if (slide != 'auto') tmp = slide;
		$('#stage-' + stage).data('current_slide', tmp);
		$('#stage-' + stage).find('.slide').not('.bg').hide();
		$('#slide-' + stage + '-' + tmp).addClass('fg').hide().fadeIn(1000);
		$('#stage-' + stage).find('.nav-stage ul li').removeClass('active');
		$('#stage-' + stage).find('.nav-stage ul li#item-' + stage + '-' + tmp).addClass('active');
		if (slide == 'auto') {
			window['stageTimeout' + stage] = window.setTimeout(function() {
				window.changeSlide(stage, 'auto');
			}, 4000);
		} else {
			window.clearTimeout(window['stageTimeout' + stage]);
		}
		
	};
	

	window.addPreloader = function(stage) {
		window.animatePreloader = function(stage) {
			var s = $('#stage-' + stage);
			var h = 40;
			var o = s.find('.stage-preloader').data('bgoffset') - h;
			if (o <= -480) o = 0;
			s.find('.stage-preloader').css('background-position', '0 ' + o + 'px');
			s.find('.stage-preloader').data('bgoffset', o);
		}
		var s = $('#stage-' + stage);
		s.find('.stage-preloader').data('bgoffset', 0);
		window['preloaderInterval' + stage] = window.setInterval(window.animatePreloader, 50, stage);
	}
		
	var b = 0;
	$('.stage').each(function() {
		$(this).attr('id', 'stage-' + b);
		$(this).data('count_slides', $(this).find('.slide').length);
		$(this).data('current_slide', -1);
		$(this).data('slides_loaded', 0);
		$(this).data('state', 'init');
		if ($.browser.msie===true) {
			$(this).find('.slide img').each(function(){
			var ts = new Date().getTime();
			var s = $(this).attr('src')+'?'+ts;
			$(this).attr('src',s);
		});
	}
	
	if ($(this).find('.slide').length > 1) {
		$(this).find('.slide img').each(function() {
			if (this.complete) {
				var s = $(this).parents('.stage');
				var tmp = s.data('slides_loaded') + 1;
				//$(this).parents('.slide').hide();
				s.data('slides_loaded', tmp);
				if (tmp == s.data('count_slides')) {
				    s.find('.slides').css('visibility', 'visible');
				    s.find('.nav-stage').css('visibility', 'visible').hide().fadeIn('normal');
				    s.find('.stage-preloader').remove();
				    var id = s.attr('id').replace(/stage-/, '');
				    clearInterval(window['preloaderInterval' + id]);
				    if (s.data('count_slides') == 1) {
				        s.find('.slide:first-child').show();
				    } 
				    else {
				        window.changeSlide(id, 'auto');
				    }
			}
		} 
		else {
		    $(this).load(function(){
		    	var s = $(this).parents('.stage'); 
		    	var tmp = s.data('slides_loaded') + 1;
		    	//$(this).parents('.slide').hide();
		    	s.data('slides_loaded', tmp);
		    	if (tmp == s.data('count_slides')) {
		    	    s.find('.slides').css('visibility', 'visible');
		    	    s.find('.nav-stage').css('visibility', 'visible').hide().fadeIn('normal');
		    	    s.find('.stage-preloader').remove();
		    	    var id = s.attr('id').replace(/stage-/, '');
		    	    clearInterval(window['preloaderInterval' + id]);
		    	    if (s.data('count_slides') == 1) {
		    	        s.find('.slide:first-child').show();
		    		} else {
		    			window.changeSlide(id, 'auto');
		    		}
				}
			});
		}
	});
	
	$(this).append('<div class="nav-stage"><ul></ul></div>');
	c = 0;
	window.addPreloader(b);
	$(this).find('.slide').each(function() {
		$(this).attr('id', 'slide-' + b + '-' + c);
		$(this).parents('.stage').find('.nav-stage ul').append('<li id="item-' + b + '-' + c + '">&nbsp;</li>');
		if (c == 0) {
			$(this).addClass('fg').show();
			$('.slide:first-child').css('z-index', 1);
			$(this).parents('.stage').find('.nav-stage ul li#item-' + b + '-' + c).addClass('active');
		} 
		else if (c == 1) {
			$(this).addClass('bg');
		}
		$(this).parents('.stage').find('.nav-stage ul li#item-' + b + '-' + c).click(function() {
			var id = $(this).attr('id').replace(/item-/, '').split('-');
			window.changeSlide(id[0], id[1]);
		});
	c++;
	});
	} else {
		$(this).find('.slide').show();
		$(this).find('.slides').css('visibility', 'visible');
		$(this).find('.stage-preloader').remove();
		}
	b++;
	}); 
	
	/*--------------------------------- PALLMANN CODE ENDE ---------------------------------*/
	
	
	$('.col.right a:not(.newsthumbnail)').has('img').addClass('content-image');
	
	/* This is basic - uses default settings */
	
	$("a#single_image").fancybox();
	
	/* Using custom settings */
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	/* Apply fancybox to multiple items */
	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$('.gallery_thumbnail').fancybox({
		'hideOnContentClick': true
	});
	
	$('.content-image').fancybox({
		'hideOnContentClick': true
	});

	$('.reseller-logo img').each(function(){
		var w = $(this).width();
		var h = $(this).height();
		var l = Math.round((180-w)/2);
		var t = Math.round((180-h)/2);
		$(this).css({'margin-top':t+'px','margin-left':l+'px'});
	});	
	
	$('.sub-menu').hover(function(){
		$(this).parents('li').addClass('hovered');
	},function(){
		$(this).parents('li').removeClass('hovered');
	});

	$('.button-simple.red').append('<span class="right"></span>');
	
	if ($('body').hasClass('single-veranstaltung')){
		$('.newsitem').append('<a style="float: left; width: 100%; margin-top: 20px" href="javascript:history.back();">&lsaquo; Zurück zur Übersicht</a>');
	}
	if ($('body').hasClass('single-pressestimme')){
		$('.newsitem').append('<a style="float: left; width: 100%; margin-top: 20px" href="javascript:history.back();">&lsaquo; Zurück zur Übersicht</a>');
	}
	
	$('.box.login p br').remove();
	
	function positionlabel (){
		var w = $('.marker-label').width();
		var tmp_w = w / 2;
		tmp_w = tmp_w - 2;
		$('.marker-bottom').css('margin-left',tmp_w);
	}
	
	positionlabel();
	
	var posclicked = 0;
	
	$('body.page-id-27').each(function(){
		$(this).find('.deutschlandkarte .marker').each(function(){
			var id = $(this).attr('id').replace(/location-/,'');
			$(this).click(function(){
				posclicked = 1;
				$(this).parents('.two-col').find('.col.right .infobox').hide();
				$(this).parents('.two-col').find('.col.right .infobox#location-info-'+id).show();
			});
		});
		$('.deutschlandkarte .marker').tipsy({gravity: 's', fade: true});
	});
	
	if (posclicked==0){
		//alert("test");
		//$(this).parents('.two-col').find('.col.right .infobox#start').show();
	}
			
	if ($('body').hasClass('parent-pageid-44')==true & $('body').hasClass('page-id-386')==false){
		$('.content .col.right img').addClass('weincollage');
	}


 });

