/*
 * Word Breaker - jQuery plugin
 *
 * Copyright (c) 2009 bushimichi bushimichi@gmail.com
 *
 * Dual licensed under
 * the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.gnu.org/licenses/gpl.html) licenses.
 *
 * @update 2009/12/10 version 0.2
 *
 */
  jQuery(function($){
 
    $.wb = {
      
      version: 0.2
         
     ,sep: String.fromCharCode(8203)
      
     ,remake: function(elm){
       var h = elm.contents();
               elm.html('');
       $(h).each(function(){
         if(this.nodeType == 3){
           elm.append($.trim(this.textContent.split('').join($.wb.sep)));
         }else if(this.textContent == ''){
           elm.append(this);
         }else{
           elm.append($.wb.remake($(this)));
         }
       });
       return elm;
     }
    }
    
    $.fn.wb = function(){
      if(/msie/i.test(navigator.userAgent)){
        $(this).css('word-break', 'break-all');
      }else{
        $.wb.sep =  (/firefox\/2/i.test(navigator.userAgent)) ? '<wbr />' : String.fromCharCode(8203);
        $(this).each(function(){ $.wb.remake($(this));});
      }
      return $(this);
    }
  });
