var imagesLoaded = 0;

preloadImages = function()
{
	for (var i=0; i<preload.length; i++) {
		var img = $('<img src="' + preload[i] + '" />');
			img.load(function() {
				imagesLoaded ++;
				if (imagesLoaded >= preload.length) {
					show();
				}
			})
	}
}

setBackgroundVideo = function()
{
	$('#officeBackground').flash({
		swf: swfPath + 'background.swf',
		width: '100%',
		height: '70%',
		scale: 'exactfit',
		wmode: 'opaque'
	});
}

updateItems = function()
{
	$('#clickArea').css('display', 'block');
	$('#contentFader').hide();
}

slideSwitch = function() 
{
	var $active = $('#officeMonitorContent img.active');
	if ( $active.length == 0 ) $active = $('#officeMonitorContent img:last');
	var $next =  $active.next().length ? $active.next() : $('#officeMonitorContent img:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {$active.removeClass('active last-active');});
}

show = function()
{
	for (var i=0; i<images.length; ++i) {
		var imageClass = (i==0) ? 'active' : '';
		var image = $('<image src="' + imagePath + images[i] + '" class="' + imageClass + '" />');
		$('#officeMonitorContent').append(image);	
	}
	
	
	/*	
	var image = $('<a class="desktopItem" title="H&uuml;ttenzauber" href="/promotion"><image src="' + imagePath + 'slideshow/Slide_Raclette.jpg' + '" class="' + '' + '" /></a>');
	$('#officeMonitorContent').append(image);	
	var notice = $('<span class="notice"></span>');
	$('#officeMonitor').append(notice);
	*/
	
	var showSplashScreen = true;


	if (intro == '1') {
  		$('#officeMonitor').css({zIndex: 500, marginLeft: -263, display: 'block'});
		$('#desktopObjects').show().css({left: 0});
		setInterval('slideSwitch()', slideInterval);
		updateItems();
	} else {
		var ablauf = new Date();
		document.cookie = ablauf.getTime();
		
		$('#officeMonitor').css({zIndex: 80, marginLeft: 2000}).show();
		
		if(showSplashScreen)
			$('#splashscreen').show().delay(splashScreenDisplay).fadeOut(250);
		else
			splashScreenDisplay = 0;
		
		$('#contentFader').delay(splashScreenDisplay).fadeOut(250, function() {
			$('#desktopObjects').show().delay(100).animate({left: 0}, 750, 'easeOutCirc');
			$('#officeMonitor').css({zIndex: 500}).delay(100).animate({marginLeft: -263}, 750, 'easeOutCirc', function() {
				if ($('#officeMonitorContent img').length > 1) {
					setInterval('slideSwitch()', slideInterval);
				}
			});
			updateItems();
		});
	}

	if (!isTouchDevice) {
		$('.desktopItem').mouseover(function() {
			if ($(this).attr('rel') && $(this).attr('rel') != 'buzzer') {
				var relId = $(this).attr('rel');
				var relObj = $('#'+relId);
				if (animationMargins[relId] != null) {
					relObj.stop().animate({marginBottom: animationMargins[relId] + 5}, 250);
				}
			}
			
			showTooltip($(this));
		})
		$('.desktopItem').mouseout(function() {
			if ($(this).attr('rel') && $(this).attr('rel') != 'buzzer') {
				var relId = $(this).attr('rel');
				var relObj = $('#'+relId);
				if (animationMargins[relId] != null) {
					relObj.stop().animate({marginBottom: animationMargins[relId]}, 250);
				}
			}
			hideTooltip($(this));
		})
		
		$('.desktopItem[rel="buzzer"]').mousedown(function(){
			$('#buzzer').addClass('active');
		});
		$('.desktopItem[rel="buzzer"]').mouseup(function(){
			$('#buzzer').removeClass('active');
		});
	}
	
	//setBackgroundVideo();
}

$(document).ready(function() {
	$('#clickArea').css('display', 'none');
intro = '0';
	if (intro == '0') {
		$('#contentFader').css('opacity', .8).show();
	}
	preloadImages();
	//window.resizeTo(1024, 768);

	if (!$.browser.mozilla) {
		if ($.flash.available) {
			$('#officeBackground').flash({
				swf: 'common/video/header.swf',
				height: "100%",
				width: "100%",
				wmode: 'transparent',
				scale: 'exactfit'
			});
		} else {
			$('#officeBackground').html('<video src="common/video/header.mp4" width="100%" height="100%" autoplay loop></video>')		
		}
	}	
});

