intro = {
	page: 'polsterei/wir.php',
	preloadImages: ['intro_1_back.png', 'intro_2_back.png', 'intro_4_back.png', 'intro_5_back.png', 'intro_6_back.png', 'intro_8_back.png', 'intro_2.jpg', 'intro_3.jpg', 'intro_4.jpg', 'intro_5.jpg', 'intro_6.jpg', 'intro_7.jpg', 'intro_8.jpg', 'intro_9.jpg', 'intro_10.jpg'  ],
	preloadedImages: 0,
	
	order: ['1_2', '2_2', '2_1', '2_3', '3_2', '1_1', '1_3', '3_1', '3_3'],
	
	startIntro: 2500,
	pauseSlow: 800,
	pauseFast: 100,
	fadeDurationSlow: 600,
	fadeDurationFast: 10,
	jumpDuration: 3000,
	countSlowFade: 5,	
	e: -1,
	
	
	preload: function() {
		$('.skip').hide();
		$(intro.preloadImages).each(function(idx, url) {
			var img = new Image();
			img.onload = intro.imagePreloaded;
			img.src = '_gfx/images/'+url;
		});
	},
	imagePreloaded: function() {
		intro.preloadedImages++;
		if (intro.preloadedImages == intro.preloadImages.length) intro.init();
	},
	
	init: function() {
		$('#loading').hide();
		$('.skip').css({display: 'block'});
		$('#middle table').css({display: 'block'});
		$.each($('#middle table td'), function() {
			$(this).bind('click', intro.startPage);
		});
		
		window.setTimeout('intro.nextFadeOut();', intro.startIntro);
	},
	
	nextFadeOut: function() {
		intro.e++;
		if (intro.e<intro.order.length && intro.e <= intro.countSlowFade) window.setTimeout('intro.fadeOut();', intro.pauseSlow);
		else if (intro.e<intro.order.length && intro.e > intro.countSlowFade) window.setTimeout('intro.fadeOut();', intro.pauseFast);
		else window.setTimeout('intro.startPage();', intro.jumpDuration);
	},
	
	fadeOut: function() {
		//$('td.t'+intro.order[intro.e]+' div').fadeOut(intro.fadeDuration, intro.nextFadeOut);
		
		if (intro.e <= intro.countSlowFade) {
			$('td.t'+intro.order[intro.e]+' div').fadeOut(intro.fadeDurationSlow);
			window.setTimeout('intro.nextFadeOut();', 100);
		} else {
			$('td.t'+intro.order[intro.e]+' div').fadeOut(intro.fadeDurationFast);
			window.setTimeout('intro.nextFadeOut();', 10);
		}
		//$('td.t'+intro.order[intro.e]+' div').fadeOut(intro.fadeDuration1);
		//window.setTimeout('intro.nextFadeOut();', 100);
	},
	startPage: function() {
		//automatische Weiterleitung	
		document.location.href=intro.page;
	}
}

$(document).ready(intro.preload);
