//**** checks browsertype and os... returns an object
function checkBrowser(){
	this.ver = navigator.appVersion;
	this.dom = document.getElementById ? true:false;
	this.ie6 = (this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie55 = (this.ver.indexOf("MSIE 5.5")>-1 && this.dom)?1:0;
	this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4 = (document.all && !this.dom) ? 1:0;
	this.ie  = (this.ie5 || this.ie4 || this.ie55 || this.ie6);
	this.ns6 = (this.dom && parseInt(this.ver) >= 5 && !this.ie6 && !this.ie5 && !this.ie55 ) ? 1:0;
	this.ns4 = (document.layers) ? 1:0;
	this.ns  = (this.ns4 || this.ns6);
	this.opera  = (this.ver.indexOf("Opera")>-1 || navigator.userAgent.indexOf("Opera")>-1) ? 1:0;
	this.os  = (this.ver.indexOf("Macintosh")>-1)? "mac":"pc";
	this.support = (this.dom);
	if(this.ie) this.browserApdx="ie";
	if(this.ns) this.browserApdx="ns";
	this.browserApdx+='_'+this.os;
	this.swf=false;
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) this.swf=true;
	if(this.ie && this.os=='pc'){
		result = false;document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.1"))</SCRIPT>\n');
		if (result) this.swf=true;
	}
	if(this.ie && this.os=='mac' && navigator.plugins["Shockwave-Flash"] && (parseInt(navigator.plugins["Shockwave-Flash"].description)>=5 || parseInt(navigator.plugins["Shockwave-Flash"].filename) >= 5))
		this.swf=true;
}

// initialization
var onLoadObj = new Array();	// array where you can put in javascript functions (as strings) to be executed onLoad
var popUps  = new Array();	// popup-windows
var is = new checkBrowser();	// Browser-check object
if(!is.support && UnSupportedBrowserRedirectURL!='') self.location.href(UnSupportedBrowserRedirectURL);

function doResize(){
	window.document.location.reload();
}

function onLoadHandler(){
	for (var i = 0; i < onLoadObj.length && i<1000; i++){	// "eval" all entries in initObjs that were put there further down the page
		eval(onLoadObj[i]);
	}
	for (var i = 1000; i < onLoadObj.length; i++)
		eval(onLoadObj[i]);
}

AddRefHandler = function(eventObj,EventName,Handler,Objs){
	eventObj[EventName] = function(Ev){
		if(is.ie) Ev=window.event;
		var res=Handler(Ev,Objs);
		return res;
	}
}


//*** DOM Helper Routines
function getElementsByAttributeValue(attrName,attrValue,tName,Parent,onlyOne){
	var elem=new Array();
	var d=Parent || self.document.documentElement;
	if(tName && tName!=''){
		var elems=d.getElementsByTagName(tName);
		for(var i=0;i<elems.length;i++){
			var av=getAttributeValue(elems.item(i),attrName);
			if((attrValue==null && av!=null) || (av!=null && av==attrValue)){
				elem[elem.length]=elems.item(i);
				if(onlyOne) break;
			}
		}
	}
	return elem;
}

function getAttributeValue(node,attrName){
	if((is.ie55 || is.ie5) && !is.opera){
		if(node.getAttribute(attrName))	return node.getAttribute(attrName);
	}else{
		if(node.getAttributeNode(attrName)) return node.getAttributeNode(attrName).value;
	}
	return null;
}

//==================== HELPER =======================

function shuffleArray(arr, recursive, rounds){
	if(!arr || !arr.length || typeof(arr)!="object"){return new Array(0);};
	var copy=new Array(arr.length);
	var increase=0;
	var limit=arr.length;
	while(increase < limit){
		var picked=Math.round( Math.random()*(arr.length-1) );
		copy[increase]=arr[picked];
		arr=arr.slice(0,picked).concat( arr.slice(picked+1) );
		++increase;
	};
	if( !isNaN(parseFloat(recursive)) ){
		rounds=(rounds)?rounds:0;
		recursive=parseFloat(recursive);
		if(rounds>=recursive){return copy;};
	}
	return (recursive)? shuffleArray(copy, recursive, ++rounds) : copy;
	/*keep this comment to reuse freely
	http://www.unitedscripters.com */
}

//**** Popup - Opener-function
function openWindow(src, name,x, y, width, height,x0,y0,features){
	var yOff=0,xOff=0;
	if(!is) is=new checkBrowser();
	if(!isNaN(x)) xOff=x;if(!isNaN(y)) yOff=y;
	if(x=="ScreenCentered") xOff = Math.ceil((screen.width-width)/2);
	if(y=="ScreenCentered") yOff = Math.ceil((screen.height-height)/2-20);
	if(x=="BrowserLeft"){
		if(is.ie) xOff = self.screenLeft-3; else
		   if(is.ns) xOff = self.screenX+self.outerWidth-self.innerWidth;
	}
	if(y=="BrowserTop"){
		if(is.ie) yOff = self.screenTop; else
		   if(is.ns) yOff = self.screenY+self.outerHeight-self.innerHeight-24;
	}
	xOff+=x0;yOff+=y0;if(xOff<0 )xOff=0;if(yOff<0)yOff=0;
	var stdfeatures = "scrollbars";
	if(features) stdfeatures=features; //else yOff-=20;
	var strfeatures = "left="+xOff+",top="+yOff+",width="+width+",height="+height;
	if (stdfeatures!="") strfeatures+=","+stdfeatures;
	if(popUps[name] && !popUps[name].closed) 		//already opened!
	//if(popUps[name].location && popUps[name].location.pathname!=src)	//not the same source!
	popUps[name].close();
	self.popUps[name]=window.open(src,name,strfeatures);
	self.popUps[name].focus();
	return void(0);
}


//***************** NAVIGATIONS ************
var NavLvl0=new NavImgs('NavLvl0',0);
var NavLvl1=new NavImgs('NavLvl1',1);

//***************** NAVIGATION-OBJECTS ************
function NavImgs(Name,Level){
	this.Active=null;
	this.Name=Name;
	this.Level=Level;
	onLoadObj[onLoadObj.length]=Name+'.Init();';
}

NavImgs.prototype.Init=function(){
	var NavT=document.getElementById('T'+this.Name);
	if(NavT){
		var NavElems=getElementsByAttributeValue('nav'+this.Level+'id',null,'a',NavT);
		for(var i=0;i<NavElems.length;i++){
			AddRefHandler(NavElems[i],'onmouseover',this.EvHandler,[this,NavElems[i],true])
			AddRefHandler(NavElems[i],'onmouseout',this.EvHandler,[this,NavElems[i],false])
			if(CurNavLevel[this.Level]!='' && getAttributeValue(NavElems[i],'nav'+this.Level+'id')==CurNavLevel[this.Level]){
				this.Active=NavElems[i].childNodes.item(0);
				this.Show(this.Active, true);
			}
		}
	}
}

NavImgs.prototype.EvHandler=function(Ev,Objs){
	Objs[0].Show(Objs[1].childNodes.item(0),Objs[2]);
}

NavImgs.prototype.Show=function(img,on){
	if(on || (img!=this.Active && !on)) this.ChangeImg(img,on);
}

NavImgs.prototype.ChangeImg=function(img,on){
	var SRC=img.src;
	var l=SRC.length;
	if(on && SRC) img.src=SRC.substring(0,l-5)+'a'+SRC.substring(l-4,l);
		else img.src=SRC.substring(0,l-5)+'i'+SRC.substring(l-4,l);
}



//******* Popup - Windows ***********
function openMemoryGame(src){
	//if(!src) 
	src="/de/erleben/31_memory.htm";
	openWindow(src, 'winMemory','ScreenCentered','ScreenCentered',628,422,0,0,'scrollbars=no,statusbar=no,toolbar=no,personalbar=0, resizable=no');
	return false;
	//return true;
}

function openZertifikate(src,width){
	if(!width) width=450;
	if(src)	openWindow(src, 'winZertifikat','ScreenCentered','ScreenCentered',width,420,0,0,'scrollbars=yes,statusbar=no,toolbar=no,personalbar=no, resizable=no');
	return false;
	//return true;
}
function openArt(src,width){
	if(!width) width=800;
	if(src)	openWindow(src, 'winArt','ScreenCentered','ScreenCentered',width,760,0,0,'scrollbars=yes,statusbar=no,toolbar=no,personalbar=no, resizable=no');
	return false;
	//return true;
}
function openTV(src,width){
	if(!width) width=500;
	if(src)	openWindow(src, 'winArt','ScreenCentered','ScreenCentered',width,225,0,0,'scrollbars=yes,statusbar=no,toolbar=no,personalbar=no, resizable=no');
	return false;
}
