jQuery.fn.truncate = function(options) {

    var defaults = {
        length: 300,
        minTrail: 20,
        ellipsisText: " ..."
    };

    var options = jQuery.extend(defaults, options);

    return this.each(function() {
        obj = jQuery(this);

        var body = obj.html();
        if (body.length > options.length + options.minTrail) {
            var splitLocation = body.indexOf(' ', options.length);
            if (splitLocation != -1) {
                // truncate box
                var splitLocation = body.indexOf(' ', options.length);
                var str1 = body.substring(0, splitLocation);
                obj.html(str1 + '<span class="truncate_ellipsis">' + options.ellipsisText +
                    '</span>');
            }
        }
    });
};

/**
* Resize product boxes
*/
jQuery.fn.hResize = function(target) {
    var max;
    var elem;
    
    this.each(function() {
        max = 0;
        elem = null;
        jQuery(this).children().each(function() {
            elem = jQuery(this).find(target).first();
            if(elem && max < elem.height()) max=elem.height();
        });
        
        elem = null;
        jQuery(this).children().each(function() {
            elem = jQuery(this).find(target).first();
            if(elem) elem.css('height', max+'px');
        });
    });
    
    return true;
}
