function truncateText(string, max_length) {
  var truncated = false;
  var text = string.replace(/\s+/g, ' ');
  text = text.replace(/^ /, '');  // string had trailing whitespace.
  if (text.length > max_length) {
    var text = text.slice(0, max_length).replace(/[\s|\W]\w*$/, '');
    truncated = true;
  }
  // Ensure HTML entities are encoded
  // http://debuggable.com/posts/encode-html-entities-with-jquery:480f4dd6-13cc-4ce9-8071-4710cbdd56cb
  text = $('<div/>').text(text).html();
  if(truncated) { text += "&hellip;"; }
  return text;
}

var uid = Math.floor(Math.random()*9000)
var pc_tc = $(".do_pc_tc").parents("div.f_pc").removeClass().addClass("pc_tc").attr("id","pc_tc-"+uid);

$.elementReady("pc_tc-"+uid, function(){
	var $items = $(this).children("div.products").find("div.item").filter(":gt(4)").hide().end().find("a img").each(function(){
		$(this).attr({'width':'116', 'height':'115', 'src':$(this).attr('src').replace(/80\./g, "115.").replace(/\/small\//g, "/medium/")});
	}).end();
	$items.find("a.pc_ellipsis").removeClass("pc_ellipsis").addClass("pc_ellipsis_hover").each(function(){
		var txtString = $(this).text();
		var txtTrunc = truncateText(txtString, 35);
		$(this).attr("title",txtString).html("<span>"+txtString+"</span>"+txtTrunc)
	});
	$items.find("a.click-for-price").next("span").hide();
});