if(!com) var com={};
if(!com.videotaxi) com.videotaxi={};
if(!com.videotaxi.filter) com.videotaxi.hilfe={};

com.videotaxi.hilfe={
	boxes_js : com.videotaxi.boxes,
	kunden_js: com.videotaxi.kunden,
	registerHandlers: function(){
		var symbole = $$('[mouseover=hilfe]');
		var self=this;
		symbole.each(function(el){
			el.observe('click',function(event){ //mouseover
				if($('olfg')){
					if($('olfg').visible()){
						return;
					}
				}
				self.initFaqBox(el);
				self.fillAndShowFaqBox(el);
//				el.observe('mouseout',function(event){ //mouseover
//					self.boxes_js.closeOverlay(true, "vert");
//					el.stopObserving('mouseout');
//				});
			});

		});
	},	
	registerSingleHandler: function(el){
		if (el) {
			var self = this;
			el.observe('click', function(event){ //mouseover
				self.initFaqBox(el);
				if ($('olfg')) {
					$('olfg').setStyle({ // z-index => zIndex 
						zIndex: 6
					})
				}
				self.fillAndShowFaqBox(el);
			//			el.observe('mouseout',function(event){ //mouseover
			//				self.boxes_js.closeOverlay(true, "vert");
			//				el.stopObserving('mouseout');
			//			});
			});
		}
	},	
	fillAndShowFaqBox: function (el){
		this.showFaqBox(el);
		this.kunden_js.showLoading($('hilfe_inhalt'));
		// Parameter für Funktion auslesen
		var faq_id = el.readAttribute('faq_id');
		var faq_gruppe = el.readAttribute('faq_gruppe');
		if(faq_id==null && faq_gruppe == null){
			this.updateFaqBox($('hilfe_inhalt'),"Es wurde leider kein Hilfe-Text gefunden.");
			return;
		}
		var url = "http://" + location.hostname + "/" + com.videotaxi.kunden.vtid+ "/ajax";
		var whereHash = new Hash();
		if (faq_id != null) {
			whereHash.set('id_frage', faq_id);
		}
		if (faq_gruppe != null) {
			whereHash.set('id_fragengruppe', faq_gruppe);
		}	
		var fieldHash = new Hash();
		fieldHash.set('where', whereHash);
		var paramArr = new Array("videotaxi", "", "Faq", fieldHash);
		var self = this;		
		var content = "";
		try {
			this.ajaxcall = new Ajax.RPCRequest(url, {
				methodName: 'get',
				methodParams: paramArr,
				contentType: 'text/xml',
				onComplete: function(transport){
					//alert("complete: " + transport.responseText);
					var erg = self.ajaxcall.responseObject;
					if (erg && erg.length > 0) {
						erg.each(function(child){
							//alert("Child: " + child['frage']);
							content += "<b>Frage:</b><br />\n" + child['frage'] +"\n<br /><b>Antwort:</b><br />\n" + child['antwort']+"<br /><br />\n";
						});
					} else { // keine Rückgabe bzw. Fehler in API-Library
						content = "Keine Hilfe gefunden.";
					}
					self.updateFaqBox($('hilfe_inhalt'),content);
				},
				onException: function(transport, e){
					/**
					 * @TODO Bessere Fehlermeldung. Globale Methode zur Fehlerausgabe?
					 */
					alert("Beim Abrufen der Hilfe ist ein Fehler aufgetreten.\nBitte versuche es zu einem späteren Zeitpunkt noch einmal." + e);
					//this.bug_tracking(e, 'fillAndShowFaqBox',3);
				}
			});
		} 
		catch (e) {
			this.bug_tracking(e, 'fillAndShowFaqBox',3);
		}	
	},
	updateFaqBox: function(el,text){
		el.update(text);
	},
	initFaqBox: function(el){
		this.boxes_js.insertOverlay(el,"");
		var content = "<div id='headline'>" +
			"<div style='float:left;'>Hilfe:</div>" +
			"<img id='overlay_closebutton' src='/images/default/icons/close_24x24.png' />" +
			"<div class='cleaner'>&nbsp;</div>" +
			"</div>" +
			"<div class='cleaner'>&nbsp;</div>" +
			"<div id='hilfe_inhalt'>&nbsp;</div>";
		$('olfg_content').update(content);
		var self=this;
		if ($('overlay_closebutton')) {
			$('overlay_closebutton').observe('click', function(){
				self.boxes_js.closeOverlay(true, "vert")
			})
		}
	},
	showFaqBox: function(el){
		this.boxes_js.openOverlay(true, "vert", 300);
	}
}

new PeriodicalExecuter(function(pe)	{
	if($('body'))	{
		com.videotaxi.hilfe.registerHandlers();
		pe.stop();
	}
},1)