// @auth cvo
// @name truncateText.js
// @desc truncates product names
// @change
//   2011-10-20 cvo
//     file creation



function truncateText (element, length) {
	jQuery(element).each(function() {
		var str = jQuery(this).text();
		var limit = length;
		var bits, i;
		
		bits = str.split('');
		if (bits.length > limit) {
			for (i = bits.length - 1; i > -1; --i) {
			if (i > limit) {
			bits.length = i;
			}
			else if (' ' === bits[i]) {
			bits.length = i;
			break;
			}
			}
			bits.push('...');
		}
		var truncate = bits.join('');
		jQuery(this).text(truncate);
	});
}


jQuery(document).ready(function() {
	$ = jQuery.noConflict();
	
	if ($(".productDetails h4").length > 0) {
		$(".productDetails h4 a").each(function() {
			truncateText($(this), 60);
		});
	}
		
			
	$("p.title a").each(function() {
		truncateText($(this), 35);
	});
			
			
	$("div.com-amazon-webstore-MiniCart-2 .miniCart .dynamicMiniCart .product div.productDetails .title a").each(function() {
		truncateText($(this), 35);
	});
	
});

