/* snippetClipper.js - function to trim the title of a 
 *     snippet to a length that will reside on a single 
 *     line. In the event that this has to be done, the 
 *     title of the anchor will be the full text.
 */

jQuery.fn.snippetClipper = function() {
	return jQuery(this).each(function(){
		if(jQuery("h4 a", jQuery(this) ).length > 0){
			jQuery("h4 a", jQuery(this) ).each(function(){
				$this = jQuery(this);
				if (($this).text().length > 90 ){
					$this.attr('title', $this.text() )
					 .truncate(90, {
					     chars: /./,
				         leave: false,
					     trail: [true, '...','']
					});
				}
			})
		}
		if(jQuery(".ez-main p.ez-desc", jQuery(this)).length > 0) {
			jQuery(".ez-main p.ez-desc", jQuery(this) ).each(function(){
				$this = jQuery(this);
				if (($this).text().length > 110 ){
					$this.attr('title', $this.text() )
					 .truncate(190, {
					     chars: /./,
				         leave: false,
					     trail: [true, '...','']
					});
				}
			})
		}
		
		if(jQuery(".ez-highlight p.highlight-text", jQuery(this)).length > 0) {
			jQuery(".ez-highlight p.highlight-text", jQuery(this) ).each(function(){
				$this = jQuery(this);
				if (($this).text().length > 190 ){
					$this.attr('title', $this.text())
   					     .truncateMe({
						 	max_length: 190
						 });
				}
			})
		}
		

	})
}
