
layerTimeoutImpressum = false;
layerTimeoutAgb = false;
layerTimeoutContact = false;

highestLevel = 100;

var bgImageRealWidth = 0;
var bgImageRealHeight = 0;

var objectInfoVisible = false;

var chosenWorkArea;

var slideshowStopped = false;

var slideshowTimeout;

function showInfoWindow(theWindow) {

	if(theWindow == 1) {
		
	}

	Effect.Appear('objectInfo', { duration: 0.2 } );
	objectInfoMoveable = true;
	document.getElementById('objectInfoContent').innerHTML = theWindow;
	objectInfoVisible = true;
}


function resetInfoWindow() {
	objectInfoVisible = false;
	Effect.Fade('objectInfo', { duration: 0.2 } );
}



function positionObjectInfo(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	
	if(objectInfoVisible) {
		document.getElementById('objectInfo').style.left = posx + 20 + "px";
		document.getElementById('objectInfo').style.top = posy + 20 + "px";
	}
}


//document.onmousemove = positionObjectInfo;

//On load page, init the timer which check if the there are anchor changes each 300 ms
jQuery(document).ready(function(){
	//$.ajaxSetup({cache:false});
	
	$.prettyLoader();
	
	$(window).resize(function() {
		updateBgImageSize();
	});
	
	updateBgImageSize();
	
	$("#switcher").click(function() {
		changeWorkArea();
	});
	

	if(!$.cookie("chosenWorkArea")) {
		chosenWorkArea = "commercial";
		selectWorkArea(chosenWorkArea);
		$("#switcher_private").addClass("switcher_private_off");
		$("#switcher_commercial").addClass("switcher_commercial_on");
	} else {
		chosenWorkArea = $.cookie("chosenWorkArea");
		if(chosenWorkArea == "commercial") {
			$("#switcher_private").addClass("switcher_private_off");
			$("#switcher_commercial").addClass("switcher_commercial_on");
			chosenWorkArea = "commercial";
		} else {
			$("#switcher_commercial").addClass("switcher_commercial_off");
			$("#switcher_private").addClass("switcher_private_on");
			chosenWorkArea = "private";
		}
	
	}
	
});


function selectWorkArea(theArea) {
	$.cookie("chosenWorkArea", theArea, { path: '/' });
	document.location.href="/#/areaChanger";
}


function changeWorkArea() {

	safeChosenWorkArea = chosenWorkArea;

	$("#switcher_private").removeClass("switcher_private_on");
	$("#switcher_commercial").removeClass("switcher_commercial_on");
	$("#switcher_private").removeClass("switcher_private_off");
	$("#switcher_commercial").removeClass("switcher_commercial_off");
	
	if(chosenWorkArea == "private") {
		chosenWorkArea = "commercial";
	} else {
		chosenWorkArea = "private";
	}
	
	changeSwitcher();
	
	$.cookie("chosenWorkArea", chosenWorkArea, { path: '/' });
	
	document.location.href="/#/areaChanger";
	
}

function changeSwitcher() {
	if(chosenWorkArea == "commercial") {
		$("#switcher_private").addClass("switcher_private_off");
		$("#switcher_commercial").addClass("switcher_commercial_on");
		chosenWorkArea = "commercial";
	} else {
		$("#switcher_commercial").addClass("switcher_commercial_off");
		$("#switcher_private").addClass("switcher_private_on");
		chosenWorkArea = "private";
	}
}

function updateBgImageSize() {
	$("#bgImage").removeAttr("width"); 
	$("#bgImage").removeAttr("height");

	
	var myWindowHeight = $(window).height();
	var myWindowWidth = $(window).width();
	
	var windowProportions = myWindowWidth / myWindowHeight;
	var imageProportions = bgImageRealWidth / bgImageRealHeight;
	
	if(windowProportions < imageProportions) {
		// Querformat
		newImageHeight = myWindowHeight;
		newImageWidth = myWindowHeight * imageProportions;
	} else {
		// Hochformat
		newImageWidth = myWindowWidth;
		newImageHeight = myWindowWidth / imageProportions;
	}
	
	
	$("#mainstageImage").css("width",newImageWidth);
	$("#mainstageImage").css("height",newImageHeight);
	
	$("#bgImage").css("width",newImageWidth);
	$("#bgImage").css("height",newImageHeight);
}

function navoverImage(theImage) {
	document.getElementById(theImage).src = document.getElementById(theImage).src.replace("_aus","_over");
}

function navoutImage(theImage,urlWord) {
	if(urlWord != newSection) {
		document.getElementById(theImage).src = document.getElementById(theImage).src.replace("_over","_aus");
	}
}


function setWindowTitle(theTitle) {
	document.title = theTitle;
}

function overImage(theImage) {
	document.getElementById(theImage).src = document.getElementById(theImage).src.replace("_off","_on");
}
function outImage(theImage) {
	document.getElementById(theImage).src = document.getElementById(theImage).src.replace("_on","_off");
}


function skipIntro() {
	$('#logoLarge').fadeOut("slow", function() {
	});
	$('#willkommenHolder').fadeOut("slow", function() {
	});
}

function loadingDone() {
	changeNavImage(newSection);
	changeImageLoop(newSection);
	$('#textcontent').fadeIn("slow", function() {
		changeImageLoop(newSection);
	});
}

function getNavWordFromNavSection(theSection) {
	
	for (var i = 0; i < navArray.length; i++) {
		theNavWord = navArray[i][0];
		theNavSection = navArray[i][2];
		if(theNavSection == theSection) {
			return theNavWord;
		}
	}
	
	
}



function resetNavImage(theSection,theNavIndex) {
	theNavContainer = "#nav_"+theSection;
	theNavImageName = "#navImage_"+theSection;
	theNavWord = getNavWordFromNavSection(theSection);
	theNavImageAddress = "/images/navimage.php?string="+theNavWord+"&navstatus=aus";
	
	$(theNavContainer).css("background-image","url('/images/navhg.png')");
	$(theNavContainer).css("background-color","#ffffff");
	
	$(theNavImageName).attr("src",theNavImageAddress);
	
	//console.log(theNavImageName);
	//console.log(theNavImageAddress);
}



function activateNavImage(theSection,theNavIndex) {
	theNavContainer = "#nav_"+theSection;
	theNavImageName = "#navImage_"+theSection;
	theNavWord = getNavWordFromNavSection(theSection);
	theNavImageAddress = "/images/navimage.php?string="+theNavWord+"&navstatus=an";
	
	$(theNavContainer).css("background-image","url('/images/navhg_on.png')");
	$(theNavContainer).css("background-color","#0f5680");
	
	$(theNavImageName).attr("src",theNavImageAddress);
}


function changeNavImage(theSection) {
	
	for (var i = 0; i < navArray.length; i++) {
		theNavWord = navArray[i][0];
		theNavSection = navArray[i][2];
		if(theNavSection != theSection) {
			resetNavImage(theNavSection,i);
		} else {
			activateNavImage(theNavSection,i);
		}
	}
	
}


function changeImageLoop(theSection) {
	
}


function imageMouseZoomer(theImage) {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	} else {
		$('#imageContainer').stop(true, true).fadeIn("slow");
	
		document.getElementById("imageContainer").innerHTML = "<img src="+theImage+" border=\"0\">";
		
		$(document).mousemove(function(e){
			$('#imageContainer').css("left",e.pageX+20);
			$('#imageContainer').css("top",e.pageY+20);
		});
	}
}


$(document).mouseleave(function() {
	imageMouseClearer();
});

function imageMouseClearer() {
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	} else {
		$('#imageContainer').stop(true, true).fadeOut("fast");
	}
}



function changeBackgroundImage(theImageName) {

	imageAddress = "/images/"+theImageName;
	var imagebg = $('<img />').attr('src', imageAddress);
	
	if($.browser.msie) {
		document.getElementById("bgImage").src = imageAddress;
	}
	
	if(!$.browser.msie) {
	$("#mainstageImage").fadeOut(200,function() {
		$('<img />')
		    .attr('src', imageAddress)
		    .attr('id', 'bgImage')
		    .load(function(){
		    	bgImageRealWidth = this.width;
		    	bgImageRealHeight = this.height;
				updateBgImageSize();
				$("#bgImage").attr('src', imageAddress);
				$("#mainstageImage").fadeIn(1000);
			});
		});
	}
	
}



var myTimeOut = "";

var areaChanged = false;

var newZ = 5;

var oldZ = 0;

var nextImage = 0;

var newSection;



function replaceImageWithMovie(movieDiv,movieAddressWithoutExtension,width,height) {
	newHtml = "<video id=\"movie\" width=\""+width+"\" height=\""+height+"\" controls autoplay>";
	newHtml += "<source src=\""+movieAddressWithoutExtension+".theora.ogv\" type='video/ogg; codecs=\"theora, vorbis\"'>";
	newHtml += "<source src=\""+movieAddressWithoutExtension+".mp4\" type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'>";
	newHtml += "<source src=\""+movieAddressWithoutExtension+".webm\" type='video/webm; codecs=\"vp8, vorbis\"'>";
	
	newHtml += "<object width=\""+width+"\" height=\""+height+"\" type=\"application/x-shockwave-flash\"";
	newHtml += "data=\""+movieAddressWithoutExtension+".swf\">";
	newHtml += "<param name=\"movie\" value=\""+movieAddressWithoutExtension+".swf\">";
	newHtml += "<param name=\"allowfullscreen\" value=\"true\">";
	newHtml += "<param name=\"wmode\" value=\"opaque\">";
	newHtml += "</object>";
	
	newHtml += "</video>";
	$('#'+movieDiv).html(newHtml);
}





function changeDivContentAndHideMoreButton(theDiv,theContent,theMoreButton) {
	$("#"+theDiv).html(theContent);
	$("#"+theMoreButton).html('');
}






function initSection(theSection) {
	
	if(theSection == "customers") {
		$("#ffCustomers").fadeIn(300);
	}
	
	if(theSection == "movie") {
		$("#ffMovie").fadeIn(300);
	}
	
	if(theSection == "home") {
    	$("#switcher").hide();
    	$("#mainstageImage").hide();
    	$("#pagefooter").hide();
    	$("#homeImage").fadeIn(300);
	}
	
	$(".textcontent").delay(300).fadeIn(200);
	
}
