function thickboxResize() { // if this works it will be a bloody miracle

    var boundHeight = 5000;
    var boundWidth = 5000;

    var viewportWidth = (self.innerWidth || (document.documentElement.clientWidth || (document.body.clientWidth || 0)))
    var viewportHeight = (self.innerHeight || (document.documentElement.clientHeight || (document.body.clientHeight || 0)))

    $('a.thickbox').each(function() {

        var text = $(this).attr("href");

        if (viewportHeight < boundHeight || viewportWidth < boundWidth) {
            text = text.replace(/height=[0-9]*/, 'height=' + Math.round(viewportHeight * .9));
            text = text.replace(/width=[0-9]*/, 'width=' + Math.round(viewportWidth * .9));
        }
        else {
            text = text.replace(/height=[0-9]*/, 'height=' + boundHeight);
            text = text.replace(/width=[0-9]*/, 'width=' + boundWidth);
        }

        $(this).attr("href", text);
    });
}

$(window).bind('load', thickboxResize);
$(window).bind('resize', thickboxResize);
