/*  #####################################################
**  Domain:    www.inn-salzach.com
**  Datei:     main.js
**  Funktion:  grundlegender JavaScript Code für alle Seiten

**  Erstellt:  19.05.2009

**  Autor:     Axel Güldner/Michael Degener
**  copyright: infomax websolutions GmbH
##################################################### */

function hideActiveOne(){
    $(document).unbind('mousedown', hideActiveOne);
    $("#topnavi").children(".first").children(".active").removeClass("active").fadeOut("fast");
}
function hideActiveTwo(){
    $("#topnavi").children(".first").children(".second").children(".second").children(".active").animate({paddingTop: "0px", paddingBottom: "0px"}).removeClass("active").slideUp("slow");
}

$(document).ready(function(){

    //Animation der Topnavigation
    //Aufklappen der zweiten Ebene
    var navHide1 = "";
    var animFlag1 = false;
    $("#topnavi").children(".first").bind("mouseenter",function(){
        window.clearTimeout(navHide1);
        if(animFlag1 == false && $(this).children(".second").size() > 0){
            animFlag1 = true;
            $(this).parent().children(".first").children(".second").removeClass("active");
            $(this).children(".second").addClass("active").fadeIn("fast", function(){
                animFlag1 = false;
            });
            $(this).parent().children(".first").children(".second:not(.active)").fadeOut("fast");
        }
        $(document).bind('mousedown', hideActiveOne);
    });
    $("#topnavi").children(".first").bind("mouseleave",function(){
        navHide1 = window.setTimeout("hideActiveOne()", 2000);
    });

    //Animation der Topnavigation
    //Aufklappen der dritten Ebene
    var navHide2 = "";
    var animFlag2 = false;
    $("#topnavi").children(".first").children(".second").children(".second").bind("mouseenter",function(){
        window.clearTimeout(navHide2);
        if(animFlag2 == false && $(this).children(".third").size() > 0){
            animFlag2 = true;
            $(this).parent().children(".second").children(".third").removeClass("active");
            $(this).children(".third").animate({paddingTop: "10px", paddingBottom: "10px"}).addClass("active").slideDown(1000, function(){
                animFlag2 = false;
            });
            $(this).parent().children(".second").children(".third:not(.active)").slideUp(1000).animate({paddingTop: "0px", paddingBottom: "0px"});
        }
    });
    $("#topnavi").children(".first").children(".second").children(".second").bind("mouseleave",function(){
        navHide2 = window.setTimeout("hideActiveTwo()", 1000);
    });



	//waechselt flagge in select-box
	$('#meta option.de').click(function () {
      						if (
								$("#meta select").hasClass("gb")) {
        						$("#meta select").removeClass("gb");
								$("#meta select").addClass("de");
      						} if (
								$("#meta select").hasClass("it")) {
        						$("#meta select").removeClass("it");
								$("#meta select").addClass("de");
      						}
    						});
	$('#meta option.gb').click(function () {
      						if (
								$("#meta select").hasClass("de")) {
        						$("#meta select").removeClass("de");
								$("#meta select").addClass("gb");
      						} if (
								$("#meta select").hasClass("it")) {
        						$("#meta select").removeClass("it");
								$("#meta select").addClass("gb");
      						}
    						});
	$('#meta option.it').click(function () {
      						if (
								$("#meta select").hasClass("de")) {
        						$("#meta select").removeClass("de");
								$("#meta select").addClass("it");
      						} if (
								$("#meta select").hasClass("gb")) {
        						$("#meta select").removeClass("gb");
								$("#meta select").addClass("it");
      						}
    						});

    //datePicker
	Date.format = 'dd.mm.yyyy';
	if(jQuery.isFunction($.fn.datePicker)) $('.date-pick').datePicker({clickInput:true}).val(new Date().asString()).trigger('change');    
    $(".date-pick").dpSetStartDate(currentCalenderDate[0]);    
    $(".date-pick").dpSetSelected(currentCalenderDate[1]);
    

    //Hubermaps
    //Animation Karte öffnen schließen
    $("*[rel=mapOpener]").click(function(){
        if($("#overlayMap").hasClass("startup")){
            $("#overlayMap").removeClass("startup");
            $("#overlayMap").css({top:"0px",left:"0px",position:"absolute",display:"none",width:"980px",height:"440px"});
        }
        $("#overlayMap").animate({height:"toggle", opacity:"toggle"});
        $("#keyvisualMaps .spaceHelper").animate({height:"toggle"});
    });
    $(document).keyup(function(event){
      if (event.keyCode == 27 && $("#overlayMap").is(":visible") && $("#overlayMap").is(":not(:animated)")) {
          $("#overlayMap").animate({height:"toggle", opacity:"toggle"});
          $("#keyvisualMaps .spaceHelper").animate({height:"toggle"});
      }
    });

    //Animation Legende
    $("#overlayMap .legende .main li").click(function(){
        var changeID = $(this).children("a").attr("rel");
        $(this).toggleClass("active");$(this).addClass("activeHelper");
        $(this).parent().children("li.active:not(.activeHelper)").removeClass("active");
        $(this).removeClass("activeHelper");
        $(this).parent().parent().children("ul.sub:not(."+changeID+")").fadeOut("slow");
        $(this).parent().parent().children("ul."+changeID).animate({height:"toggle", opacity:"toggle"},"slow");
    });

    $("#overlayMap .legende .sub li").click(function(){    	
    	$(this).toggleClass("active");
    });
		
    //Aktualisieren der Karte
	$("#overlayMap .legende li").click(function(){    	
    		    	
    	cmsProfiling = $(this).attr("id").substr(6);	//Profiling für CMS Suche befindet sich in ID des <li>    	
    	ecCategories = new Array();						//Profiling für eContentMaps Kategorien befindet sich in CLASS der Child <span>
    	ecProfiling = new Array();    					//Profiling für eContentMaps POIs befindet sich in ID der Child <span>
		$(this).find("span").each(function(){
			ecCategories.push($(this).attr("class"));
			ecProfiling.push($(this).attr("id").substr(6));
		});
    	        
		//Suchen nach POIs im CMS
		if($(this).hasClass("map")){			
			if($(this).hasClass("active"))functionMethod = "set";
			else functionMethod = "unset";			
			UpdateSearch(cmsProfiling, functionMethod);
		}
		//Suchen nach POIs per eContentMaps
		if($(this).hasClass("ecPOI")){
			//Es werden alle Kinderspans durchgegangen und einzeln behandelt
			if($(this).hasClass("active")) for(var counter in ecCategories){
				//Normale POIs werden per PinLoader auf den ShapeLayer gebracht (Davon können beliebig viele kombiniert werden)
				if(ecCategories[counter] == "POI"){
					ecMap.EnablePOICategory(ecProfiling[counter]);
					ecPinLoader_mapLarge.SetEnabled(eContent.PinType.POI, true);
				}					
				//Die übrigen POI-Klassen werden per GEO-Feed geladen. Es kann immer nur ein Feed jeder Klasse geladen werden (es ist also zB nicht möglich mehrere verschiedene Gastrobetriebe darzustellen, entweder nur einen oder alle)
				else if(ecCategories[counter] == "Gastro") ecMap.LoadGastros(ecProfiling[counter],"");
				else if(ecCategories[counter] == "Hotels") ecMap.LoadHotels(currentCalenderDate[0], currentCalenderDate[1], ecProfiling[counter],"");				
				else if(ecCategories[counter] == "Events") ecMap.LoadEvents(currentCalenderDate[2], currentCalenderDate[1], ecProfiling[counter],"");
				else if(ecCategories[counter] == "Touren") ecMap.LoadTouren(ecProfiling[counter],"");
			}else for(var counter in ecCategories){
				if(ecCategories[counter] == "POI"){
					ecMap.DisablePOICategory(ecProfiling[counter]);
					ecPinLoader_mapLarge.SetEnabled(eContent.PinType.POI, true);
				}
				else if(ecCategories[counter] == "Gastro") ecPinLoader_mapLarge.SetEnabled(eContent.PinType.Gastro, false);
				else if(ecCategories[counter] == "Hotels") ecPinLoader_mapLarge.SetEnabled(eContent.PinType.Hotel, false);
				else if(ecCategories[counter] == "Events") ecPinLoader_mapLarge.SetEnabled(eContent.PinType.Event, false);
				else if(ecCategories[counter] == "Touren") ecPinLoader_mapLarge.SetEnabled(eContent.PinType.Tour, false);							
			}
			
		}
		
		//Voneinander abhängige Navpunkte der Karte werden hier geprüft
		if($(this).hasClass("dependend")){			
			dependendClass = $(this).children("a").attr("class");
			$(this).children("a").removeClass(dependendClass);
			$("#overlayMap .legende").find("a."+dependendClass).parent().removeClass("active");
			$(this).children("a").addClass(dependendClass);			
		}
    });

    //clear standard form values
    var activeInputValue = "";
    $("body").find("input:not(.dp-applied):not([name=searchType]):not(.ignoreHoverBlur)").each(function(){
    	$(this).focus(function(){
    		activeInputValue = $(this).val();
    		$(this).val("");
    	});
    	$(this).blur(function(){
    		if($(this).val() == "")$(this).val(activeInputValue);
    		activeInputValue = "";
    	});
	});
    $("body").find("textarea").each(function(){
    	$(this).focus(function(){
    		activeInputValue = $(this).val();
    		$(this).val("");
    	});
    	$(this).blur(function(){
    		if($(this).val() == "")$(this).val(activeInputValue);
    		activeInputValue = "";
    	});
    });

});


$(window).load(function(){

});
