var TextCropper = function(selectors, props) {

	this.letters = 30;
	this.selectors = {
		comment : '.comment',
		dots : '.dots_comment',
		full : '.full_comment',
		tooltip : '.tooltip'
	};
	this.hideLast = true;
	this.lastHolder = null;
	this.tooltipW = 0;

	for (var s in selectors) {
		this.selectors[s] = selectors[s];
	}
	for (var p in props) {
		this[p] = props[p];
	}

	this.init = function() {
		//alert('init');
		var cls = this;

		jQuery(this.selectors.comment).each(function(index, obj) {
			var comment = this.textContent || this.innerText || '';
			var spaceIndex = comment.indexOf(' ', cls.letters);
			if (spaceIndex != -1) {
				var holder = jQuery(this).parent();
				// crop comment
				jQuery(this).html(comment.slice(0, spaceIndex)).after('<span class="'+cls.selectors.dots.slice(cls.selectors.dots.lastIndexOf('.')+1)+'">'+(comment.slice(spaceIndex-1, spaceIndex) == '.' ? '..' : '...')+'</span>')
				// tooltip
				holder.find(cls.selectors.full).removeClass('hidden').bind('mouseover', function() {
					cls.showTooltip(this);
				}).bind('mouseout', function() {
					cls.hideTooltip(this);
				})
				holder.find(cls.selectors.tooltip).show().css('opacity', 0);
				if (cls.tooltipW) {
					holder.find(cls.selectors.tooltip).css('width', cls.tooltipW).css('margin-left', -Math.round(cls.tooltipW/2));
				}
				holder.find(cls.selectors.tooltip).html(comment);
			}
		});
	};

	this.showTooltip = function(link) {
		//alert('onShowClick holder='+holder);
		jQuery(link).find(this.selectors.tooltip).show().css('opacity', 0).stop().fadeTo(500, 1); /*.bind('mouseout', function() {
			jQuery(this).stop().fadeOut(500);
		}).bind('mouseover', function() {
			jQuery(this).stop().fadeIn(500);
		}); */
	};

	this.hideTooltip = function(link) {
		jQuery(link).find(this.selectors.tooltip).stop().fadeTo(500, 0, function() { jQuery(this).hide(); });
	};

	this.init();

};