﻿function resizeIFrames() {

    // Set specific variable to represent all iframe tags.
    var iFrames = document.getElementsByTagName('iframe');

    // Resize heights.
    function iResize() {
        // Iterate through all iframes in the page.
        for (var i = 0, j = iFrames.length; i < j; i++) {
            // Set inline style to equal the body height of the iframed content.
            if (iFrames[i] != null) {
                if (iFrames[i].className.indexOf('invisible') > -1) {
                    if (iFrames[i].contentWindow != null) {
                        if (iFrames[i].contentWindow.document.body != null) {
                            iFrames[i].style.height = (iFrames[i].contentWindow.document.body.offsetHeight + 32) + 'px';
                        }
                    }
                }
            }
        }
    }

    // Check if browser is Safari or Opera.
    if ($.browser.safari || $.browser.opera) {
        // Start timer when loaded.
        $('iframe.invisible').load(function() {
            setTimeout(iResize, 0);
        }
			);

        // Safari and Opera need a kick-start.
        for (var i = 0, j = iFrames.length; i < j; i++) {
            var iSource = iFrames[i].src;
            iFrames[i].src = '';
            iFrames[i].src = iSource;
        }
    }
    else {
        // For other good browsers.
        $('iframe.invisible').load(function() {
            // Set inline style to equal the body height of the iframed content.
            this.style.height = (this.contentWindow.document.body.offsetHeight + 32) + 'px';
        }
		);
    }

    iResize();
}

$(document).ready(function() {
    resizeIFrames();
}
);
