jQuery(document).ready(function(){
  set();
});

function set (){

 jQuery(".languages").hide();

jQuery(".arrow").click(function(){
   
    var options = jQuery(this).parent().find(".languages");
    
    if(options.css("display") == "none"){
      options.show();
      setTimeout(function(){
        jQuery("body").click(function(event){
          options.hide();
          
          jQuery(this).unbind(event);
        });
      },1);
    }
  
  });
  
  var _path = window.location.pathname;  
  //alert(_path);     
                           
   if ((_path == "/")||(_path == "/indexb.html")||(_path == "/index.html")) {
      var length =jQuery(".languages").find(".en").find("a").length;
    
      jQuery(".languages").find(".en").find("a").attr("href", "/index_e.html");
      jQuery(".languages").find(".de").find("a").attr("href", window.location.pathname);
      jQuery(".lang_de").find("a").attr("href", window.location.pathname);
      
     
   } else if ((_path == "/index_e.html")||(_path == "/indexb_e.html")) {
      //alert(_path);
      _path = "/index.html";  
      jQuery(".languages").find(".de").find("a").attr("href", _path);
      jQuery(".languages").find(".en").find("a").attr("href", window.location.pathname);
      jQuery(".lang_en").find("a").attr("href", window.location.pathname);
   }   
  else {
   var _lang = _path.substr(5,1);      
   var _lang2 = _path.slice(0,6);   
   var _length = _path.length;   
   var _lang3 = _path.slice(6,_length);
   
   if (_lang == "e")  { 
    _path = _lang2.replace(/e/g, "d") + _lang3;  
     var _href = jQuery(".languages").find(".de").find("a").attr("href", _path);
     var _href2 = jQuery(".languages").find(".en").find("a").attr("href", window.location.pathname);
     var _href3 = jQuery(".lang_en").find("a").attr("href", window.location.pathname);
    
   }else {
    _path = _lang2.replace(/d/g, "e") + _lang3; 
     var _href = jQuery(".languages").find(".en").find("a").attr("href", _path);
     var _href2 = jQuery(".languages").find(".de").find("a").attr("href", window.location.pathname);
     var _href3 = jQuery(".lang_de").find("a").attr("href", window.location.pathname);
   }
  } 
    
 jQuery(".languages").find(".de").click(function(){ 
      var link = jQuery(".languages").find(".de a")
     jQuery(this).parent().parent().find(".lang_en a").replaceWith(link);
  
 });
 
 jQuery(".languages").find(".en").click(function(){ 
      var link = jQuery(".languages").find(".en a")
     jQuery(this).parent().parent().find(".lang_en a").replaceWith(link);
  
 }); 
  
  
   
 }; 
