(function($) {
    $(function () {
        // Resize the album review listing text to fit inside its cell.
		$('.albumReview').each(function() {
            var el = $(this);
            var artist = el.find('h2').css('display', 'inline');
            var title = el.find('h3').css('display', 'inline');    
            el.css('width', 1000);
            var idealArtist = Math.min(24, Math.max(parseInt(artist.css('font-size')) * (125 / artist.width()), 13));
            var idealTitle = Math.min(18, Math.max(parseInt(title.css('font-size')) * (125 / title.width()), 11));
            artist.css('font-size', idealArtist + 'px');
            title.css('font-size', idealTitle + 'px');
			if(artist.width() > 125) {
				artist.css('font-size', 13 + 'px');
				if(artist.text().length > 19) {
					artist.text(artist.text().substring(0, 19) + "...");
				}
			}
			if(title.width() > 125) {
				title.css('font-size', 11 + 'px');
				if(title.text().length > 22) {
					title.text(title.text().substring(0, 22) + "...");
				}
			}
            el.css('width', null);
            artist.css('display', 'block');
            title.css('display', 'block');
        });
		
		// Attempts to wrap lines; that never really happened.
		/*$('.albumReview').each(function() {
            var el = $(this);
            var artist = el.find('h2').css('display', 'inline');
            var title = el.find('h3').css('display', 'inline');    
            el.css('width', 1000);
            var idealArtist = Math.min(24, Math.max(parseInt(artist.css('font-size')) * (120 / artist.width()), 13));
            var idealTitle = Math.min(18, Math.max(parseInt(title.css('font-size')) * (120 / title.width()), 11));
            artist.css('font-size', idealArtist + 'px');
            title.css('font-size', idealTitle + 'px');
            el.css('width', null);
            artist.css('display', 'block');
            title.css('display', 'block');
            if(idealArtist < 16 && artist.height() + title.height() + parseInt(artist.css('line-height')) < 60){
                artist.css('white-space', 'normal');
                idealArtist = 18;
                artist.css('font-size', idealArtist + 'px');
                if(artist.text().length > 35){
                    artist.text(artist.text().substring(0,30) + "...");
                }
            } else if (idealArtist < 16) {
                idealArtist = 18;
                artist.css('font-size', idealArtist + 'px');
                if(artist.text().length > 19){
                    artist.text(artist.text().substring(0,15) + "...");
                }
            }
            if(idealTitle < 12 && artist.height() + title.height() + parseInt(title.css('line-height')) < 60){
                title.css('white-space', 'normal');
                idealTitle = 12;
                title.css('font-size', idealTitle + 'px');
                if(title.text().length > 43){
                    title.text(title.text().substring(0,40) + "...");
                }
            } else if (idealTitle < 12) {
                idealTitle = 12;
                title.css('font-size', idealTitle + 'px');
                if(title.text().length > 23){
                    title.text(title.text().substring(0,20) + "...");
                }
            }
        });*/
    });
})(jQuery);
