/**
 * Bildern welche als Klasse generate_caption habe eine Caption erstellen, welche dem alt-tag entspricht.
 * siehe ngi-wiki (https://intranet.studcom.ch/ngiwiki/index.php/Eigene_jQuery-Module)
 *
 * @copyright 2011 StudCom GmbH
 * @version 2011-05-31
 * @since 1.2
 */
 
  jQuery.fn.generateCaption = function(){
  
    var $ = jQuery;
    
    $('img.generate_caption', this).each(function(){
      var copy = $(this).clone();
      
      if(copy.attr('alt') == "")
        return;
      
      var div = $('<div></div>');
      div.attr("class", copy.attr("class"));
      div.addClass("GCaption_Container");
      div.attr("style", copy.attr("style")); 
      
      var p = $('<div></div>');
      p.attr("class", "GCaption_Text");
      
      p.append(document.createTextNode(copy.attr('alt')));
      
      div.append(copy).append(p);
      
      $(this).replaceWith(div);
      
      var w1 = p.outerWidth()-1;
      
      while(p.outerWidth()>copy.innerWidth() && w1 != p.outerWidth())
      {
        w1 = p.outerWidth();
        var str =  p.text();
        p.text(str.substring(0, str.length-3)+'..');
      }
      
      p.css("width", copy.innerWidth() - (p.outerWidth()-p.width()));
    });
 
 
    return this;
  };
