// main.js
// copyright oestreicher & wagner

function detectBrowser() {
	var agent	=	navigator.userAgent.toLowerCase();
	this.major	=	parseInt(navigator.appVersion);
	this.minor	=	parseFloat(navigator.appVersion);
	this.ns		=	((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
	this.mozComp	=	((agent.indexOf("gecko") != -1 || agent.indexOf('mozilla')!=-1) && (this.major >= 5));
	this.ie		=	(agent.indexOf("msie") != -1);
	this.op3	=	(agent.indexOf("opera") != -1);
	this.win	=	(agent.indexOf("win")!=-1);
	this.mac	=	(agent.indexOf("mac")!=-1);
	this.unix	=	(agent.indexOf("x11")!=-1);
	this.w3c	=	document.documentElement;

	return this;
}
ready = false;
// initialize browser object
is = new detectBrowser();

aLayers = new Array();
var toppos = 127+84;
if (is.mac && is.ie) toppos = toppos-126;

function SpaltenFaerben(farbe,spalte) {
	if (document.getElementById && ready) {
		document.getElementById(spalte).style.backgroundColor = farbe;
	}
}

function showLayer(arg) {
	if (document.getElementById && ready) {
		hideLayer(arg);
		if (arg == 0) arg = aLayers[0];
		document.getElementById(arg).style.visibility = "visible";
	}
}

function hideLayer(arg) {
	if (document.getElementById && ready) {
		if (arg == 0) arg = aLayers[0];
		for (i = 0; i < aLayers.length; i++) {
		if (aLayers[i] != arg) document.getElementById(aLayers[i]).style.visibility = "hidden";
		}
	}
}

// necessary for some mozilla versions
function reset() {
	if (checkMOZ()) { 
		for (var i = 0; i < aLayers.length; i++) {
			document.getElementById(aLayers[i]).style.position = 'relative';
			document.getElementById(aLayers[i]).style.position = 'absolute';
		}
	}
}

function checkMOZ() {
	if (!document.layers && !is.ie && is.w3c && !is.op3 && is.mozComp) {
		return true
	} else {
		return false
	}
}

function SendSchnellzugriff() {
	document.schnellzugriff.submit();
}

// system globals
var highestVersion = 6;	// highest version we can actually detect
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

function flashObject(){
	this.highestVersion=highestVersion; // Change this to highest version available
	this.isFlashInstalled=isFlashInstalled;
	this.getFlashVersion=getFlashVersion;
	this.setFlashPage=setFlashPage;
	this.setNonFlashPage=setNonFlashPage;
	this.setUpgradeFlashPage=setUpgradeFlashPage;
	this.flashVersionThroughVBscript=flashVersionThroughVBscript; // for IE on windows

	this.flashInstalled=false;
	this.flashVersion=0;
}

function isFlashInstalled(){
	var flashVersion = this.getFlashVersion();
	var returnVal=(flashVersion>1)?true:false;
	this.flashInstalled=returnVal;
	return returnVal;
}
function getFlashVersion(){
	var flashVersion = 0;
	if (navigator.plugins){
		if (navigator.plugins["Shockwave Flash 2.0"] 	// yes>> then is Flash 2
		|| navigator.plugins["Shockwave Flash"]){		// or flash 3+ installed?

			// set convenient references to flash 2 and the plugin description
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			// a flash plugin-description looks like this: Shockwave Flash 4.0 r5
		 flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		}else{
			if(isIE && isWin){ // don't write vbscript tags on anything but ie win
				flashVersion=this.flashVersionThroughVBscript();
			}
		}
	}
	// if we're on webtv, the version supported is 2 (pre-summer2000, or 3, post-summer2000)
	if(navigator.userAgent.indexOf("WebTV") != -1) flashVersion = 2;
	this.flashVersion=flashVersion;
	return flashVersion;
}
function flashVersionThroughVBscript(){
	 var flashVersion=0;
	 // VERY IMPORTANT
	 // these are global so that same variables can be shared between
	 // VBscript and Javascript
	 flash2Installed = false;		// boolean. true if flash 2 is installed
	 flash3Installed = false;		// boolean. true if flash 3 is installed
	 flash4Installed = false;		// boolean. true if flash 4 is installed
	 flash5Installed = false;		// boolean. true if flash 5 is installed
	 flash6Installed = false;		// boolean. true if flash 6 is installed
// write vbscript detection if we're not on mac.
	if(isIE && isWin){ // don't write vbscript tags on anything but ie win
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
	}
	if(isIE && isWin){ // don't write vbscript tags on anything but ie win
		for (var i = 2; i <= this.highestVersion; i++) {
			if (eval("flash" + i + "Installed") == true) flashVersion = i;
		}
	}
	return flashVersion;
}

// javascript should be >=1.1 otherwise replace command wont work.
function setFlashPage(flashPageURL,targetFrame){
	if(this.flashInstalled){
		if(targetFrame){
			targetFrame.location.replace(flashPageURL);
		}else{
			window.location.replace(flashPageURL);
		}
	}
}

function setNonFlashPage(nonFlashPageURL,targetFrame){
	if(!this.flashInstalled){
		if(targetFrame){
			targetFrame.location.replace(nonFlashPageURL);
		}else{
			window.location.replace(nonFlashPageURL);
		}
	}
}
function setUpgradeFlashPage(upgradeFlashPageURL,targetFrame,requiredVersion){
	if(this.flashInstalled && requiredVersion >this.flashVersion){
		if(targetFrame){
			targetFrame.location.replace(upgradeFlashPageURL);
		}else{
			window.location.replace(upgradeFlashPageURL);
		}
	}
}

var flashobj=new flashObject();
var flashInstalled=flashobj.isFlashInstalled();

function gotoMultimedial() {
	var currentPath = document.location.href;
	if (currentPath.indexOf("english") < 0) {
		var start = currentPath.indexOf("aktuelles");
		var prePath = currentPath.substring(0,start);
		document.location.href = prePath + 'bilderBerichteDokumente/multimedial/index.html';
	} else {
		var start = currentPath.indexOf("contemporaryIssues");
		var prePath = currentPath.substring(0,start);
		document.location.href = prePath + 'illustrationsDocumentation/multimedia/index.html';
	}
}

