$(document).ready(function() {

	//fix PNG-BUG IE<=6
	$('img').ifixpng();
	$('#metaa').ifixpng();
	$('#main_footer').ifixpng();
	$('#banner img').ifixpng();
	$('.icon_img').ifixpng();
	$('.panel-overlay').ifixpng();

	//überprüfen ob IE 6
	var ie6 = false;
	var ie7 = false;
	if ($.browser.msie) {

		if ($.browser.version<7) {
			ie6 = true;
		} else if ($.browser.version<8) {
			ie7 = true;
		}
	}

	//MAP einbinden
	if($("#myMap").length>0) {

		$("#myMap").html('<img src="../../style/loading.gif" alt="" />');

		LazyApiLoader.Load(GetECMap);

	}

	//Pin zur Karte hinzufügen
	$("#poi_suche_map input").change(function() {

		load_map();

	});

	//Pin zur Karte hinzufügen
	$("#event_suche_map input").change(function() {

		load_map();

	});

	//Metaa
	$("li.metaa").hover(

		function () {

			var bu_up = $(this).children("img").attr("rel");

			//do Button in rel schreiben
			$(this).children("img").attr("rel", $(this).children("img").attr("src"));

			//Button austauschen
			$(this).children("img").attr("src", bu_up)

			//Position des Buttons ermitteln
			var position = $(this).position();

			if (ie6 || ie7) {

				//Breite des UL (Vater)
				var width_ul = $(this).children("ul").width()-50;

				$(this).children("ul").children("li").each(function() {

					$(this).children("a").width(width_ul);

				});

			}

			//Primärnavigation positionieren und einblenden
			if (ie6) {
				$(this).children("ul").css("left", 1);
				$(this).children("ul").css("top", 30);


			} else {
				$(this).children("ul").css("left", position.left + 1);
				$(this).children("ul").css("top", position.top + 30);
			}


			var width_ul = $(this).children("ul").width();

			$(this).children("ul").show();

		},

		function () {

			var bu_do = $(this).children("img").attr("rel");

			//up Button in rel schreiben
			$(this).children("img").attr("rel", $(this).children("img").attr("src"));

			//Button austauschen
			$(this).children("img").attr("src", bu_do)

			//Primärnavigation ausblenden
			$(this).children("ul").hide();

		}

	);

	//Tab
	$("div.tab").hover(

		function () {

			var bu_up = $(this).attr("rel");

			//do Button in rel schreiben
			$(this).attr("rel", $(this).children("img").attr("src"));

			//Button austauschen
			$(this).children("img").attr("src", bu_up)

		},

		function () {

			var bu_do = $(this).attr("rel");

			//up Button in rel schreiben
			$(this).attr("rel", $(this).children("img").attr("src"));

			//Button austauschaen
			$(this).children("img").attr("src", bu_do)

		}

	);

	$("div.tab").click(function() {

		//alle ausblenden
		$(".tabcontent").hide();

		$("#content_" + $(this).attr("id")).show();

		//aktuelles Tab speichern
		var akt_tab = $(this);

		//alle Buttons austauschen
		$(".tab").each(function() {

			$(this).children("img").attr("src", $(this).children("img").attr("src").replace("up", "do"));

		});

		//Buttons austauschen
		akt_tab.attr("rel", akt_tab.children("img").attr("src").replace("do", "up"));
		akt_tab.children("img").attr("src", akt_tab.children("img").attr("src").replace("do", "up"));

	});

	//Suche aufklappen
	$("div.box2").click(function() {

		var box2_id = $(this).attr("id");

		// Alle Boxen außer die angeklickte slideUp
		$(".box2_content").not($("#" + box2_id + "_content")).slideUp();

		// Die angeklickte Box slideToggle
		$("#" + box2_id + "_content").slideToggle();


	});

	//Navigation Links
	$("img.navi_left_main").click(function() {

		if ($(this).next("ul").css("display")=="block") {
			$(this).next("ul").hide();
		} else {
			$(this).next("ul").show();
		}

	});

		//Navigation Links
	$("p.poi_info_uebers, p.mp3_info_uebers").click(function() {


		$(".more_information").not($(this).next("ul")).hide();

		if ($(this).next("ul").css("display")=="block") {
			$(this).next("ul").hide();
		} else {
			$(this).next("ul").show();
		}

	});

	//drucken
	$("#drucken").click(function() {

		window.print();

	});

	// Default value Suchen
 	$("#suche_text").defaultValue("Search...");


	function customRange(input) {
		$("#editor_1").hide();
	    return {
	    	minDate: (input.id == "bis" ?
	        $("#von").datepick("getDate") : null),
	        maxDate: (input.id == "von" ?
	        $("#bis").datepick("getDate") : null)
	   };
	}


	$('#von,#bis').datepick({
		beforeShow: customRange,
		showOn: 'both',
		buttonImage: '/style/calendar.gif',
		buttonImageOnly: true,
		regional: 'de',
		minDate: 0
	});


	//Tab-Navigation Website / Karte
	$(".tab").click(function() {

		var tab_id = $(this).attr('id');

		//alle Bilder austauschen up -> do
		$(".tab").each(function() {

			$(this).attr("src", $(this).attr("src").replace("up", "do"))

		});

		//aktives Bild do -> up
		$(this).attr("src", $(this).attr("src").replace("do", "up"))

		//Alle Tabs ausblenden
		$(".tabcontent").hide();


		//aktives Tab einblenden
		$("#content_"+ tab_id).fadeIn();

	});

	$(".tooltip").tooltip({
		showURL: false,
		fade: 250,
		top: -15,
    	left: 10
    });


    // Tourist packages
	$("select#auswahl").change(function () {

		$("#auswahl option:selected").each(function () {
			var anzeigen = $(this).val();

			window.location.href = rewritepath+"?ort="+anzeigen;
        });

	});

	$('#photos').galleryView({
		panel_width: 630,
	    panel_height: 650,
	    frame_width: 87,
	    frame_height: 65,
	    background_color: 'none',
	    border: 'none',
	    nav_theme: 'dark',
	    filmstrip_position: 'top',
	    overlay_position: 'top'
	});

	//Validierung
	$("#validate_form").validate();

	//************ Login Bereich Menü ********************/

	// Breite der meta-Button
	$(".login_navi_meta").each(function(){
		var mata_width = $(this).width();
		$(this).parent().width(mata_width+11);
	});

	// Sekundär-Navigation anzeigen/ausblenden
	$(".login_navi_bg_img").hover(
		function(){

			$(this).children("ul").show();

			var li_height = 0;

			$(this).parent("ul").children("li").each(function(){

				// CSS top-Position berechnen
				if($(this).hasClass('login_navi_bg_img')) {

					// +8 => padding-top vom Klasse 'ul.login_navi_primaer'
					$(".login_navi_sek").css("top",li_height+8);
				}
				// Höhe +4 => padding vom Klasse 'ul.login_navi_primaer li'
				li_height = li_height + $(this).height() + 4;

			});
		},
		function(){

			$(this).children("ul").hide();
    });

	// Primar-Navigation anzeigen/ausblenden
	$(".list_menue").hover(
		function(){

			$(this).children("ul").show();

    	},
    	function(){

			$(this).children("ul").hide();
    });


	// Captcha
	$("#captcha").click(function(){

		var random = Math.floor(Math.random()*25600);

		$("#captcha img").attr({
			src: "../../captcha/image.php?new_captcha=true&" + random
		});
	});


	/* Größe Schriftart ändern*/
	//Schriftgröße kleiner
	$("#kleiner").click(function() {

		if (!document.getElementById("root").style.fontSize) {
			var fontsize = 1.1;
		} else {
			var fontsize = document.getElementById("root").style.fontSize;
		}
		fontsize = parseFloat(fontsize)-0.1;

		if (fontsize>0.8) {
			document.getElementById("root").style.fontSize = fontsize + "em";
		}

	});

	//Schriftgröße kleiner
	$("#groesser").click(function() {

		if (!document.getElementById("root").style.fontSize) {
			var fontsize = 1.1;
		} else {
			var fontsize = document.getElementById("root").style.fontSize;
		}
		fontsize = parseFloat(fontsize)+0.1;

		if (fontsize<1.8) {
			document.getElementById("root").style.fontSize = fontsize + "em";
		}

	});


	//*************** Audioguide *************************


	// Zip download
	$("#zip_mp3, .poi_zip_mp3, #poi_zip_mp3_form").click(function(){

		if($(this).hasClass("poi_zip_mp3")) {
			var this_zip = $(this);
		}

		var poi_value = "";
		var in_shadowbox = "";

		if($("#show_pois").val()) {
			
			poi_value = $("#show_pois").val();
		
		} else if(this_zip!="undefined" && $(this_zip).attr("rel")){
			
			poi_value = $(this_zip).attr("rel");
		
		} else {
			
			poi_value = $("#poi_zip_mp3_form").attr("rel");
			in_shadowbox = 1;
		}


		//loading einblenden -> wird ausgeblendet sobald alles geladen ist

		if(!in_shadowbox) {
			$("#loading").height($(document).height());
			$("#loading").width($(document).width());
			$("#loading_img").height($(document).height());
			$("#loading_img").width($(document).width());

			$("#loading").show();
			$("#loading_img").show();
			$("#loading_img img").center();
		}

		// loading einblenden bei click auf link
		$("#loading").show();
		$("#loading_img").show();

		$('body').append('<iframe src="' + liveurl + "inc/ajax.php?make_zip=" + poi_value + '" style="display:none;"></iframe>');

		$.get(liveurl + "inc/ajax.php?zip_delete=" + poi_value + "_temp", function(data){

			$("#loading").hide();
			$("#loading_img").hide();

		});

	});

	// Klick auf MP3 anhören
	$(".mp3_anhoeren").click(function(){

		// mp3 id
		var mp3_id = $(this).attr("id");

		// Link informationen
		$.getJSON(liveurl + "inc/ajax.php?mp3_info=1&mp3_id=" + mp3_id, function(data2) {

			window.open(liveurl + "/c_mp3/" + data2.file);

		});

	});


	//*************** ENDE Audioguide *************************

});
