function mo(url){
	/* PopUp Fenstereinstellung der alten EFA-Hilfe */
	// window.open(url, "efahelp", 'height=540,width=444,scrollbars=1,status=0');
	window.open(url, "efahelp", 'height=600,width=462,scrollbars=1,status=0');
}

function wo(url){
	window.open(url);
	return false;
}

// Load Facebook Button in VVS ToolBox "Social Media Buttons"
function toolBoxLoadFbButton(container, url, layout){
	var url = url;
	var layout = (layout!=null) ? layout : 'button_count';
	if(url != null) {
		var fb_html = '<iframe src="http://www.facebook.com/plugins/like.php?locale=de_DE&amp;href=';
		fb_html += url;
		fb_html += '&amp;send=false&amp;layout=';
		fb_html += layout;
		fb_html += '&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial" scrolling="no" frameborder="0" allowTransparency="true"></iframe>';
		container.innerHTML = fb_html;
	}
}

var toolbox = toolbox?toolbox:{
	init:function(){
		var tbStatus = JSON.decode(Cookie.read("tbStatus"));
		if(tbStatus == null) tbStatus = {};
		if(!tbStatus[mnPid]) tbStatus[mnPid] = [];
		$$(".toolBox").each(function(el, index){
			$$("#"+el.id+ " .toolBoxWrapper").each(function(ul){
				var vs = new Fx.Slide(ul);
				if(!tbStatus[mnPid][index]) {
					if(ul.hasClass("toolBoxOpen")) tbStatus[mnPid][index]="open";
					else tbStatus[mnPid][index]="closed";
				}
				if(tbStatus[mnPid][index]=="open") {
					vs.show();
					toolbox.setIcon(el,true);
				}else{
					vs.hide();
					toolbox.setIcon(el,false);
				}
				vs.addEvent("complete", function(){
					toolbox.setIcon(el,vs.open);
					tbStatus[mnPid][index] = vs.open?"open":"closed";
					Cookie.write("tbStatus", JSON.encode(tbStatus));
				});
				el.getElement("h6").addEvent("click", function(e){
					e.stop();
					vs.toggle();
				});
			});
		});
	},
	setIcon:function(obj,status){
		var icon = obj.getElement("h6").getElement("img");
		var iconPlus = "fileadmin/templatesvvs/main/images/icon.plus.gif";
		var iconMinus = "fileadmin/templatesvvs/main/images/icon.minus.gif";
		status?icon.set("src", iconMinus):icon.set("src", iconPlus);
	}
};

window.addEvent("domready", function(){
/* Hyperlinks */
	$$("a[rel=newwin]").each(function(el){
		el.addEvent("click",function(e){
			e.stop();
			window.open(this.href);
	});});
/* EFA */
	if($("efaSelect")){
		//initEfaDate();
		var vs = {};
		var valueOrigin = "Von: Ort, Hst., Adr. oder POI";
		var valueDestination = "Nach: Ort, Hst., Adr. oder POI";
		var lastIndex = $("efaSelect").selectedIndex;
		$$("#efaSelect option").each(function(el, index){
			var mnF = $(el.value);
			vs[index] = new Fx.Slide(mnF);
			if(index == $("efaSelect").selectedIndex) {
				mnF.removeClass("hide");
				vs[index].show();
			}else{
				vs[index].hide()
				mnF.removeClass("hide");
			}
		});

		$("efaSelect").addEvent("change", function(e){
			e.stop();
			if(lastIndex != this.selectedIndex) {
				vs[lastIndex].toggle();
				vs[lastIndex].addEvent("complete", function(){
					vs[$("efaSelect").selectedIndex].toggle();
					lastIndex = $("efaSelect").selectedIndex;
					this.removeEvents("complete");
				});
			}
		});

	/* prefill field values */
		$$("#efa input[name=name_origin]").each(function(el){
			el.set("value", valueOrigin);
			el.setStyle("color", "#575757");
			el.addEvent("focus", function(e){
				if(this.value==valueOrigin) this.value="";
				this.select();
			});
			el.addEvent("blur", function(e){
				if(this.value=="") this.value=valueOrigin;
			});
			$(el.id.substring(0,el.id.indexOf("Origin"))+"Form").addEvent("submit", function(e){
				if(el.value==valueOrigin) el.value="";
			});
		});
		$$("#efa input[name=name_destination]").each(function(el){
			el.set("value", valueDestination);
			el.setStyle("color", "#575757");
			el.addEvent("focus", function(e){
				if(this.value==valueDestination) this.value="";
				this.select();
			});
			el.addEvent("blur", function(e){
				if(this.value=="") this.value=valueDestination;
			});
			$(el.id.substring(0,el.id.indexOf("Destination"))+"Form").addEvent("submit", function(e){
				if(el.value==valueDestination) el.value="";
			});
		});
	/* help */
		$$("#efa .button25").each(function(el){
			// var url=el.getElement("a").get("href");
			
			/* Pfad zur alten EFA-Hilfe */
			// var url = "/efa_hilfe/help.php";
			var url = "/hilfeseiten/efa-hilfeseiten/efahilfe/";
			
			el.addEvent("click",function(e){
				e.stop();
				mo(url);
			});
		});
	/* arrow up/down */
		$$("#efaArrow img").each(function(el){
			el.addEvent("click", function(e){
				this.id=="efaArrowUp"?dateUpDown('up'):dateUpDown('down');
			});
			el.setStyle("cursor", "pointer");
		});
		$("efaArrow").setStyle("display", "inline");
	/* 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});
			$("efaCalendar").setStyle("display", "inline");
		}
	/* eTracker */
/* onmousedown not used due to inaccuracy (dblclick etc)
		if($("efaSubmit")) {
			$("efaSubmit").addEvent("mousedown", function(){
				ET_Event.click('EFA%20Anyfield%20Klicks', 'EFA%20Anyfield%20Klicks');
			});
		}
*/
		if($("efaForm")) {
			$("efaForm").addEvent("submit", function(){
				ET_Event.click('EFA%20Anyfield', 'EFA%20Anyfield');
			});
		}
	}
/* PressSearch */
	if($("pressSearchKey")) {
		var valuePress = "in den Pressemeldungen";
		var sel = $("pressSearchKey");
		sel.set("value", valuePress);
		sel.setStyle("color", "#575757");
		sel.addEvent("focus", function(e){
			if(this.value==valuePress) this.value="";
		});
		sel.addEvent("blur", function(e){
			if(this.value=="") this.value=valuePress;
		});
	}
/* Ambassadors */
	if($("titleV1")) {
		$$('.ambassadorWrapper').each(function(el){
			var newWidth = el.getElements("li").length*100;
			if(Browser.Engine.trident && Browser.Engine.version==4) newWidth+=4;/* 3px IE6 Bug */
			el.setStyle("width", newWidth+"px");
		});
	}

/* Toolbox */
	toolbox.init();
/* Multibox */
	new MultiBox('mb', {useOverlay:true,showControls:false,showNumbers:false});
	new MultiBox('mbgal_mediathek', {
	  useOverlay:true,
	  showTitle:false,
	  showControls:true,
	  showNumbers:false,
	  descClassName:'multiBoxDesc',
	  offset:{x:0, y:-100}
	});
	$$('.mb img', '.mbgal_mediathek img').each(function(el){
		var dim = el.getCoordinates($("col3_content"));
		var newEl = new Element("div", {'class': 'mbZoom'});
		el.getParent().grab(newEl);
		var top = dim['top']+el.getSize().y-newEl.getSize().y-5;
		var left = dim['left']+el.getSize().x-newEl.getSize().x-5;
		newEl.fade("hide").setStyles({top:top,left:left}).fade(0.3);
	});
	if($("warnmeldung") && $("warnmeldungLink")) {
		var sgStatus = JSON.decode(Cookie.read("sgStatus"));
		if(sgStatus == null) {
			new MultiBox('sg', {useOverlay:true,showControls:false,showNumbers:false}).open($("warnmeldungLink"));
			Cookie.write("sgStatus", JSON.encode(1));
		}
//		Cookie.write("sgStatus", JSON.encode(null));
	}
/* Twitter */
	if($("twitterFCE")) {
		$("twitterFCE").addEvent("click", function(e){
			e.stop();
			wo($("twitterFCE").getElement("a").get("href"));
		});
	}
/* Top-Thema eTracker */
	if($("topthemaEventTracker")) {
		$("topthemaEventTracker").addEvent("mousedown", function() {
			ET_Event.click('Homepage%20Top-Meldung', 'Homepage%20Top-Meldung')
		});
	}
	
/* Bonusbereich Login Formular */
	var loginForm = $("tx_vvsbonusbereich_loginform");
	if(loginForm) {
		var valueUsernameField = "E-Mail Adresse";
		var valuePasswordField = "Passwort";
		
		// Logout Link anzeigen
		var logoutLink = loginForm.getElements('p.hideLogoutLink');
		if(logoutLink.get('tag').length > 0){
			loginForm.getElements('input[name=submit]').destroy();
			logoutLink.removeClass("hideLogoutLink");
			logoutLink.addEvent('click', function(el) {
				el.stop();
				loginForm.getElement('form[name=vvs_bonusbereich_logoutForm]').submit();
			});
		}
		
		// Benutzername
		$$("#tx_vvsbonusbereich_loginform input#user").each(function(el){
			el.addEvent("focus", function(e){
				if(this.value==valueUsernameField) this.value="";
				this.select();
			});
			el.addEvent("blur", function(e){
				if(this.value=="") this.value=valueUsernameField;
			});
		});
		
		// Passwort
		$$("#tx_vvsbonusbereich_loginform input#pass").each(function(el){
			el.addEvent("focus", function(e){
				if(this.value==valuePasswordField) this.value="";
				this.select();
			});
			el.addEvent("blur", function(e){
				if(this.value=="") this.value=valuePasswordField;
			});
		});
	}
	
	// Call function to replace Link with Facebook Like-Button IFRAME
	$$('.toolbox-facebook-button a.load-fb-button').each(function(el){
		el.addEvent('click', function(e){
			e.stop();
			var url = this.getProperty('rel');
			var parentElement = this.getParent('.toolbox-facebook-button');
			if(parentElement.parentNode.getProperty('class') == 'footerContent') {
				toolBoxLoadFbButton(parentElement, url, 'standard');
			}else{
				toolBoxLoadFbButton(parentElement, url);
			};
			
		});
	});
	
});

function dump(myvar)
{
	var dump="";
	for (i in myvar) dump += i+": "+myvar[i]+"<br/>\n";
//	alert(dump);
	return dump;
}


