/* Legende */
function hideLayer(id)
{
	if($(id)) $(id).style.display = 'none';
}

function showLayer(id)
{
	if($(id)) $(id).style.display = 'block';
}

/* Clear search input field on focus */
function clearSearchInputOnFocus()
{
	var default_value = "suchen";
	
	$$('input[name^=tx_t3webvvsorangepages_pi1[sword]]').each(function(el){
	  el.set("value", default_value);
	  el.addEvent("focus", function(e){
		if(this.value == default_value) this.value = "";
		this.select();
	  });
	  el.addEvent("blur", function(e){
		if(this.value == "") this.value = default_value;
	  });
	});
}

/* Promobar */
mnp = {
	"promobar":{slidespeed:500,slidemode:"sine",items:5,step:169},
	"promobarBottom":{slidespeed:500,slidemode:"sine",items:5,step:169},
	"picRotator":{slidespeed:500,slidemode:"sine",items:1,step:660}
};
var p=p?p:
{
	initbar:function(id, item)
	{
		if(!item.curpos) item.curpos=0;
		if($$('#'+id+' ul')[0]) $$('#'+id+' ul')[0].setStyles({width:item.step*$(id).getElements('li').length});
		$$('#'+id+' .promoB').fade("hide")
		if((item.curpos + item.items) < $(id).getElements('li').length) $$('#'+id+' .promoB').fade("in");
		var mnu=$$('#'+id+' ul')[0];
		var sls=item.slidespeed;
		var slm=item.slidemode;
		var mfx=new Fx.Tween(mnu,{duration:sls,fps:50,transition:Fx.Transitions[slm.capitalize()].easeOut});
		$$('#'+id+' .promoF').each(function(el)
		{
			var mnd=id;
			el.addEvent('click',function()
			{
				if(item.curpos > 0)
				{
					mfx.cancel();
					mfx.start('left','-'+(item.curpos-1)*item.step);
					item.curpos--;
				}
				if((item.curpos + item.items) < $(mnd).getElements('li').length) $$('#'+mnd+' .promoB').fade("in");
				if(item.curpos == 0) $$('#'+mnd+' .promoF').fade("out");
				return false;
			});
		});
		$$('#'+id+' .promoB').each(function(el2)
		{
			var mnd=id;
			el2.addEvent('click',function()
			{
				if((item.curpos + item.items) < $(mnd).getElements('li').length)
				{
					mfx.cancel();
					mfx.start('left','-'+(item.curpos+1)*item.step);
					item.curpos++;
				}
				if((item.curpos + item.items) == $(mnd).getElements('li').length)$$('#'+mnd+' .promoB').fade("out");
				if(item.curpos > 0)$$('#'+mnd+' .promoF').fade("in");
				return false;
			});
		});
		$$("#"+id+" li").each(function(el){if($chk(el.getElement("a"))){el.addEvent("click", function(e){
			var myA = this.getElement("a");
			if(myA.get("target")=="_blank") {
				window.open(myA.get("href"));
			} else {
				document.location.href = myA.get("href");
			}
			return false;
		});}});
	},
	init:function(items)
	{
		for(pr in items)
		{
			if($(pr)) this.initbar(pr, items[pr]);
		}
	}
};

var n=n?n:
{
	init:function()
	{
		var active="";
		var sn = $("subnavWrapper");
		var req = new Request.HTML(
		{
			async:false,
//			url:"ajax/subnav.php",
			url:"index.php?type=1",
			onRequest: function()
			{
				if($("promobar")) $("promobar").fade("hide");
				sn.empty();
				sn.removeClass("subnavHidden");
				sn.addClass("subnavLoading");
			},
			onSuccess: function(html)
			{
				if(html.length > 0)
				{
					sn.adopt(html);
					sn.removeClass("subnavLoading");
					sn.addClass("subnavShown");
					pbar = {slidespeed:700,slidemode:"quart",items:5,step:169};
					p.initbar("promobarAj", pbar);
					$("promospace").store("height", $("promospace").getSize().y);
					if(!$("promobar")){
						n.pstoggle($("promobarAj").getSize().y+sn.getSize().y+$("promospace").getStyle("marginBottom").toInt());
//						$("promospace").getElement("div").fade("hide");
						$("promospace").getElement("div").setStyle("display", "none");
					}
					else
					{
						n.pstoggle(264);
					}
					$("promospace").fade("hide");
				}
				if($("subnavCloseP"))
				{
					$("subnavCloseP").addEvent('click',function()
					{
						sn.removeClass("subnavShown");
						sn.addClass("subnavHidden");
						$("promospace").fade("show");
						if(!$("promobar")) {
//							$("promospace").getElement("div").fade("show");
							$("promospace").getElement("div").setStyle("display", "block");
						}
						n.pstoggle($("promospace").retrieve("height"));
						if($("promobar")) {
							$("promobar").fade("show");
						}
						if(active != "") active.setStyle("background","");
					});
				}
			},
			onFailure: function()
			{
				return true;
			}
		});

		$$('#nav_main li').each(function(el)
		{
			el.addEvent('click',function(e)
			{
				el.setStyle("background-image","url('./images/bg_nav.active.gif')");
				if(active != "") active.setStyle("background","");
				active = el;
				var myid = el.getProperty("id");
				myid = myid.substring(3);
				var ret = req.send("id="+myid);
				//var ret = req.send("id="+el.getProperty("id"));
				if(ret.response.text.length > 0) return false;
				else return true;
			});
		});
		n.pstoggle(264);
	},
	pstoggle:function(myh)
	{
		if(!myh)
		{
			var md = $("promospace").getElement("div").getSize().y;
			var mh = $("promospace").getSize().y;
			myh=(mh<md)?md:264;
		}
		$("promospace").set('tween',{duration: 500,transition: Fx.Transitions.linear}).tween('height', myh+"px");
	}
};

function $get(key,url)
{
	if(arguments.length < 2) url =location.href;
	if(arguments.length > 0 && key != "")
	{
		if(key == "#")
		{
			var regex = new RegExp("[#]([^$]*)");
		}
		else if(key == "?")
		{
			var regex = new RegExp("[?]([^#$]*)");
		}
		else
		{
			var regex = new RegExp("[?&]"+key+"=([^&#]*)");
		}
		var results = regex.exec(url);
		return (results == null )? "" : results[1];
	}
	else
	{
		url = url.split("?");
		var results = {};
		if(url.length > 1)
		{
			url = url[1].split("#");
			if(url.length > 1) results["hash"] = url[1];
			url[0].split("&").each(function(item,index)
			{
				item = item.split("=");
				results[item[0]] = item[1];
			});
		}
		return results;
	}
}

function urldecode(str)
{
	var histogram = {};
	var ret = str.toString();
	var replacer = function(search, replace, str) {
		var tmp_arr = [];
		tmp_arr = str.split(search);
		return tmp_arr.join(replace);
	};
	histogram["'"]   = '%27';
	histogram['(']   = '%28';
	histogram[')']   = '%29';
	histogram['*']   = '%2A';
	histogram['~']   = '%7E';
	histogram['!']   = '%21';
	histogram['%20'] = '+';
	histogram['ä']   = '%E4';
	histogram['ö']   = '%F6';
	histogram['ü']   = '%FC';
	histogram['Ä']   = '%C4';
	histogram['Ö']   = '%D6';
	histogram['Ü']   = '%DC';
	histogram['ß']   = '%DF';
	for (replace in histogram)
	{
		search = histogram[replace]; // Switch order when decoding
		ret = replacer(search, replace, ret) // Custom replace. No regexing   
	}
	ret = decodeURIComponent(ret);
	return ret;
}

function dump(myvar)
{
	var dump="";
	for (i in myvar) dump += i+": "+myvar[i]+"\n";
	alert(dump);
}

function tmi(obj) //toggles map image
{
	obj.src=(obj.src.test("icon.arrow.up.gif"))?obj.src.replace(/icon.arrow.up.gif/, "icon.arrow.down.gif"):obj.src.replace(/icon.arrow.down.gif/, "icon.arrow.up.gif");
}
function prec(num) {
	var ret;
	num<10?ret="0"+num.toString():ret=num.toString();
	return ret;
}

var boxEfa,boxMail;

window.addEvent('domready', function()
{
/* hide Tabcontainers */
	$$(".detailTabcontainer").each(function(el) {
		el.setStyle("display", "none");
	});
/* Set EFA & Mail Targets for the sake of strict coding*/
	if($("formEFA")) $("formEFA").set("target","_blank");
	if($("formMail"))  $("formMail").set("target","_blank");
/* init navigaion */
	n.init();
/* init picture rollers */
	p.init(mnp);
/* Init Efa & Mail */
	var today = new Date();
	if($("itdDateDayMB")) $("itdDateDayMB").value=prec(today.getDate());;
	if($("itdDateMonthMB")) $("itdDateMonthMB").value=prec(today.getMonth()+1);
	if($("itdDateYearMB")) $("itdDateYearMB").value=today.getFullYear().toString().substr(2,2);
	if($("itdTimeHourMB")) $("itdTimeHourMB").value=prec(today.getHours());
	if($("itdTimeMinuteMB")) $("itdTimeMinuteMB").value=prec(today.getMinutes());
	boxEfa = new box({mbClass: '.mbEfa',container: $(document.body),width: 360,height:148,type:"element"});
	boxMail = new box({mbClass: '.mbMail',container: $(document.body),width: 360,height:181,type:"element"});
/* Init Tabs */	
	if($('detailTabContent'))
	{
		var container = $('detailTabContent');
		new SimpleTabs(container,{});
	}
/* init Calendar */
	if($("itdDateYear")) myCal = new Calendar({itdDateYear:{itdDateDay: 'd',itdDateMonth: 'm',itdDateYear: 'y'}},{classes:['efaCalendar'],days:["So","Mo","Di","Mi","Do","Fr","Sa"],months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],offset:1});
/* Init EFA-iframe */
	if($("efaFrame")) $("efaFrame").setStyle("height", $("col3_content").getSize().y-81);
/* Clear search input field on focus */
	clearSearchInputOnFocus();

/* Open New Window - XHTML 1.1 Strict Valid */
  $$('a[rel="external"]').addEvent('click', function(e){
    e.preventDefault();
    window.open(this.getProperty('href'));
  });

});

/*
window.addEvent('unload', function()
{
	onUnLoadHandler();
});
*/
