/*
########################################################################
##
##               Titel: JavaScript Seh-Netz
##           Dateiname: sehnetz.js
##         Verzeichnis: /js/
##               Autor: Marco Krings
##  letzter Bearbeiter: Marco Krings
##    Erstellungsdatum: 2010-01-01
##    Veröffentlichung: 2010-xx-xx
##   Bearbeitungsdatum: 2010-01-01
##             Version: 1.0.0
##           Datenbank: -
##         Komponenten: -
##           Kommentar: -
##
########################################################################
*/

$(document).ready(function() {


// GET-Parameter eines Links abfragen
function getParam(tLink, tParam) {
	var aList = tLink.split("#")[0].split("&");
	for(var i = 0; i < aList.length; i++) {
		var aParam = aList[i].split("=");
		if (aParam[0]==tParam) return aParam[1];
	}
	return "";
}


// ##################################################################
// ## N A V I G A T I O N
// ##################################################################

var hTimer;
$(".ausblenden").hide();

var sAdresse = document.location.toString();
if (sAdresse.match("#nav")) {
	var sAnker = sAdresse.split("#")[1];
	$("#"+sAnker).show();
} else {
	$(".einblenden").show();
}

function handle(e) {
	function einblenden() {
		if(!$(".ausblenden:visible",oElement).length)
			$(".ausblenden").slideUp();
		$(".ausblenden:hidden", oElement).slideDown(500);
	}
	var oElement = this;
	if (hTimer) window.clearTimeout(hTimer);
	hTimer = window.setTimeout(einblenden, 200);
};

$(".ausblender").mouseover(handle);
$(".ausblender").click(handle);

// ##################################################################
// ## T A B E L L E N Z E I L E
// ##################################################################

$("tr").mouseover(function() {
	$(this).addClass("ansicht");
});
$("tr").mouseout(function() {
	$(this).removeClass("ansicht");
});

$("table.liste tr:even").addClass("zeile1");
$("table.liste tr:odd").addClass("zeile2");
$("table.liste td").css("border",'0 solid');

// ##################################################################
// ## B U N D E S L A N D Ü B E R S I C H T
// ##################################################################

$("#bundeslandimages area").mouseover(
	function(e) { hoverBundeslandKarte(this, "area_", e) }
);
$("#bundeslandimages area").mouseout(
	function() { resetBundeslandKarte(this, "area_") }
);
$("#bundeslandliste a").mouseover(
	function(e) { hoverBundeslandKarte(this, "link_", e) }
);
$("#bundeslandliste a").mouseout(
	function() { resetBundeslandKarte(this, "link_") }
);

function hoverBundeslandKarte(sAuswahl, sBereich, e) {
	var sKuerzel = sAuswahl.id.toLowerCase();
	if (sKuerzel.match(sBereich)) {
		// Tooltipp deaktivieren
		$(sAuswahl).attr("title","");
		// Karte anzeigen
		var sWert = sKuerzel.split(sBereich)[1];
		document.dkarte.src = "images/dkarte/dkarte_"+ sWert +".gif";
		// Eintrag in Liste auswählen
		$("#link_"+sWert).addClass("markierung");
		$("#link_"+sWert).parent().css("background-image","url('images/pfeil_links_klein.png')");
		// Tooltipp
		if (typeof $(sAuswahl).attr("alt") != "undefined") {
			$("#ausgabe").addClass("ausgabe_css")
			             .css("top",e.pageY)
			             .css("left",e.pageX+15)
			             .text($(sAuswahl).attr("alt"));
		}
	}
}

function resetBundeslandKarte(sAuswahl, sBereich) {
	var sKuerzel = sAuswahl.id.toLowerCase();
	if (sKuerzel.match(sBereich)) {
		var sWert = sKuerzel.split(sBereich)[1];
		document.dkarte.src = "images/leer.gif";
		$("#link_"+sWert).removeClass("markierung");
		$("#link_"+sWert).parent().css("background-image","none");
		$("#ausgabe").text("")
		             .removeClass("ausgabe_css");
	}
}
// ##################################################################
// ## D E U T S C H L A N D K A R T E
// ##################################################################

$("#deutschlandkarte img").maphilight({
	    fillColor: '194597'
	, fillOpacity: 0.4
	, strokeColor: '194597'
	, strokeWidth: 2
});

$("#deutschlandkarte area").mouseover(function(e) {
	var aData = $(this).data('maphilight') || {};
	aData.groupBy = 'rel';
	$(this).data('maphilight', aData);
	hoverDeutschlandKarte(this, e);
});

$("#deutschlandkarte area").mouseout(function() {
	resetDeutschlandKarte();
});

$(".karten area").mouseover(function(e) {
	hoverDeutschlandKarte(this, e);
});

$(".karten area").mouseout(function() {
	resetDeutschlandKarte();
});

function hoverDeutschlandKarte(sAuswahl, e) {
	if (typeof $(sAuswahl).attr("alt") != "undefined") {
		$(sAuswahl).attr("title","");
		$("#ausgabe").addClass("ausgabe_css")
		             .css("top",e.pageY)
		             .css("left",e.pageX + 15)
		             .text($(sAuswahl).attr("alt"));
	}
}

function resetDeutschlandKarte() {
	$("#ausgabe").text("")
	             .removeClass("ausgabe_css");
}

// ##################################################################
// ## L I G H T B O X
// ##################################################################

$("a.lightbox").lightBox();

// ##################################################################
// ## F O R M U L A R E
// ##################################################################

$("form.formulare p").mouseover(function () {
	$(this).addClass("markierung");
});

$("form.formulare p").mouseout(function () {
	$(this).removeClass("markierung");
});

// ##################################################################
// ## T I T E L   S T A R T S E I T E
// ##################################################################

function setStartTitel() {
	var oDatum  = new Date();
	var nStunde = oDatum.getHours();
	if (nStunde >= 0 && nStunde < 12) {
		sTitel = "Guten Morgen";
	} else if (nStunde >= 12 && nStunde < 18) {
		sTitel = "Guten Tag";
	} else if (nStunde >= 18 && nStunde <= 23) {
		sTitel = "Guten Abend";
	}
	var sText = $("#inhalt h1:first").html();
	$("#inhalt h1:first").html(sText.replace(/Herzlich/, sTitel+","));
}
setStartTitel();

// ##################################################################
// ## F L U G H A F E N K A R T E
// ##################################################################

$("#flughafen area").mouseover(function(e) {
	$(this).attr("title","");
	if (typeof $(this).attr("alt") != "undefined") {
		$("#ausgabe").addClass("ausgabe_css")
		             .css("top",e.pageY-10)
		             .css("left",e.pageX+10)
		             .text($(this).attr("alt"));
	}
});

$("#flughafen area").mouseout(function() {
	$("#ausgabe").text("")
	             .removeClass("ausgabe_css");
});

// ##################################################################
// ## I N F O B R I E F S U C H E
// ##################################################################

$("form.suche2 p.keinabsatz").html("Klicken Sie auf die &Uuml;berschriften zum Ausklappen der Eigenschaften.");
$(".suche_ausblenden").hide();
$(".suche_einblenden legend").attr("title","Auf diese Überschrift klicken zum Ausklappen");
$("input:checkbox:checked").addClass("auswahl2");
$("input:checkbox:checked").siblings().addClass("auswahl2");

$(".suche2 input:checkbox").click(function() {
	if (this.checked == true) {
		$(this).addClass("auswahl2");
		$(this).siblings().addClass("auswahl2");
	} else {
		$(this).removeClass("auswahl2");
		$(this).siblings().removeClass("auswahl2");
	}
});

$(".suche_einblenden legend").click(function() {
	$("form.suche2 .suche_ausblenden").slideUp(500);
});

$("fieldset.suche_einblenden").click(function() {
	if(!$(".suche_ausblenden:visible",this).length) {
		$(".suche_ausblenden", this).slideDown(500);
	}
});

// ##################################################################
// ## F A Q
// ##################################################################

$("#faq p.keinabsatz").html("Klicken Sie auf die Fragen zum Ausklappen der Antworten.");
$("#faq dt").each(function() {
	$(this).append("<a id=\"faq_linkein"+$(this).attr("id")+"\" href=\"#"+$(this).attr("id")+"a\">ausklappen</a>"+
	               "<a id=\"faq_linkaus"+$(this).attr("id")+"\" href=\"#"+$(this).attr("id")+"\">einklappen</a>");
	$("#faq_linkaus"+$(this).attr("id")).hide();
});
$("#faq dd").hide();
$("#faq dt").click(function(e) {
	if($(this).next("dd:visible").length) {
		$(this).next("dd").slideUp(500);
		$("#faq_linkein"+$(this).attr("id")).show();
		$("#faq_linkaus"+$(this).attr("id")).hide();
	} else {
		$(this).next("dd").slideDown(500);
		$("#faq_linkein"+$(this).attr("id")).hide();
		$("#faq_linkaus"+$(this).attr("id")).show();
	}
	e.preventDefault();
});

// ##################################################################
// ## S T R E C K E N V E R Z E I C H N I S
// ##################################################################

$("form.streckenverzeichnis ul li a").click(function(e) {
	if ($(this).attr("rel")=="ein") {
		$("form.streckenverzeichnis input:checkbox").attr("checked","checked");
	} else if ($(this).attr("rel")=="aus") {
		$("form.streckenverzeichnis input:checkbox").attr("checked","");
	}
	e.preventDefault();
});

// ##################################################################
// ## S T Y L E S W I T C H E R
// ##################################################################

$("#styleswitcher #style_auswahl").change(function() {
	$("#styleswitcher form").submit();
});

// ##################################################################
// ## B A H N H O F S A B F R A G E
// ##################################################################

$("#bfabfrage1").autocomplete({
	source: function(sRequest, response) {
		$.getJSON("functions/m_bahnhofsabfrage/ajax.bahnhofsabfrage.php", sRequest, function(aData) {
			response(aData);
		});
	},
	minLength: 1,
	delay: 300,
	select: function(e, aWerte ) {
		$("#bfabfrage1").val(aWerte.item.label);
		$("#bfabfrage").submit();
	}
});

$("#bfabfrage_liste li a").live("click", function(e) {
	e.preventDefault();
	var sBahnhof = getParam($(this).attr("href"),"bahnhof");
	var sAllebf  = getParam($(this).attr("href"),"allebf");
	$.get("functions/m_bahnhofsabfrage/ajax.bahnhofsabfrage2.php", {bahnhof : sBahnhof, allebf : sAllebf}, function(sResult) {
		$("#bfabfrage_auswahl").html(sResult);
		window.location.hash = "#bfabfrage_auswahl";
		$("html,body").scrollTop($("#bfabfrage_auswahl").offset().top);
	});
});

// ##################################################################
// ## L I N K H A N D L E R
// ##################################################################

$(".linkhandlerjs li a").live("click", function(e) {
	e.preventDefault();
	var oListe = $(".linkhandlerjs").has(this);
	var sFile  = oListe.attr("id").split("_")[0];
	var sValue = getParam($(this).attr("href"), oListe.attr("id").split("_")[1]);
	$.get("template/ajax."+sFile+".php", {ajax: sValue}, function(sResult) {
		$("#auflistung").html(sResult);
		window.location.hash = "#auflistung";
		$("html,body").scrollTop($("#auflistung").offset().top);
	});
});

// ##################################################################
// ## T E X T B O X
// ##################################################################

$("textarea.resizable").resizable({
	handles: 's'
});

// ##################################################################
// ## 
// ##################################################################

});
