function moduleNavigationInit() {
  $("#module_navigation ul a[href='']").click(function(e) {
    if($(this).next().tagName() && $(this).next().tagName() == "ul") {
      if($(this).next().css("display") == "block") {
        $(this).next().css("display","none");
      }else {
        $("#module_navigation ul ul").not($(this).parent().parent()).css("display","none");
        $(this).next().css("display","block");
      }
    }
    redraw("module_navigation");
    return false;
  });

  $("#module_navigation .control").click(function() {
    if(moduleNavigationOpen) {
      moduleNavigationOpen = false;
      var aniTop = 0 - ($("#module_navigation").height() - 117);
      $("#module_navigation").animate({top: aniTop},"fast");
      $("#module_navigation .control div").removeClass().addClass("down");
    }else {
      moduleNavigationOpen = true;
      $("#module_navigation").animate({top: "94px"},"fast");
      $("#module_navigation .control div").removeClass().addClass("up");
    }
  });

  $("#module_navigation .control").hover(
    function () {
      if(moduleNavigationOpen) {
        $("#module_navigation .control div").removeClass().addClass("upHigh");
      }else {
        $("#module_navigation .control div").removeClass().addClass("downHigh");
      }
    },
    function () {
      if(moduleNavigationOpen) {
        $("#module_navigation .control div").removeClass().addClass("up");
      }else {
        $("#module_navigation .control div").removeClass().addClass("down");
      }
    }
  );
}

function startAutoFoldMainNavi(){

  $(document).bind("mousemove", function(mouseEvent){
    if(($("#mainNavigationContainer").css("top").replace("px", "") == -67) && (mouseEvent.pageY <= 67)){
      if(!mainNaviIsAnimating && !moduleNavigationOpen && !mainNavigationOpen){
        mainNaviIsAnimating = true;
        $("#mainNavigationContainer").stop().animate({top: "0px"}, function(){
          mainNaviIsAnimating = false;
        });
        $("#idModule").stop().animate({top: "-2px"});
      }
    }

    if(($("#mainNavigationContainer").css("top").replace("px", "") == 0) && (mouseEvent.pageY >= 100)){
      if(!mainNaviIsAnimating && !moduleNavigationOpen && !mainNavigationOpen){
        mainNaviIsAnimating = true;
        $("#mainNavigationContainer").stop().animate({top: "-67px"}, function(){
          mainNaviIsAnimating = false;
        });
        $("#idModule").stop().animate({top: "65px"});
      }
    }
  });
}


function mainNavigationHide(){
  $("#mainNavigationContainer").animate({top: "-67px"});
  $("#idModule").stop().animate({top: "65px"});
}

function mainNavigationShow(){  
  $("#mainNavigationContainer").animate({top: "0px"});
  $("#idModule").stop().animate({top: "-2px"});
}



function getWcmsPrefix(){
  var prefix = "";
  if (self.location.href.indexOf('/bmwdealer_edit/') != -1) {
    prefix = "/bmwdealer_edit";
  } else if (self.location.href.indexOf('/bmwdealer_qa/') != -1) {
    prefix = "/bmwdealer_qa";
  } else if (self.location.href.indexOf('/bmwdealer_prod/') != -1) {
    prefix = "/bmwdealer_prod";
  }
  return prefix;
}



var ajaxImportUrl = getWcmsPrefix() + "/_common/narrowband/js/navigation_seo.js";
$.ajax({
	url: ajaxImportUrl,
	dataType: "script",
	async: false,
	success: function(js){if(jQuery.browser.safari){eval(js);}}
});


$(document).ready(function() {

  $(".sales_navigation_layer").each(function() {
    var counter = 0;
    $(this).find("a").each(function() {
      counter++;
    });
    if(counter == 0) {
      $("#" + $(this).attr("id").replace("layer","button")).hide();
    }
  });
// delete headline for empty related links
  $("#relatedLinks").each(function() {
    var counter = 0;
    $(this).find("a").each(function() {
      counter++;
    });
    if(counter == 0) {
      $(this).hide();
    }
  });
});

if (detectedBandwidth == "vhigh") {
  highbandUser = false;
}




