(function($){
  //jQuery plugin for language selector
  $.fn.langDropdown = function() {  
    return this.each(function() {
      var $this = $(this);
      
      $this.find('dt a').click(function() {
        $this.find('dd ul').toggle();
      });
            
      $this.find("dd ul li a").click(function() {
        var text = $(this).html();
        $this.find('dt a span').html(text);
        $this.find('dd ul').hide();
      });
    
      $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if ($clicked.parents().filter($this).size() === 0)
          $this.find('dd ul').hide();
      });
    
    });

  };
}(jQuery));

