/*
	BEVOR DIESE DATEI EINGEBUNDEN WIRD MUSS jquery-1.3.2.js 
	EBENFALLS IN DAS DOKUMENT EINGEBUNDEN WERDEN!
*/


/*
	Das Array bgs:
	Beinhaltet fŸr jede Seite Informationen, welche Bilder verwendet werden
	und an welcher Stelle die Inhaltsbox angezeigt wird.
*/
var oldScreenWidth = 0;
var oldScreenHeight = 0;
var fusszeile = "";


var bgs = new Array();
/*
	bgs["beispiel"] = new Array(
						new Array("bilddateiname", "top-Wert", "left-Wert", "Alpha-Wert"),
						new Array("bild_4.jpg", "50px", "100px", "0.5"),
						Hšhe des Anzeigefensters
						);
*/

    bgs["index.php"] = new Array(
						new Array("bollewick.jpg", "150px", "80px", "0.5"),
						200
						);
    bgs["buero.php"] = new Array(
						new Array("bollewick.jpg", "300px", "70px", "0.8"),
						200
						);
    bgs["shaack.php"] = new Array(
						new Array("bild_32.jpg", "25px", "25px", "0.8"),
						200
						);
    bgs["team.php"] = new Array(
						new Array("bild_14.jpg", "300px", "20px", "0.8"),
						200
						);
    bgs["sundp.php"] = new Array(
						new Array("bild_18.jpg", "300px", "25px", "0.8"),
						220
						);
    bgs["bundp.php"] = new Array(
						new Array("bild_22.jpg", "150px", "25px", "0.4"),
						200
						);



function randomBG(filename) {
	var picname = "";
	var refPicNum = 0; 
	var contentBoxHeight = "400px";
	//alert(filename);
	do {
		if(filename == "") {
			refPicNum = Math.round(Math.random() * (bgs["index.php"].length-2));
			attributes = bgs["index.php"][refPicNum];
			contentBoxHeight = bgs["index.php"][bgs["index.php"].length-1];
		} else {
			refPicNum = Math.round(Math.random() * (bgs[filename].length-2));
			var attributes = bgs[filename][refPicNum];
			contentBoxHeight = bgs[filename][bgs[filename].length-1];
		}
		picname = attributes[0];
		$("#fusszeile").text(attributes[4]);
	} while (picname == bgs[dateinameReferrer()][refPicNumGet][0] && bgs[dateinameReferrer()].length > 2); // ein Bild soll nicht doppelt angezeigt werden
	$(document).ready(function(){
		var bild = new Image();
		bild.src = "img/bgs/"+picname;
		document.getElementById('backgroundimage').src = bild.src;
	});
	//alert(picname);
}

function autoFitBackgroundImage() {
	var box_left = $("#bg-left-container");
	var box_right = $("#bg-right-container");
	var picture_left = $("#background-left");
	var picture_right = $("#background-right");
	var screenHeight = 0;
	var screenWidth = 0;
//	alert(i);
	if(navigator.userAgent.indexOf("irefox") > -1) {
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	} else {
		screenWidth = $(window).width();
		screenHeight = $(window).height();	
	}
//	alert($(window).height());
	if(oldScreenWidth != screenWidth || oldScreenHeight != screenHeight) {
		oldScreenWidth = screenWidth;
		oldScreenHeight = screenHeight;

		if(screenHeight > 545) {
			var seitenVerhaeltnis = 71/screenHeight;
			var seitenVerhaeltnisBild = 71/545;
			box_left.attr('height', screenHeight);
//			alert(screenHeight);
			if (screenHeight*seitenVerhaeltnisBild >= 71) {
				picture_left.attr('width', screenHeight*seitenVerhaeltnisBild);
				picture_left.attr('height', screenHeight);
			}
		}
		
		if(screenHeight > 545) {
			var seitenVerhaeltnis = (screenWidth-274)/screenHeight;
			var seitenVerhaeltnisBild = 750/545;
			box_right.attr('width', screenWidth-274);
			box_right.attr('height', screenHeight);
			if(seitenVerhaeltnis<=seitenVerhaeltnisBild) {
				picture_right.attr('width', screenHeight*seitenVerhaeltnisBild);
				picture_right.attr('height', screenHeight);
			}else {
				picture_right.attr('width', screenWidth-274);
				picture_right.attr('height', (screenWidth-274)/seitenVerhaeltnisBild);
			}
		}
	}
	if(screenHeight < 590) {
		$("body").css("overflow","auto");
		$("html").css("overflow","auto");
	} else {
		$("body").css("overflow","hidden");	
		$("html").css("overflow","hidden");	
	}
}

function calculateRatio(picWidth, picHeight) {
	var screenHeight = 0;
	var screenWidth = 0;
	if(navigator.userAgent.indexOf("irefox") > -1) {
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	} else {
		screenWidth = $(window).width();
		screenHeight = $(window).height();	
	}
	var seitenVerhaeltnis = screenWidth/screenHeight;
	var seitenVerhaeltnisBild = picWidth/picHeight;

	if(seitenVerhaeltnis<=seitenVerhaeltnisBild) {
		return new Array(screenHeight*seitenVerhaeltnisBild, screenHeight);
	}else {
		return new Array(screenWidth, screenWidth/seitenVerhaeltnisBild);
	}
}

function setPosition (filename) {
	var attributes = null;
	var contentBoxHeight = "400px";
	if(filename == "") {
		attributes = bgs["index.php"][refPicNumGet];
		contentBoxHeight = bgs["index.php"][bgs["index.php"].length-1];
	} else {
		attributes = bgs[filename][refPicNumGet];
		contentBoxHeight = bgs[filename][bgs[filename].length-1];
	}
	$("#main-container").css("top",attributes[1]);
	$("#main-container").css("left",attributes[2]);
	$("#main-container").css("height",(contentBoxHeight+vertikaleKorrektur)+"px");
	$("#text").css("height",contentBoxHeight+"px");
	$("#content-inner-container").css("height",contentBoxHeight+"px");
	$("#content-inner-container").css("opacity",attributes[3]);
	$("#main-container").css("visibility", "visible");
}

//////////////////////////////////////////////
// Gibt Dateinamen der aktuellen Datei zurŸck
function dateinameReferrer() {
	var strFilename;
	var strHref = "";
	if(document.referrer != "") {
		strHref = document.referrer;
	} else {
		strHref = self.location.href;	
	}
	strHref = strHref.replace(/\//g,"\\");
	var iIdx = strHref.lastIndexOf("\\");
	if (-1 < iIdx) {
		strFilename = strHref.substring(iIdx+1);
	} else {
		strFilename = strHref;
	}
	if(strFilename.split("?")[0] != "") {
		return strFilename.split("?")[0];
	} else {
		return "index.php";
	}
}
//////////////////////////////////////////////

//////////////////////////////////////////////
// Gibt Dateinamen der aktuellen Datei zurŸck
function dateiname() {
	var strFilename;
	var strHref = self.location.href;
	strHref = strHref.replace(/\//g,"\\");
	var iIdx = strHref.lastIndexOf("\\");
	if (-1 < iIdx) {
		strFilename = strHref.substring(iIdx+1);
	} else {
		strFilename = strHref;
	}
	if(strFilename.split("?")[0] != "") {
		return strFilename.split("?")[0];
	} else {
		return "index.php";
	}
}
//////////////////////////////////////////////

function projektShow(projektid) {
	document.getElementById(projektid).style.display = "block";
	document.getElementById("projekt-starttext").style.display = "none";
	document.getElementById(projektid+"link").style.color = "#aaaaaa";
}

function projektHide(projektid) {
	document.getElementById(projektid).style.display = "none";
	document.getElementById("projekt-starttext").style.display = "block";
}
