var fakeHover = null, doclhook = [], currenttextsize = 0, maxtextsize = 3, load_method = "load", navihide = 3500, navitimer = null, openNavi = null;;
var alternateSWF = "";

if(window.ie6)
{


	XHR.implement({
		
		setTransport: function(){
			//this.transport = (window.XMLHttpRequest) ? new XMLHttpRequest() : (window.ie ? new ActiveXObject('Microsoft.XMLHTTP') : false);
			this.transport = new gb_fake_xhr(this);
			return this;
		}
	});
}

fakeAjax = {};

gb_fake_xhr = new Class({
	
	'method' : '',
	'turl' : '',
	'responseText' : '',
	'responseXML' : '',
	'myid' : '',
	'vars' : {},
	'pobj' : null,

	initialize : function(pobj)
	{
		this.myid = 'a' + Math.random().toString().split(".")[1];
		fakeAjax[this.myid] = this;
		this.pobj = pobj;
	},
	
	open : function()
	{
		this.method = arguments[0];
		this.turl = arguments[1];
	},
	
	send : function()
	{
		var tmp = arguments[0].split("&");
		for(var i = 0; i < tmp.length; i++)
		{
			var pair = tmp[i].split("=");
			this.vars[pair[0]] = pair[1];
		}

		var tmp = new Element("iframe",
		{
			'name' : 'if'+this.myid,
			'class' : 'superhidden',
			'events' : { 'load' : function()
				{
					fakeAjax[$(this).getProperty("name").substring(2)].pobj.response = {
							'text' : this.contentWindow.document.firstChild.lastChild.innerHTML, 
							'xml' : null
						};
					fakeAjax[$(this).getProperty("name").substring(2)].pobj.onComplete();

				}
			}
		});

		document.body.appendChild(tmp);
		var frm = new Element("form",{'class':'superhidden','action':this.turl,'method':this.method,'target':'if'+this.myid});
		for(var i in this.vars)
		{
			frm.appendChild(new Element("input",{name : i, value : unescape(this.vars[i])}));
		}
		document.body.appendChild(frm);
		frm.submit();
	}
});

	/*
var Ajax2 = new Class({
	
	//crazy random ie6 patch
	
	'aurl' : "",
	'params' : "",
	'myid' : "",
	'vars' : {},
	
	initialize: function()
	{
		this.aurl = arguments[0];
		this.params = arguments[1];
		this.myid = "a" + Math.random().toString().split(".")[1];
		var x = this.params.postBody.split("&");
		for(var i = 0; i < x.length; i++)
		{
			var bla = x[i].split("=");
			this.vars[bla[0]] = bla[1];
		}
		
	},
	request : function()
	{
	
		var tmp = new Element("iframe",
		{
			'name' : "if"+this.myid,
			'title' : this.vars.ebene,
			'class' : "superhidden",
			'events' : { "load" : function()
				{
					$("filter"+this.title).setHTML(this.contentWindow.document.firstChild.lastChild.innerHTML);
				}
				}
		});
		
		
		document.body.appendChild(tmp);
		var frm = new Element("form",{'class' : "superhidden",action:this.aurl,method:"post",target:"if"+this.myid});
		

		for(var i in this.vars)
		{
			
			frm.appendChild(new Element("input",{name : i, value : this.vars[i]}));
		}
		
		document.body.appendChild(frm);
		frm.submit();
	}
	
});	

	
}

*/

window.addEvent(load_method, function(){

	for(var i = 0; i < doclhook.length; i++)
	{
		
		doclhook[i]();
	}

	//flashversion checken und von Server in Cookie speichern lassen
	if(!Cookie.get("hasFlash8Player"))
	{
		document.body.appendChild(new Element("div",{id:'flash8checkbox'}));
		var check8 = new SWFObject("/fileadmin/templates/swf/setflashcookie.swf", "check8", "10", "10", "8", "");
		check8.write("flash8checkbox");
	}


	if(alternateSWF != "")
	{
		if (bigheader)
		{
			var gblogo = new SWFObject(alternateSWF, "titel", "1004", "410", "8", "");		
		}
		else
		{
			var gblogo = new SWFObject(alternateSWF, "titel", "1004", "128", "8", "");		
		}
		gblogo.write("titel");

	}

	
	if(alternateSWF == "")
	{
		if (bigheader=="1")
		{
			var gblogo = new SWFObject("/fileadmin/templates/swf/fx2_big.swf", "titel", "1004", "410", "8", "");
		}
		else
		{
			var gblogo = new SWFObject("/fileadmin/templates/swf/fx2.swf", "titel", "1004", "128", "8", "");
		}
		gblogo.addVariable("text",title2use);
		gblogo.addVariable("bild",img2use);
		gblogo.write("titel");
	}

	var navi2 = $$("li.navi0 a");
	for (var i=0, o; o=navi2[i]; i++) {
		o.addEvents(
			{ 
				'mousemove':function(e)
				{
					var _e = new Event(e);
					
					var mycoords = this.getCoordinates();
					var mx = _e.page.x - mycoords.left;
					var my = _e.page.y - mycoords.top;
					
					//console.log("x:"+mx+" /y:"+my);
					if(mx < 20 || mx > 140 || my < 12 || my > 25)
					{
						if(fakeHover)fakeHover.removeClass('a');
						//fakeHover = null;
						return;
					}

					if(fakeHover)fakeHover.removeClass('a');
					this.addClass('a');
					fakeHover = this;
					
					var navibox = $("l2navi");
						if(openNavi == this.href || !this.getParent().hasClass("navi0"))
					{
						//der ie kriegt das mit dem css path leider nicht so 100% hin :(
						return;
						
					}
					
					if(!this.getNext())
					{
							navibox.setStyle("display","none");
							openNavi = null;
							return;
					}


					
					var items = this.getNext().getChildren();

					openNavi = this.href;
					navibox.setStyle("opacity",1);
					navibox.empty();
					new Element("ol").inject($("l2navi"));
					new Element("div",{'id':"l2navi-bottom"}).inject($("l2navi"));
					
					for(var i = 0; i < items.length; i++)
					{
						items[i].clone().injectInside(navibox.getFirst());
					}

					navibox.setStyles({
						"left" : "-1000px",
						"top": "-1000px",
						"display": 'block'
					});
					
					
					var boxcoords = navibox.getCoordinates();
					

					
					
					if(window.ie)
					{
						var bodycoords = $(document.body).getCoordinates();
					}
					
					//alert(((mycoords.top + mycoords.height / 2) - boxcoords.height / 2 - 206)+"px");
					
					navadder = 0;
					if (bigheader == "1") 
					{
						navadder = 280;
					}
					
					navibox.setStyles({
							'top' : ((mycoords.top + mycoords.height / 2) - boxcoords.height / 2 - 206 - navadder)+"px",
							'left' : "150px",
							'zIndex' : '999'
						});
					
					//mycoords.left + 150 +(window.ie?bodycoords.left * -1:0)
					resetNaviTimeout();		
					
				},
				'focus':function()
				{
					this.blur();
				}
			}
		);
		
	}
	
	$("l2navi").addEvents(
					{
					'mouseleave':function(){
					this.empty();
					this.setStyle("display","none");
					
					openNavi = null;
					if(fakeHover)fakeHover.removeClass('a');
					fakeHover = null;
					},
					'mousemove':function()
					{
						if(fakeHover)fakeHover.addClass('a');
						resetNaviTimeout();
						
					}
	
	});

	if($("newsplayer"))
	{
		np.timer();
	}
	
	/* referenzen fix */
	var refs = $$(".gb_referenzen_teaser");
	if(refs)
	{
		for(var i = 0; i < refs.length; i++)
		{
			
			var img = $(refs[i].getElementsByTagName("img")[0]).clone();
			$(refs[i].getElementsByTagName("div")[0]).empty();
			var a = new Element("a",{href:refs[i].getElementsByTagName("a")[0].href});
			a.appendChild(img);
			refs[i].getElementsByTagName("div")[0].appendChild(a);
			
			var h2 = $(refs[i].getElementsByTagName("h2")[0]);
			var h3 = $(refs[i].getElementsByTagName("h3")[0]);
			
			h2.addEvent("click",function(){ window.location = this.getParent().getElementsByTagName("a")[0].href });
			h3.addEvent("click",function(){ window.location = this.getParent().getElementsByTagName("a")[0].href });
			h2.setStyle("cursor","pointer");
			h3.setStyle("cursor","pointer");
			
		}
	}
	
	
	/* dl fix */
	var dl = $$(".dl-item");
	if(dl)
	{
		for(var i = 0; i < dl.length; i++)
		{
			
			var div = $(dl[i].getElementsByTagName("div")[0]);
			var h2 = $(dl[i].getElementsByTagName("h2")[0]);
			div.addEvent("click",function(){ window.open(this.getParent().getElementsByTagName("a")[0].href) });
			h2.addEvent("click",function(){ window.open(this.getParent().getElementsByTagName("a")[0].href) });
			div.setStyle("cursor","pointer");
			h2.setStyle("cursor","pointer");

		}
	}
	

});




function resetNaviTimeout()
{
	if(navitimer)
	{
		clearTimeout(navitimer);
	}
	
	navitimer = setTimeout("forcehidenavi()",navihide);
	
}

function forcehidenavi()
{
		$("l2navi").effects({duration:500,'onComplete':function(){
			
			openNavi = null;
			if(fakeHover)fakeHover.removeClass('a');
			fakeHover = null;
			}}).start({'opacity':[1,0]});
}

function textsize()
{
	if(currenttextsize < maxtextsize)
	{
		currenttextsize++;
	}
	else
	{
		currenttextsize = 0;
	}
	
	if(currenttextsize == 0)
	{
		$("content").removeClass("txtsize3");
	}
	else
	{
		$("content").removeClass("txtsize"+(currenttextsize - 1));
		$("content").addClass("txtsize"+currenttextsize);
	}
	
}

function switchlang()
{
	var l = window.location;
	var s = l.search+"";
	if(s.length > 0)
	{
		if(s.indexOf("L=") > -1)
		{
			if(s.indexOf("L=0") > -1)
			{
				s = s.replace("L=0","L=1");
			}
			else if(s.indexOf("L=1") > -1)
			{
				s = s.replace("L=1","L=0");
			}
		}
		else
		{
				s += "&L=1";
		}
	}
	else
	{
			s = "?L=1";
	}
	
	l.search = s;
}




function openPageInLightbox(page,width,height)
{
	
	var lbox = new Element('div',{
			'id'	:	'mylightbox'
		});
		
	lbox.injectBefore('head');
	
	$('mylightbox').setHTML('<div id="lightbox_outer"><div id="lightbox_left">&nbsp;</div><div id="lightbox_top">&nbsp;</div><div id="lightbox_inner"></div><div id="lightbox_bottom">&nbsp;</div><div id="lightbox_right">&nbsp;</div></div>');
		
	setLightboxSize();
		
	
}

function setLightboxSize()
{
	if (window.innerHeight){
		theHeight=window.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight){
		theHeight=document.documentElement.clientHeight;
	}else if (document.body){
		theHeight=document.body.clientHeight;
	}			
	window.document.body.style.overflow = 'hidden';
	window.document.body.style.height = (theHeight)+'px';
	
	if (window.innerWidth){
		theWidth=window.innerWidth;
	}else if (document.documentElement && document.documentElement.clientWidth){
		theWidth=document.documentElement.clientWidth;
	}else if (document.body){
		theWidth=document.body.clientWidth;
	}
				
	innerheight	= $('lightbox_inner').getStyle('height').toInt();
	innerwidth	= $('lightbox_inner').getStyle('width').toInt();

	restheight	= theHeight - innerheight;
	restwidth	= theWidth - innerwidth;
	
	if(restheight < 20 ) { restheight = 20; }
	if(restwidth < 20 ) { restwidth = 20; }
	
	$('lightbox_left').setStyle('width', restwidth/2);
	
	$('lightbox_top').setStyle('width', innerwidth);
	$('lightbox_top').setStyle('left', restwidth/2);
	$('lightbox_top').setStyle('height', restheight/2);
	
	$('lightbox_inner').setStyle('left', restwidth/2)
	$('lightbox_inner').setStyle('top', restheight/2);
	
	$('lightbox_bottom').setStyle('width', innerwidth);
	$('lightbox_bottom').setStyle('left', restwidth/2);
	$('lightbox_bottom').setStyle('height', 1200-innerheight-(restheight/2));
	$('lightbox_bottom').setStyle('top', restheight/2+innerheight);
	
	$('lightbox_right').setStyle('width', restwidth/2);
	$('lightbox_right').setStyle('left', restwidth/2+innerwidth);
	
	$('lightbox_left').setStyle('height', 1200);
	$('lightbox_right').setStyle('height', 1200);
	$('lightbox_outer').setStyle('height', theHeight);
	$('mylightbox').setStyle('height', theHeight);
	
	window.document.body.style.overflow = 'scroll';
}
