function Intro() {
	
	
	//public properties
	this.active = false;
	
	//private properties
	var interval;
	var afterAnimationCalled = false;
	
	//public methods
	this.afterAnimation = function() {
		if (afterAnimationCalled) return;
		afterAnimationCalled = true;
		$('.bg-overlay').show();
		$('#header').fadeIn('normal', this.remove);
	}
	
	this.skip = function() {
		$('.bg-overlay, #header').show();
		this.remove();
	}

	this.remove = function() {
		this.active = false;
		$('#intro').remove();
	}
	
	this.startAnimation = function () {
		
		var movieName = "../intro/blume.swf";
		var flash = '<div id="intro"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="1512" height="1290" id="blume" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="' + movieName + '" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" />	<embed src="' + movieName + '" quality="high" scale="noscale" salign="lt" wmode="transparent" bgcolor="#ffffff" width="1512" height="1290" name="blume" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /></object></div>';

		$('.bg-overlay, #content, #header').hide();
		$('#menu .active').removeClass('active');
		$("body").append(flash);
		$("body").show();
	}
	
	
	//private methods
	var isRoot = function () {
		return document.location.href.match(/http:\/\/[^\/]*\/?$/i) ? true : false;
	}
	
	var hideWhenLoaded = function(selector) {
		var interval = setInterval(function(){
			if (!$(selector)) return;
			clearInterval(interval);
			$(selector).hide();
		}, 10);
	}
	
	var hideBodyWhenLoaded = function() {
		interval = setInterval(function(){
			clearInterval(interval);
			$("body").hide();
		}, 10);

	}
	
	
	//constructor
	if (!isRoot()) return;
	this.active = true;
//	hideBodyWhenLoaded();

}



//old intro------------------
/*function Intro() {
	//public properties
	this.active = false;
	
	//private properties
	var whiteStar = new Image();
	var src = '/white_star.png';
	var src2 = '/backgrounds/bg_vision_ol.jpg';
	var interval;
	
	//private methods
	var isRoot = function () {
		return document.location.href.match(/http:\/\/[^\/]*\/?$/i) ? true : false;
	}
	var startAnimation = function () {
		$('.bg-overlay').hide();
		$('#content').hide();
		$(document.body).show();
		$('#menu .active').removeClass('active');
		var startWidth = 50000;
		var endWidth = 813;
		var endTop = 247;
		var endLeft = 619;
		var startTop = parseInt(endTop - (startWidth - endWidth) / 2);
		var startLeft = parseInt(endLeft - (startWidth - endWidth) / 2);
		whiteStar.src = src;
		whiteStar.style.position = 'fixed';
		whiteStar.style.zIndex = 10;
		whiteStar.style.top = startTop + 'px';
		whiteStar.style.left = startLeft + 'px';
		whiteStar.style.height = startWidth + 'px';
		whiteStar.style.width = startWidth + 'px';
		document.body.appendChild(whiteStar);
		$(whiteStar).animate({
			'height': endWidth + 'px',
			'width': endWidth + 'px',
			'top': endTop + 'px',
			'left': endLeft + 'px'
		}, 2000, 'easeOutExpo', startFade);
	}
	var startFade = function () {
		$('.bg-overlay').show();
		$(whiteStar).fadeOut(2000);
	}
	
	//constructor
	if (!isRoot()) return;
	this.active = true;
	interval = setInterval(function(){
		if (!document.body) return;
		clearInterval(interval);
		$(document.body).hide();
		new Preloader(src, function(){
			new Preloader(src2, function(){
				setTimeout(startAnimation, 1000);
			});
		});
	}, 10);
	
}*/









function Background(){
}
//static properties
Background.path = "/backgrounds/";

//static methods
Background.fileEncode = function(filename) {
	filename = filename.toString();
	filename = filename.replace(/ä/g, 'ae');
	filename = filename.replace(/ö/g, 'oe');
	filename = filename.replace(/ü/g, 'ue');
	return filename;
}
Background.getBgFromPage = function(page) {
	return this.path + 'bg_' + this.fileEncode(page) + '.jpg';
}
Background.getOverlayFromPage = function(page) {
	return this.path + 'bg_' + this.fileEncode(page) + '_ol.jpg';
}
Background.getDiv = function(page) {
	var div = document.createElement('div');
	div.className = 'bg ' + page;
	var ol = document.createElement('div');
	ol.className = 'bg-overlay';
	div.appendChild(ol);
	return div;
}
Background.getColor = function() {
	var color = 'orange';
	$('#menu a').each(function () {
		if (this.href.match(/team/i) && $(this).hasClass('active')) color = 'white';
	});
	return color;
}







function Preloader(urls, callback, waitForCacheTime, callbackIfCached){

//private properties
	var images = [];
	var howManyLoaded = 0;
	var currentCallback, i;

//private methods	
	var setCallback = function () {
		currentCallback = callback;
	}
	
	var onload = function () {
		howManyLoaded++;
		if (howManyLoaded == urls.length) currentCallback();
	}

//constructor
	if (typeof(urls) == 'string') urls = [urls];
	
	waitForCacheTime || (waitForCacheTime = Preloader.stdWaitTime);
	callbackIfCached || (callbackIfCached = callback);
	
	currentCallback = callbackIfCached;
	setTimeout(setCallback, waitForCacheTime)

	for (i = 0; i < urls.length; i++) {
		images[i] = new Image();
		images[i].onload = onload;
		images[i].src = urls[i];
	}
}

//static properties
Preloader.stdWaitTime = 100; // time to wait for file to be served from cache before assuming it is not cached (in milliseconds)
//static methods
Preloader.executeIfLoaded = function (urls, callback, time) {
	if (typeof(time) != 'number') time = this.stdWaitTime;
	var preloader = new Preloader(urls, callback, time, function(){})
}
Preloader.executeIfNotLoaded = function (urls, callback, time) {
	if (typeof(time) != 'number') time = this.stdWaitTime;
	var loaded = false;
	var preloader = new Preloader(urls, function(){
		loaded = true;
	});
	var callAfterWait = function () {
		if (!loaded) callback();
	}
	setTimeout(callAfterWait, time);
}






function BgFader(el, page, alwaysFade){


//private properties
	var waitForCacheTime = Preloader.stdWaitTime; //wait time for pic to be served from cache before setting up animation (in milliseconds)
	var fadeTime = 2000; // fade time in ms
	var src, preloader;

//private methods
	var getSrc = function () {

		if (page) return getSrcFromPage(page);
		if (el.css('background-image') !== 'none') {
			return el.css('background-image').match(/http.*?(?=["\)])/i)[0];
		}
		
		//on document ready external css might not be loaded in safari
		else 
			return getSrcFromBodyId();
	}
	
	var getSrcFromBodyId = function () {
		return getSrcFromPage(document.body.id);
	}
	
	var getSrcFromPage = function (page) {
		return Background.getOverlayFromPage(page);
	}
	
	var fadeIn = function () {
		el.fadeIn(fadeTime);
	}
	
	var show = function () {
		el.show();
	}

//constructor
	el.hide();
	if (alwaysFade) preloader = new Preloader(getSrc(), fadeIn);
	else preloader = new Preloader(getSrc(), fadeIn, waitForCacheTime, show);
	
}








var akademie = {}; //global object

akademie.intro = (FlashDetect.installed && FlashDetect.major >= 9) ? new Intro() : {};

$(document).ready(function(){
	if (akademie.intro.active) {
		new Preloader(['../backgrounds/bg_vision.jpg', '../backgrounds/bg_vision_ol.jpg', '../logo_white.png'], akademie.intro.startAnimation);
		return;
	}
	$('body').show();
	var fader = new BgFader($('.bg-overlay'));
});

