// js port of the php truncate function from www.chirp.com.au
function jsTruncate(thestring, limit) {
	// return with no change if string is shorter than limit
	if(thestring.length <= limit) return thestring;

	// find a space between limit and the end of the string
	if(false !== (breakpoint = strpos(thestring, ' ', limit))) {
		if(breakpoint < thestring.length - 1) {
			thestring = thestring.substr(0, breakpoint) + ' ';
		}
	}

return thestring;
}

// from phpjs.org
function strpos (haystack, needle, offset) {
	var i = (haystack+'').indexOf(needle, (offset || 0));
	return i === -1 ? false : i;
}
