jQuery.fn.tripShorten = function( maxHeight, settings ) {
	
	var $ = jQuery;
	this.each( function() {

		// if the element is too tall...
		if ( $(this).height() > maxHeight ) {
		
			// remove all but the first paragraph element
			$('p:not(:first-child)', this).remove();
			
			// then begin reducing the size of the remaining element
			var a = $('p',this).text().split(' ');
			var c = 0;
			while( $('p',this).height() > maxHeight ) {
				a.pop();
				$('p', this).text( a.join(' ')+'... ' );
			}
//			$('p',this).append( $('p ~ a.read-more',this).addClass('show'));
//			$('p ~ a.read-more',this).remove();
		}
	});
};

jQuery( function($) {
	/*$(window).bind('load resize', function() {
		$('.business-index .item-body').tripShorten( 60 );
	});*/
	
	$('div.business-index .one-item').add('div.business-index .paginator').wrapAll( $('<div />').addClass('all-items'));
	$('div.body > .column').wrapAll( $('<div />').addClass('all-columns'));
	if ( $('div.all-columns .column.right').height() > $('div.all-columns .column.main').height() ) {
		$('div.all-columns .column.main').height( $('div.all-columns .column.right').height() );
	}
	//$('div.business-index .all-items').prepend( $('<div />').addClass('waiting'));
	
    $('select.business-sort').change( function() {
        
        var f = $(this).parents('form');
        f.submit();
        return;
    });
    $('select.business-limit').change( function(event) {
        event.preventDefault();
        $('form#business-filter input#business-limit').val( $(this).val() ).parent('form').submit();
    });
	
    var $paginatorClick = function( event ) {
        event.preventDefault();
        
        $.get(
            $(this).attr('href') + '/sort:'+ $('select.business-sort').val()+'?'+Math.random(),
            {},
            function( html ) {
                $('div.business-index .all-items').empty().html( html ).find('.paginator a').click( $paginatorClick );
                location.href = '#business-top';
            },
            'html'
        );
    };
    
    //$('.business-index .paginator a').click( $paginatorClick );
	
});