//extend prototypes
String.prototype.truncate = function( chars, loc, ellip ){
    var s = this, loc = loc || 'start', ellip = ellip || 8230;
    ellip = isNaN(ellip)? ellip: String.fromCharCode(ellip);
   
    if( s.length > chars){
        if( loc == 'start' ){
            s = s.slice(0,chars - ellip.length) + ellip;
        } else if( loc == 'middle' ){
            s = s.slice(0,Math.floor(chars/2)) + ellip + s.slice(s.length - Math.ceil(chars/2),s.length);
        } else {
            s = ellip+s.slice(s.length-chars+ellip.length,s.length);
        }
    }
    return s.toString();
}