$(document).ready(function() {
	
	var wi = $(window).width();
	if (wi <= 520) {
		$('.anythingSlider .bigtext h1').each(function(){
			$(this).append($(this).parent().next('.box').html());
			$(this).parent().next('.box').empty();
		});
	}
	$('.anythingSlider, .anythingSlider .wrap, .anythingSlider .wrap .placer').css('width',wi+'px');
	$(window).resize(function() {
		var nwi = $(window).width();
		$('.anythingSlider, .anythingSlider .wrap, .anythingSlider .wrap .placer').css('width',nwi+'px');
		if (wi <= 520) {
			$('.anythingSlider .bigtext h1').each(function(){
				$(this).append($(this).parent().next('.box').html());
				$(this).parent().next('.box').empty();
			});
		}
	});
	
	$('.anythingSlider').anythingSlider({
		easing: "linear",                // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
		delay: 9000,                    // How long between slide transitions in AutoPlay mode
		animationTime:  1000,             // How long the slide transition takes
		hashTags: false,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "",           		// Start text
		stopText: "",               // Stop text
		navigationFormatter: null       // Details at the top of the file on this use (advanced use)
	});
	
	$('#referenz img').each(function(index) {
		$('#referenz .counter').append('<span class="count">x</span>');
		if (index == 0) {
			$('#referenz .count').addClass('active');
		}
	});
	
	$('#referenz img').click(function() {
		$(this).next('img').addClass('active');
		if ($(this).next().hasClass('active')) {
			$(this).removeClass('active');
			$('referenz .counter span').removeClass('inactive');
			$('#referenz .counter .active').addClass('inactive');
			$('#referenz .counter span').removeClass('active');
			$('#referenz .counter .inactive').next('span').addClass('active');
		}
		else {
			$(this).removeClass('active');
			$('#referenz img:first-child').addClass('active');
			$('#referenz .counter span').removeClass('active');
			$('#referenz .counter span').removeClass('inactive');
			$('#referenz .counter span:first-child').addClass('active');
		}
	});
});
