$(document).ready(function(){

        if ($("#map-austria").length)
        {
             
        }
/*
       $("#map-austria > li > a").click(function(e)
       {
           e.preventDefault();
           var path = "";
           var link = $(this).attr("href");

                
                var arrLink = link.split("/");
                var countryCaption = "";
                if (arrLink[arrLink.length-1] != "")
                {
                    countryCaption = arrLink[arrLink.length-1];
                }
                else if(arrLink[arrLink.length-2] != "")
                {
                    countryCaption = arrLink[arrLink.length-2];
                }
                window.location.href = window.location.href.split("#")[0] + "#" + countryCaption;

               $(".dealerList").fadeOut("fast", function() {
                    
                    $.ajax({
                        url: link,
                        global: false,
                        type: "POST",
                        data: ({
                            request : "ajax"
                            }),
                        dataType: "html",
                        async:false,
                        success: function(data){
                            
                            $(".dealerList").html(data);
                            $(".dealerList").slideDown("");

                        }
                   });
        });
        
   });
*/

//   console.log("Here");
       if($("#mainMenu > ul > li.active > ul.menuLevel_1").length)
           {
            $("#menu_wrapper_left").height(53);
           }
/*
   if ((".newsListItem").length)
   {
        var path = window.location.href.split("#");
        if (path[1])
        {
            var link = path[0];
            $(".newsContainer").hide(0, function() {
               $.ajax({
                   url: link,
                   global:false,
                   type:"POST",
                   data: ({
                       request: "ajax",
                       article: path[1]
                   }),
                   dataType:"html",
                   async:false,
                   success: function(data) {
                       $(".newsContainer").html(data);
                       $(".newsContainer").fadeIn();
                   }
               });

        });
        }
   }
 
   $(".newsListItem a").click(function(e) {
        window.location.href = window.location.href.split("#")[0] + "#" + $(this).attr("title");
        e.preventDefault();
        var link = $(this).attr("href");
        $(".newsContainer").fadeOut("fast", function() {

           $.ajax({
               url: link,
               global:false,
               type:"POST",
               data: ({
                   request: "ajax"
               }),
               dataType:"html",
               async:false,
               success: function(data) {
                   $(".newsContainer").html(data);
                   $(".newsContainer").fadeIn();
               }
           });

        });
   });
   */
  /*
   if (window.location.href.split("#")[1])
   {

       $(".contentPart h2").click(function(){

            var isVisible=false;
            $(this).parent().children(":not(h2)").each(function(x){
               $(this).slideToggle(0, function() {

                    $(this).css("cursor", "pointer");
                    if ($(this).is(":visible"))
                    {
                        isVisible=true;
                    }
                    else
                    {
                        isVisible=false;
                    }
               });

                
            });
            if (isVisible)
            {
                $(this).removeClass("collapsed");
                if($(this).parent().parent().next().attr("class") == "contentPart ImageBlock") {
                   $(this).parent().parent().next().slideDown();
                }
            }
            else
            {
                $(this).addClass("collapsed");
                if($(this).parent().parent().next().attr("class") == "contentPart ImageBlock") {
                   $(this).parent().parent().next().slideUp();
                }
            }
       });

       var gotoAbsatz = window.location.hash.split("#")[1];
       $(".contentPart h2").each(function (e) {
           $(this).addClass("clickable");
           $(this).addClass("collapsed");
           $(this).parent().children(":not(h2)").each(function(en){
               $(this).hide(0);
               if($(this).parent().parent().next().attr("class") == "contentPart ImageBlock") {
                   $(this).parent().parent().next().hide(0);
               }
           });

            if ($(this).html().toLowerCase() == gotoAbsatz.toLowerCase())
            {
                $(this).removeClass("collapsed");
                $(this).parent().children(":not(h2)").each(function(x){
                    $(this).slideDown();
                });
                if($(this).parent().parent().next().attr("class") == "contentPart ImageBlock") {
                   $(this).parent().parent().next().slideDown();
                }

                //console.log();
            }
       });
  }*/
    $(".footerContainer > a").hover(function() {

        $("html,body").animate({ scrollTop: $("html").attr("scrollHeight") }, 500);

        var margin = parseInt($(this).css("margin-left").replace("px", ""));
        if(!margin) {
            margin = 0;
        }
        var left = $(this).position().left + margin + ($(this).width() - 13) / 2;
        //alert(left + "__" + $(this).position().left);
        $(".footerContainer img.arrow").css("left", "+" + parseInt(left) + "px");
        $(".footerContainer img.arrow").show();        
        $(this).find("span.modelCaption").fadeIn(150)();
    }, function() { $(this).find("span.modelCaption").hide(); });

    $(".footerContainer").mouseleave(function() {
        $(".footerContainer img.arrow").hide();
        $(this).find("span.modelCaption").hide();
    });

    $(".DealerImageBlock a[rel=fancybox]").fancybox({type: 'image', titleShow: false});

    $(".imageGallery a[rel=fancybox]").click( function(e){
        if($("#galleryImage").size()) {
            $("#galleryImage a").attr("href", $(this).attr("href") + "&download=1&name=");
            $("#galleryImage img").attr("src", $(this).attr("href"));
            $("#galleryImage img").attr("alt", $("img", this).attr("title"));
			$("#galleryImage img").attr("title", $("img", this).attr("title"));
            $("#galleryImage p").html($("img", this).attr("title"));
        }
        e.preventDefault();        
    });

    $(".contentPart.ImageBlock a[rel=fancybox]").fancybox({type: 'image', titleShow: false});
});


var hash = false;
checkHash();

function checkHash(){    
    if(window.location.hash != hash) {
        hash = window.location.hash;
        processHash(hash);
    } t=setTimeout("checkHash()",1000);
}

function processHash(hash){
     /*
     var gotoAbsatz = window.location.hash.split("#")[1];
       $(".contentPart h2").each(function (e) {
           $(this).addClass("clickable");
           $(this).addClass("collapsed");
           $(this).parent().children(":not(h2)").each(function(en){
               $(this).hide(0);
               if($(this).parent().parent().next().attr("class") == "contentPart ImageBlock") {
                   $(this).parent().parent().next().hide(0);
               }
           });


            if ($(this).html() == gotoAbsatz)
            {
                $(this).removeClass("collapsed");
                $(this).parent().children(":not(h2)").each(function(x){
                    $(this).slideDown();
                });
                if($(this).parent().parent().next().attr("class") == "contentPart ImageBlock") {
                   $(this).parent().parent().next().slideDown();
                }
                //console.log();
            }
       });
       */
}


var disableNext = false;

function nextHeaderImage()
{

        if ($(".headerContainer").find("img").length > 1)
        {

            var visibleImage = $(".headerContainer").find("img.active");
            var nextImage = visibleImage.next("img");
            if (nextImage.length)
            {
                
                visibleImage.removeClass("active");
                nextImage.addClass("active");
                nextImage.fadeIn();
                visibleImage.fadeOut()
                
            }
            else
            {
                visibleImage.removeClass("active");
                nextImage = $(".headerContainer").find("img:first");
                nextImage.addClass("active");
                nextImage.fadeIn();
                visibleImage.fadeOut()
                
            }            
        }        
}

function gotoPage(i)
{

    i=i-1;

    $(".newsListItem").each(function(key) {


        if (key < (i*5))
        {
            $(this).hide();
        }
        else if (key < ((i+1)*5))
        {
            $(this).show();
        }
        else
        {
            $(this).hide();
        }
     
    });
}

function toggleLogin()
{
    if ($("#loginFailedBox").size)
    {
        $("#loginFailedBox").fadeOut("slow");
    }

    if ($(".loginForm").css("display") == "none")
    {
        if ($('.searchInfo').is(':visible')) {
            $('.searchInfo').fadeOut("slow");
        }
        $(".loginForm").fadeIn("slow");
        loginFormOpen = true;
        $("#username").select();
        $("#username").focus();
    }
    else
    {
        loginFormOpen = false;
        $(".loginForm").fadeOut("slow");
        $("#linkLogin").focus();
    }
}
function toggleLoginInfo()
{
    if ($("#loginFailedBox").size)
    {
        $("#loginFailedBox").fadeOut("slow");
    }

    if ($(".loginFormInfo").css("display") == "none")
    {
        $(".loginFormInfo").fadeIn("slow");
    }
    else
    {
        $(".loginFormInfo").fadeOut("slow");
        $("#username").select();
        $("#username").focus();
    }
}

function showMedia()
{
    var Fenster1 = window.open('Intern/?m=m', '_blank', 'width=990, height=680, left=20, top=20, scrollbars=no, resizable=yes');
    //Fenster1.$("#containerMediaBottom").hide();
    
    //getElementByID("").height("20");
    Fenster1.focus();
    //Fenster1.window.resize();
}

