$(document).ready(function(){
	// Tabs
	$('.tabList').each(function(c, tablist){
		$(this).find('.tabs .tab:first').addClass('current');
		
		$(this).find('.tabContent').each(function(e) {
			if (e != 0) $(this).css({'display':'none'});
		});
		
		$(this).find('.tabs .tab').each(function(tab) {
			$(this).click(function() {
				$(tablist).find('.tabs .tab').removeClass('current');
				$(this).addClass('current');
				
				$(tablist).find('.tabContent').each(function(tabNumber) {
					if (tabNumber != tab) {
						$(this).css({'display':'none'});
					} else {
						$(this).fadeIn(200);
					}
				});
			});
		});
	});
	
	// Bundle Images
	$('ul.images').each(function(){
		$(this).find('li').each(function(c){
			$(this).css('display', 'none');
			$(this).css('position', 'absolute');
		});
		var dummy = $(this).find('li:first').html();
		$(this).prepend('<li>'+dummy+'</li>');
	});
	
	
	// Suchfeld
	var query = 'Suchbegriff eingeben...';
	$('#query').attr('value', query).css('color', '#949597');
	
	$('#query').focus(function() {
		if ($(this).attr('value') == query) {
			$(this).attr('value', '').css('color', '#2a2a2a');
		}
	});
	
	$('#query').blur(function() {
		if ($(this).attr('value') == '') {
			$(this).attr('value', query).css('color', '#949597');
		}
	});
	
	
	// Schnellauswahl
	$('#sub').css('display', 'none');
	$('#quickselect').change(function(){
		top.location.href = $(this).attr("value");
	});
	
	
	// Zusammenklappbare Felder in Formularen
	$('.collapsible').each(function(e) {
		var legend = $(this).find('legend');
		
		$(this).find('*').css('display', 'none');
		legend.css({
					'display': 'inline-block',
					'cursor': 'hand'
					});
		
		legend.append(' <small>(Hier klicken um die Option anzuzeigen)</small>');
		
		legend.click(function() {
			$(this).parent().find('*').fadeIn();
		});
	});
});


var count = 0;

$(document).ready(window.setInterval(animateImages, 3000));
	function animateImages() {
		// Bundle Images
		$('ul.images').each(function(){
			$(this).find('.tempImage').remove();
			
			var images = [];
			$(this).find('li').each(function(c){
				if(c > 0) {
					images[c-1] = $(this).find('img').attr('src');
				}
			});
			var previousImage = images[count % images.length];
			var currentImage = images[(count+1) % images.length];
			
			$(this).append('<li style="position:absolute;opacity:1" class="tempImage"><img src="'+previousImage+'" width="141" height="156" alt="" class="thumbnail" /></li>');
			
			$(this).delay(1500).find('li:first img').attr('src', currentImage);
			
			$(this).find('.tempImage').fadeIn(0).fadeOut(800);
		});
		count++;
	}

