;var ads = {
    language: "en",
    country: "<?php echo file_get_contents('http://app.germany.travel/default/index/getUserCountry?q='.strtr(base64_encode($_SERVER['HTTP_ACCEPT_LANGUAGE']), '+/=', '-_,')); ?>",
    page: {
        textTitle: "Tourism in Germany – travel, breaks, holidays"
    },
    translation: {
        textMap: "Map",
        textSatellite: "Satellite",
        textTerrain: "Terrain",
        textClose: "End map mode",
        textSearch: "Search> City, town, region ...",
        textReadOn: "read more »",
        textMore: "More »",
        textMoreAt: "More at »",
        textBooking: "Book",
        textAdvertisement: "Advertisement",
        hrefLogo: "",
        hrefMap: "/en/kartenansicht.html"
    }
};



;var config = {};
;var widget = {};

;var application = {

    map: null,
    
    mtk: {
		menu: {}
    },

    country: "",
    
    isIpad : false,
    
    language: "en",
    
    page: {
        textTitle: "Tourism in Germany – travel, breaks, holidays"
    },
    
    content: {
		level: 1
    },
    
    translation: {
        textMap: "Map",
        textSatellite: "Satellite",
        textTerrain: "Terrain",
        textClose: "End map mode",
        textSearch: "Search> City, town, region ...",
        hrefLogo: "",
        hrefMap: "/en/kartenansicht.html"
    },
    
    mapWidget: { setState: function() {}, setItem: function() {} },
    
	url: {
		search: {				"en": "/en/search-results.html",
				"de": "/de/suchergebnisse.html",
				"fr": "/fr/resultat-de-la-recherche.html",
				"es": "/es/resultados-de-la-busqueda.html",
				"nl": "/nl/zoekresultaten.html",
				"it": "/it/risultati-della-ricerca.html",
				"ru": "/ru/search-results.html",
				"pl": "/pl/wyniki-wyszukiwania.html",
				"pt": "/pt/suchergebnisse.html",
				"dk": "/dk/sgeresultater.html",
				"cn": "/cn/search-results.html",
				"jp": "/jp/search-results.html",
				"kr": "/kr/search-results.html",
				"ae": "/ae/search-results.html",
				"no": "/no/resultater.html",
				"fi": "/fi/hakutulokset.html",
				"hu": "/hu/a-kereses-eredmenye.html",
				"il": "/il/search-results.html",
				"tr": "/tr/arama-sonucu.html",
				"se": "/se/soekresultat.html",
				"cz": "/cz/vysledky-vyhledavani.html",
				"gr": "/gr/search-results.html",
				"rs": "/rs/suchergebnisse.html",
				"lv": "/lv/suchergebnisse.html",
				"ee": "/ee/otsingutulemused.html",
				"lt": "/lt/suchergebnisse.html"
},
		
		iframe: {				"en": "/en/iframe.html",
				"de": "/de/iframe.html",
				"fr": "/fr/iframe.html",
				"es": "/es/iframe.html",
				"nl": "/nl/iframe.html",
				"it": "/it/iframe.html",
				"ru": "/ru/iframe.html",
				"pl": "/pl/iframe.html",
				"pt": "/pt/iframe.html",
				"dk": "/dk/iframe.html",
				"cn": "/cn/iframe.html",
				"jp": "/jp/iframe.html",
				"kr": "/kr/iframe.html",
				"ae": "/ae/iframe.html",
				"no": "/no/iframe.html",
				"fi": "/fi/iframe.html",
				"hu": "/hu/iframe.html",
				"il": "/il/iframe.html",
				"tr": "/tr/iframe.html",
				"se": "/se/iframe.html",
				"cz": "/cz/iframe.html",
				"gr": "/gr/iframe.html",
				"rs": "/rs/iframe.html",
				"lv": "/lv/iframe.html",
				"ee": "/ee/iframe.html",
				"lt": "/lt/iframe.html"
}
		
    },
	
    
    tabLocation: null,
    
    loadingGallery: false,
    loadingMap: false,
    
    getEventType: function() {
        return (navigator.userAgent.match(/iPad/i)) ? "touchstart" : "click";
    },
    
    init: function() {
        this.isIpad = navigator.userAgent.match(/iPad/i);
        
        // iPad-Magic 
        if (this.isIpad) {
			
			/**
			 * iPad Background repositioning
			 *
			 * EDIT: Apple released an update for fixed backgrounds...
			 */
			/*
			var
				bg = $("#bg"),
				sz = $("#bg,#supersized li");
			
			$("#supersized").css("overflow", "visible");
			
			$(window).scroll(function() {
				var t = $(window).scrollTop();
				bg.css({"top": t});
			});
			*/
			
			/*
            $(document).bind('scroll', function(e) {
                $('#supersized').css({'top':$('.layoutPage').position().top});
            });
            */
            
			$("div.headerNavigationContainer ul.headerNavigation li a.language").bind(this.getEventType(), function(e){
				e.preventDefault();
				var $c = $(this).parent().children("ul");
				if ($c.is(":visible")) {
					$c.fadeOut("fast");
				} else {
					$c.fadeIn("fast");
				}
			});
        }
        
        // small background-slideshow
        if (document.width <= 1024 || this.isIpad) {
        	$("#bgImageSlideContainer").addClass("small" + (this.content.level === 1 ? " smallHome" : "") );
        }
        
        // language menu fade
		$("div.headerNavigationContainer ul.headerNavigation li").hover(function(){
			$(this).children("ul").stop().fadeTo("fast", 1);
		},function(){
			$(this).children("ul").stop().fadeTo("slow", 0.0, function() { $(this).hide() });
		});
		
		
        if ((document.location.toString().indexOf("/hu/ms/ungarn") == -1) && $.cookie && $.cookie("hucampaign") == "1") {            
            $(".layoutPageHead").append('<div style="position:fixed;left: 0; top: 40px; width:230px; height: 81px"><a href="http://www.germany.travel/hu/ms/ungarn/ismerdmegnemetorszagot_game.html"><img src="http://www.germany.travel/applications/microsites/gewinnspiel-ungarn/zurueck-btn.png" border="0"/></a></div>');
        }
        
        // lh navigation hack
        if ($("body.page_ms.page_lufthansa").length == 1) {
			var a=['/de/microsite/lufthansa/newsletter/newsletter.html','/de/microsite/lufthansa/angebote/angebote.html'];
			$('.navigationMain a').each(function(){var _s=this; for (var i = 0; i < a.length; i++) if(a[i] == $(_s).attr('href')) $(_s).attr('target','_blank'); });
        }
        
        $("body").click(this.dropdown.closeAll);
        
        application.initFoldingList();
        //application.ieHeightFixed();
        
        application.initSharing();
		application.initKeys();
    },
    
    
    initSharing: function() {
    
		if (typeof addthis !== "undefined") {
			
			$(".sharing-button").each(function(i,el) {
			
				var config = {}, share = {}, $el = $(el);
				
				var a = $(el).attr("data-config");
				if (a) {
					try {
						a = JSON.parse(a);
						if (typeof a == "object") {
							 $.extend(config, addthis_config, a);
						}
					} catch (e) {}
				}
				
				a = $(el).attr("data-share");
				if (a) {
					try {
						a = JSON.parse(a);
						if (typeof a == "object") {
							$.extend(share, addthis_share, a);
						}
					} catch (e) {}
				}
				
				addthis.button(el, config, share);
				
			});
			
			addthis.addEventListener('addthis.menu.open', function() { application.createOverlay("share"); });
			addthis.addEventListener('addthis.menu.close', function() { application.removeOverlay(); });
		}
		
    },
    
    /**
     * global search init
     */
    initSearch: function() {
    
		$("#form_search").submit(function(e) {

			application.createSearch($("#search_content").val());

			e.preventDefault();
			return false;
		});				
	},
    
    /**
     * global folding list init
     */
    initFoldingList: function() {
        var $headline = $("div.foldinglist>h3"); 
        
        if ($headline.length > 0) {
            $headline.click(function() {
                if ($(this).hasClass("open")) {
                    $(this).removeClass("open").addClass("close").siblings(".foldingListContent").removeClass("foldingListInnerActive").slideUp();
                } else {
                    $(this).removeClass("close").addClass("open").siblings(".foldingListContent").addClass("foldingListInnerActive").slideDown();
                }
            });
            
        } else {
            $(".foldingListHeadline>h4").click(function() {
                if ($(this).hasClass("open")) {
                    $(this).parents("div.foldingListInner").removeClass("foldingListInnerActive");
                    $(this).removeClass("open").addClass("close").parent().siblings("*").slideUp();
                } else {
                    $(this).parents("div.foldingListInner").addClass("foldingListInnerActive");
                    $(this).removeClass("close").addClass("open").parent().siblings("*").slideDown();
                }
            });
        }
    },
    
    
    initKeys: function() {
		
		var
			keys = [],
			codes = {
				dxinfo: {
					sequence: "100,120,105,110,102,111",
					callback: function(){
						var res = "";
						$("head>meta").each(function(){
							var
								n = $(this).attr("name");
							if (n.indexOf("dx-") >= 0) {
								res += n + ": " + $(this).attr("content") + "\n"; 
							}
						});
						alert(res);
					}
				}
			};
		
		$("body").keypress(function(e){
		
			keys.push(e.keyCode || e.charCode);
			var s = keys.toString();
			$.each(codes, function(i,e){
				if (typeof e.sequence === "string" && $.isFunction(e.callback) && s.indexOf(e.sequence) >= 0) {
					e.callback();
					keys = [];
				}
			});
		});
    },
    
    /**
	 * IE page height fix
	 */
	fixPageHeight: function() {
		/*
        // ie height fix
        if($.browser.msie) {
        
			// added for reinitialising page height
			$('body').css({'height': 'auto', 'min-height': 'auto'});
			
			// moved from application.init()
            $('body').css({'min-height': $('.layoutPage').height(), 'overflow': 'hidden' });
            
            // moved from page template
            $('body').css({'height':$('.layoutPage').height() + 'px' });
        }
        */
    },
    
    
    setMapItem: function(theme, lat, lng) {
        theme    = theme || "";
        
        lat        = lat || 0;
        lng        = lng || 0;
        
        lat        = parseFloat(lat);
        lng        = parseFloat(lng);
        
        lat        = isNaN(lat) ? 0 : lat;
        lng        = isNaN(lng) ? 0 : lng;
        
        if (application.mapWidget != null) {
            if (lat == 0 || lng == 0) {
                theme = "";
            }
            application.mapWidget.setItem(theme, lat, lng);
            if (theme != "" && lat != 0 && lng != 0) {
                application.lastMapItem = {t: theme, la: lat, ln: lng};
            }
        }
    },
    
    setMapImage: function(image, lat, lng) {
    
        return;
    
        image    = image || "";
        lat        = lat || 0;
        lng        = lng || 0;
        
        if (application.mapWidget != null && image != "" && lat != 0 && lng != 0 && application.mapWidget.setImage) {
            application.mapWidget.setImage(image, lat, lng);
        }
    },

    createOverlay: function(clazz) {
        
        clazz = clazz || "";
    
        var $overlay = $("#overlayModal");
        if ($overlay.length > 0) {
            $overlay.removeClass().addClass(clazz);
            
            var op = parseFloat($overlay.css("opacity")) || .55;
            
			if ($.support.opacity) {
				$overlay.css({ display: "block", opacity: 0 }).animate({ opacity: op });
			} else {
				$overlay.css({ display: "block", opacity: 1, filter: 'alpha(opacity=0)' }).animate({filter: 'alpha(opacity='+ op*100 +')' });
			}
        } else {
            $overlay = $("<div></div>").attr("id", "overlayModal").appendTo("body").addClass(clazz);
            
            var op = parseFloat($overlay.css("opacity")) || .55;
            
			if ($.support.opacity) {
				$overlay.css({ display: "block", opacity: 0 }).animate({ opacity: op });
			} else {
				$overlay.css({ display: "block", opacity: 1, filter: 'alpha(opacity=0)' }).animate({filter: 'alpha(opacity='+ op*100 +')' });
			}
        }
        
        // pause slideshow
        if ($("ul#slideshowHeader").length > 0) {
            $("ul#slideshowHeader").cycle("pause");
        }
        if ($("ul#slideshowHeader").length > 0) {
            $("ul#slideshowTeaser").cycle("pause");
        }
        
        application.ads.hide();
        return $overlay;
    },
    
    removeOverlay: function() {
        application.ads.show();
        var $overlay = $("#overlayModal");
        if ($overlay.length > 0) {
            $overlay.fadeOut(function() { $(this).removeClass(); });
        }
        $("body").removeClass("fullscreen");
        
        // pause slideshow
        if ($("ul#slideshowHeader").length > 0) {
            $("ul#slideshowHeader").cycle("resume");
        }
        if ($("ul#slideshowHeader").length > 0) {
            $("ul#slideshowTeaser").cycle("resume");
        }
        
    },
    
    
    
    createOverlayIframe: function(href, options) {

        href = href || "";

        options = options || {};
        options.top = options.top || "35px";
        options.left = options.left || "0";
        options.width = options.width || "100%";
        options.height = options.height || ($(window).height() - 35);
        
        if (href != "" && $("#overlayIframe").length == 0) {
        
            $('html, body').scrollTop(0);
            
            $overlay = application.createOverlay("iframe");
            
            var ua = navigator.userAgent, event = (ua.match(/iPad/i)) ? "touchstart" : "click";

            $item    = $("<li></li>").text("close").bind(event, application.removeOverlayIframe);
            $control = $("<ul></ul>").attr("id", "overlayIframeControl").append($item).appendTo("body");
            
            $content = $("<iframe></iframe>")
                            .attr("id", "overlayIframe")
                            .attr("src", href)
                            .css("position", "absolute")
                            .css("top", options.top)
                            .css("left", options.left)
                            .css("width", options.width)
                            .css("height", options.height)
                            .css("display", "block")
                            .css("z-index", "1103")
                            .appendTo("body");
            
            $(window).resize(function() {
                $("#overlayIframe").css("height", options.height);
            });
            
            $control.fadeIn();
            $content.fadeIn();
            
            $("body").addClass("fullscreen");
            
            return $content;
        }
    },
    
    removeOverlayIframe: function() {
        $("#overlayIframe").fadeOut().remove();
        $("#overlayIframeControl").fadeOut().remove();
        application.removeOverlay();
    },
    
    
    createGallery: function(href) {
    
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Galerie '+'['+application.language+']','Click');
    
        if (application.loadingGallery != false) {
            return false;
        }
        
        href = href || "";
        target = "";
        var index = href.indexOf("#");
        
        if (index > -1) {
			
            application.tabLocation = href.substring(index+1);
        }
        
        if (href != "" && $("#overlayGallery").length == 0) {
        
            application.loadingGallery = true;
            

            $.get(href, function(data) {
                $overlay = application.createOverlay("gallery");
                $content = $("<div></div>").attr("id", "overlayGallery").appendTo("body");
                $content.append(data);
                $content.fadeIn();
                
                application.iPadFixGallery();
                if ($("#galleryTabs").length > 0) {
                    $("#galleryTabs").tabs({
                        show: function(event, ui) { application.iPadFixGallery(); }
                    });
                }
                
                
                var ua = navigator.userAgent, event = (ua.match(/iPad/i)) ? "touchstart" : "click";
                
                $("div#overlayGallery ul.headerNavigation a.close").bind(event, function() {
                    application.removeGallery();
                });
                
                $('html, body').animate({scrollTop:0}, 'slow');
                
                $("div#overlayGallery a.replace").click(function() {
                    application.replaceGallery($(this).attr("href"));
                    return false;
                });
                
                application.loadingGallery = false;
                return $content;
            }, "html");

        }
    },
    
    evtTabsLoaded: function(event, ui) {
        if (application.tabLocation != null && application.tabLocation != "") {
            $("#galleryTabs").tabs("select", application.tabLocation);
            application.tabLocation = null;
        }
    },
    
    removeGallery: function() {
        $("#overlayGallery").fadeOut().remove();
        application.removeOverlay();
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Galerie '+'['+application.language+']','Click');
    },
    
    replaceGallery: function(href) {
    
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Galerie '+'['+application.language+']','Wechseln');

        if (application.loadingGallery != false) {
            return false;
        }
        
        href = href || "";
        var index    = href.indexOf("#");
        
        if (index > -1) {
            application.tabLocation = href.substring(index+1);
        }
        
        if (href != "") {
        
            if (typeof gallery != "undefined") {
                gallery.destroy();
            }
        
            application.loadingGallery = true;
            
            $.get(href, function(data) {
                $overlay = application.createOverlay("gallery");
                
                $('html, body').scrollTop(0);
                
                $content = $("#overlayGallery");
                if ($content.length > 0) {
                    $content.children().remove();
                } else {
                    $content = $("<div></div>").attr("id", "overlayGallery").appendTo("body").css("opacity", 0);
                }
                $content.append(data);
                
                application.iPadFixGallery();
                if ($("#galleryTabs").length > 0) {
                    $("#galleryTabs").tabs({
                        show: function(event, ui) { application.iPadFixGallery(); }
                    });
                }
                
                /*
                if($.browser.msie) {
                    $('body').css({'height':$('.layoutPage').height() + 'px' });
                    $('#overlayGallery').css({'height':$('.layoutPage').height() + 'px' });
                }
                */
                $content.animate({opacity: 1});
                
                var ua = navigator.userAgent, event = (ua.match(/iPad/i)) ? "touchstart" : "click";
                
                $("div#overlayGallery ul.headerNavigation a.close").bind(event, function() {
                    application.removeGallery();
                    return false;
                });
                
                $("div#overlayGallery a.replace").click(function() {
                    application.replaceGallery($(this).attr("href"));
                    return false;
                });
                
                application.loadingGallery = false;
                
                return $content;
            }, "html");
        }
    },
    
    iPadFixGallery: function() {
        if (navigator.platform == 'iPad') {
            var max = 0;
            $('.layoutPage').each(function() {
                if ($(this).height() > max) {
                    max = $(this).height();
                }
            });
            if($('#galleryTabs').height() > max) {
                max = $('#galleryTabs').height() + $('#galleryTabs').offset().top;
            }
            
            $('#overlayModal').css({'height': max + 'px' });
            $('#overlayGallery').css({'height': max + 'px' });
        }    
    },
    
    ieHeightAuto: function() {
		/*
        if($.browser.msie) {
            var css = {'height':$('.layoutPage').height() + 'px' };
            $('body').css(css);
            $('#overlayModal').css(css);
            $('#overlayGallery').css(css);
        }
        */
    },
    
    ieHeightFixed: function() {
		/*
        if($.browser.msie) {
            var css = {'height':$(window).height() + 'px' };
            $('body').css(css);
            $('#overlayModal').css(css);
            $('#overlayGallery').css(css);
        }
        */
    },
    
    
    createMap: function(themeList, pointList, mapZoom, routeId, options) {
    
        if (application.loadingMap != false) {
            return false;
        }
        
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Karte '+'['+application.language+']','Click');

        themeList                    = themeList    || [];
        pointList                    = pointList    || [];
        mapZoom                      = mapZoom    || 11;
        routeId                      = routeId   || "";

        options = options || {};    
		options = $.extend(true, {
			themes: [],
			points: [],
			zoom: 11,
			routeId: "",
			convertToParentIds: true,
			mtk: {
				menu: MTK.DZTMenuControl,
				logo: MTK.DZTLogoControl,
				mapType: MTK.DZTMapTypeControl
			}
		}, options);
		
		var loc, controls = [];
		
		for (var i in options.mtk) {
			if (typeof options.mtk[i] == "function") {
				controls.push(options.mtk[i]);
			}
		}
		
        if (pointList.length == 0 && ($("ul#slideshowHeader").length == 0 && $("ul#slideshowTeaser").length == 0) && application.lastMapItem) {
            loc = MTK.DZTLocation({ points: [[application.lastMapItem.la, application.lastMapItem.ln]] });
            
        } else if (pointList.length > 0) {
            loc = MTK.DZTLocation({ points: pointList });
        } else {
            loc = MTK.DZTLocation({ themes: themeList });
        }
        
        if ( $.browser.msie ) {
            
            for (var i=0, l=pointList.length; i<l; i++){
                if (pointList[i] instanceof Array){
                    pointList[i] = pointList[i].join("_");
                }
            }            
        
            location.href = application.translation.hrefMap + "?points=" + pointList.join(",") + "&themes=" + themeList.join(",") + "&route=" + routeId + "&pIds=" + options.convertToParentIds + "&back=" + encodeURIComponent(location.href);
            return;
        }    
        
        $('html, body').scrollTop(0);
            
        $overlay = application.createOverlay("map");
        $content = $("#overlayMap");
        
        if ($content.length == 0) {

            application.loadingMap = true;
        
            $content = $("<div></div>").attr("id", "overlayMap").css("opacity", 0).appendTo("body");
            
            MTK.init({ api_key: 'dzt' });
            var map = MTK.createMap("overlayMap", {
                map: {
                    translation: {
                        map:		application.translation.textMap,
                        satellite:	application.translation.textSatellite,
                        terrain:	application.translation.textTerrain,
                        close:		application.translation.textClose,
                        search:		application.translation.textSearch,
                        logo:		application.translation.hrefLogo
                    },
                    size: { offsetBottom: 0 },
                    location: loc,
                    controls: controls,
                    mapType: google.maps.MapTypeId.TERRAIN,
                    options: {
                        minZoom: 6,
                        disableDefaultUI: true,
                        panControl: true,
                        panControlOptions: {
                            position: google.maps.ControlPosition.LEFT_TOP
                        },
                        zoomControl: true,
                        zoomControlOptions: {
                            style: google.maps.ZoomControlStyle.LARGE,
                            position: google.maps.ControlPosition.LEFT_TOP
                        },
                        scaleControl: true,
                        scaleControlOptions: {
                            position: google.maps.ControlPosition.LEFT_BOTTOM                  
                        }
                    }
                },
                clusters: {
                    naming: MTK.i18n.dzt_eintraege,
                    color: "000000",
                    opacities: [0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.75],
                    icon: "http://static.toursprung.com/images/dzt/cluster.png"
                },
                resources: {
                    dzt_pois: {
                        filter: { theme: themeList },
                        convertToParentIds: options.convertToParentIds,
                        markerLimitPerTile: 6,
                        handleInfoWindowClick: false,
                        icon: "custom",
                        template: "v2",
                        clusters: true
                    }
                }
            }, function(map) {
                application.map = map;
                DZTGermanyOutline.setMap(map.gmap);
                
                if (routeId != "") {
                    new google.maps.KmlLayer("http://static.toursprung.com/custom/dzt_pois/" + routeId + ".kml", { preserveViewport: true, clickable: false, map: map.gmap, suppressInfoWindows: true });
                }
            });
            
            window.setTimeout("application.bindCloseMap();", 2000);
            window.setTimeout("application.bindCloseMap();", 5000);
            window.setTimeout("application.bindCloseMap();", 10000);
            
            application.loadingMap = false;
            
        } else {
          
            application.map.config.resources.dzt_pois.filter.theme = themeList;
            application.map.refresh();
            $("#overlayMap").show(function() { MTK.getMap("overlayMap").resize(); });
           
        }
        $("body").addClass("fullscreen");
        
        return $content.animate({opacity: 1});
    },
    
    bindCloseMap: function() {
    
        var ua = navigator.userAgent, event = (ua.match(/iPad/i)) ? "touchstart" : "click";
        
        $('div.mtk-dzt-maptype-close').bind(event, function() { application.removeMap(); });
    },
    
    removeMap: function() {
        $("#overlayMap").hide();
        application.removeOverlay();
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Karte '+'['+application.language+']','Click');
    },
    
    
    createSearch: function(url, search) {
    
    	// 2011-11-14 (jm): search shall now be full page
		if (undefined === search) {
			search = url;
		}
    	
    	document.location.href = application.url.search[application.language] + '?search_content=' + search;
    	return;
    	
       
        application.ads.hide();

        if (typeof ET_Event !== "undefined") ET_Event.eventStart('Suche','Allgemein '+'['+application.language+']','Oeffnen');

        $overlay = application.createOverlay("search");
        $content = $("#overlayContainer");
        
        if ($content.length == 0) {

            $.post(url, {search_content: search}, function(data) {
                $overlay = application.createOverlay("search");
                $content = $("<div></div>").attr("id", "overlayContainer").appendTo("body");
                $content.append(data);
                $content.fadeIn();
                
                var ua = navigator.userAgent, event = (ua.match(/iPad/i)) ? "touchstart" : "click";
                
                $("div#overlayContainer a.close").bind(event, function() {
                    application.removeSearch();
                });
                
                $("#form_search_overlay").submit(function(e) {
                    e.preventDefault();
                    application.replaceSearch(url ,$("#search_content_overlay").val());
                    return false;
                });                
                
                $("#searchPagination a").click(function() {
                        application.replaceSearch(url, search, $(this).attr("rel"));
                        return false;
                    });
                
                $("#search_content_overlay").val($("#search_content").val());
                $("#search_content_overlay").focus();
                
                
                $('html, body').animate({scrollTop:0}, 'slow');

                et_eC_Wrapper("t0VgVg","Suchergebnisse_en","germany.travel/en","","","","","","","","","11217","","",encodeURIComponent(search));
                
                return $content;
            }, "html");    
            
        } else {
            $("#overlayContainer").fadeIn();
        }
        
        return $content.animate({opacity: 1});
    },
        
    removeSearch: function() {
        $("#overlayContainer").fadeOut().remove();
        application.removeOverlay();
        application.ads.show();
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Suche '+'['+application.language+']','Schliessen');
    },    
    
    replaceSearch: function(url, search, offset) { 
    
        offset = offset || 0;
        $('html, body').animate({scrollTop:0}, 'slow');

        $.post(url, {search_content: search, start: offset}, function(data) {
            $content = $("<div></div>").attr("id", "tmpContainer").css('display', 'none').appendTo("body");
            $content.append(data);
                        
            $('#overlayContainer .layoutColumn100InnerContent').replaceWith($('#tmpContainer .layoutColumn100InnerContent'));
            $("#search_content").val($("#search_content_overlay").val());
            
            $content.remove();

            $("#searchPagination a").click(function() {
                    application.replaceSearch(url, search, $(this).attr("rel"));
                    return false;
                });
            
        }, "html");    
                    
        et_eC_Wrapper("t0VgVg","Suchergebnisse_en","germany.travel/en","","","","","","","","","11218","","",encodeURIComponent(search));
        
        if (typeof ET_Event !== "undefined") ET_Event.eventStart(etracker_category.level_1,'Suche '+'['+application.language+']','Weitersuchen');

    },
    
    
    createSitemap: function(options) {
    
		options = $.extend({
			iframe: true,
			sitemapLabel: "",
			onLoad: function() {
				$("#overlayHead").append(
					$("<a href='#'></a>")
						.addClass("linkBcs closeBcs")
						.html("<span>"+options.sitemapLabel+"</span>")
						.click(application.removeOverlayContent)
				);
			}
		}, options);
		
		return this.createOverlayContent(options);
    
    },
    
    
    createOverlayContent: function(options) {
    
		options = $.extend({
			url: "",
			html: "",
			fixed: false,
			iframe: false,
			onCreate: function() {},
			onLoad: function() {}
		}, options);
		
    
        if (options.url || options.html) {
        
            application.ads.hide();

            $("#overlayContent").remove();
            $overlay = application.createOverlay("light");
            
			$content = $("<div></div>").attr("id", "overlayContent").addClass("overlayContent").appendTo("body");
			
			if ($.isFunction(options.onCreate)) {
				options.onCreate($content, options);
			}
			
			if (options.iframe) {
				
				$content.load(application.url.iframe[application.language], options.urlParams, function(cb) {
				
					// attach event handler
					$(".closeOverlyContent,.closeOverlayContent", $content)
						.show()
						.bind(application.getEventType(), function() {
							application.removeOverlayContent();
						});
					
					$iframe = $("#iFrameOverlay").attr({src: options.url});
					
					if ($.isFunction(options.onLoad)) {
						options.onLoad($content, options);
					}
					
				});
			
			
			} else if (options.url != "") {
				
				$content.load(options.url, options.urlParams, function(cb) {
				
					// attach event handler
					$(".closeOverlyContent,.closeOverlayContent", $content)
						.show()
						.bind(application.getEventType(), function() {
							application.removeOverlayContent();
						});
					
					if ($.isFunction(options.urlCallback)) {
						$.each(options.urlCallback, cb);
					}
				});
			
			
			} else if (options.html != "") {
			
				$content.append(options.html);
				
				// attach event handler
				$(".closeOverlyContent,.closeOverlayContent", $content)
					.show()
					.bind(application.getEventType(), function() {
						application.removeOverlayContent();
					});
				
				if ($.isFunction(options.urlCallback)) {
					$.each(options.htmlCallback);
				}
			}
			
			if (options.fixed) {
				$content.addClass("fixed");
			} else {
				$content.removeClass("fixed");
			}
			$content.show();
            return $content;
        }
    },
        
    removeOverlayContent: function() {
        $("#overlayContent").remove();
        application.removeOverlay();
        application.ads.show();
    },    
    
    
    createPopupBubble: function(sender, content, position) {
        var $sender        = $(sender) || $("body");
        var position    = position || "pageCenterTop";
        var content        = content || "";
        var time        = (new Date()).getTime();
        var id            = "popupBubble_" + time;
        
//        $sender.css("z-index", 1101);
        $overlay    = application.createOverlay("popup");
        $overlay.addClass("light");
        
        $button        = $("<span></span>").addClass("buttonClose").text('close').click(function() { application.removePopupBubble(id); });
        $body        = $("<div></div>").addClass("popupBubbleBody").append(content).append($button);
        $content    = $("<div></div>")
                            .attr("id", id)
                            .attr("sender", $sender)
                            .addClass("popupBubble")
                            .append('<div class="popupBubbleTop"></div>')
                            .append($body)
                            .append('<div class="popupBubbleBottom"></div>')
                            .appendTo("body");
        
        if (position == "pageCenterTop") {
            $content
                .css("left", ($(".layoutColumnMain").position().left + 15) + "px")
                .css("top", ($(sender).position().top - $content.height() - 10) + "px");
        }
        return $content;
    },
    
    removePopupBubble: function(id) {
        $bubble    = $("#" + id);
        if ($bubble.length == 1) {
//            $bubble.sender.css("z-index", "");
            $bubble.fadeOut().remove();
        }
        application.removeOverlay();
    },
    
    
    ads: {
        showMoreInfo: function(el) {
            var $el = $(el);
            
            if ($el.parent().siblings('p.adMoreInfo').not(':visible')) {
                $el.parent().siblings('p.adMoreInfo').slideDown();
                $el.hide();
            }
            return false;
        },
        
        hide: function() {
            $(".dztAdsense").css({ visibility: "hidden" });
        },
        
        show: function() {
            $(".dztAdsense").css({ visibility: "visible" });
        }
    },
    
    
    dropdown: {
		
		closeAll: function() {
		
			var $c = $("div.dcDropdownContainer");
			
			$c.find("div.dcDropdown").hide();
			$c.find("div.dcDropdownInput").removeClass('dcDropdownInputOpen');
		}
    }
};

$(document).ready(function() {
    application.init();
});

// jquery image loading plugin (triggers load-event for images)
$.fn.imageLoad = function(fn){
    this.load(fn);
    this.each( function() {
        if ( $(this).get(0).complete && $(this).get(0).naturalWidth !== 0 ) {
            $(this).trigger('load');
        }
    });
};


// -- addthis configuration
var addthis_share = {};
var addthis_config = {
    services_exclude: "",
    services_compact: "email,facebook,blogger,google,favorites,digg,twitter,delicious,stumbleupon,myspace",
//    services_expanded: "",
    ui_click: true,
    ui_hover_direction: 1,
    ui_open_windows: true,
    ui_language: application.language,
    ui_offset_top: -4,
    ui_offset_left: -115,
//    ui_use_css: false,
//    ui_508_compliant: true,
    ui_delay: 5000,
    dummy: false
};



// render files for adserver
// http://www.germany.travel/media/js/jquery_ui_1/jquery_ui_datepicker_de.js
// http://www.germany.travel/media/js/jquery_ui_1/jquery_ui_datepicker_en.js
// http://www.germany.travel/media/js/widget_lufthansa.js
// http://www.germany.travel/media/layout/stylesheet/jquery_ui/jquery-ui-widget.css
// http://www.germany.travel/media/js/application_translation.js

