var debug_level = 0 ;

function prepareIFrames(inDocument, reload)
	{
		// Set specific variable to represent all iframe tags.
		// var iFrames = inDocument.getElementsByTagName('iframe');
		var iFrames = $(".autoHeight", inDocument);
		if (debug_level > 8) alert("prepareIFrames n Frames " + iFrames.length) ;
		if (debug_level > 8) alert("prepareIFrames $.browser.safari " + $.browser.safari) ;

		// Resize heights.
		function iResize()
		{
			if (debug_level > 8) alert("iResize") ;
			// Iterate through all iframes in the page.
			var hasChanged = false ;
			for (var i = 0, j = iFrames.length; i < j; i++)
			{
				// Set inline style to equal the body height of the iframed content.
				try {
					var heightOwner = (iFrames[i].style)? (iFrames[i].style):(iFrames[i]) ;
					
					var prevHeight = heightOwner.height ;
					if (debug_level > 1) alert("before heightOwner.height " + heightOwner.height) ;
					heightOwner.height = 0 ;
					
				//	iFrames[i].style.height = ((iFrames[i].contentWindow.document.body.scrollHeight || iFrames[i].contentWindow.document.body.offsetHeight) + 35) + 'px';
					if (iFrames[i].contentDocument) {
						doc = iFrames[i].contentDocument ;
						heightOwner.height = ((doc.body.scrollHeight || doc.body.offsetHeight) + 35) + 'px';
						if (debug_level > 8) {
							alert("doc.height " + doc.height) ;
							alert("doc.body.scrollHeight " + doc.body.scrollHeight) ;
							alert("doc.body.clientHeight " + doc.body.clientHeight) ;
							alert("doc.body.offsetHeight " + doc.body.offsetHeight) ;
						}
					}
					else 
						heightOwner.height = ((iFrames[i].Document.body.scrollHeight || iFrames[i].Document.body.offsetHeight) + 35) + 'px';
						
					hasChanged = hasChanged || (heightOwner.height != prevHeight) ;
						
					if (debug_level > 8) alert("heightOwner.height " + heightOwner.height) ;
					if (debug_level > 1) alert("after heightOwner.height " + heightOwner.height) ;
				}
				catch(err) {
					if (debug_level > 0) alert("Exception in iResize " + err) ;
				}
			}
			
			if (hasChanged)	{
			//	alert("frame has changed") ;
				setTimeout(iResize, 500); 
			}
		}

		// Check if browser is Safari or Opera.
		if ($.browser.safari || $.browser.opera || $.browser.mozilla || true)
		{
			if (debug_level > 8) alert("safari or opera") ;
			// Start timer when loaded.	$('iframe')
			iFrames.load(function()
				{
					if (debug_level > 8) alert("iFrames.load") ;
					setTimeout(iResize, 500);
				}
			);

			// Safari and Opera need a kick-start.
			if (reload) {
				for (var i = 0, j = iFrames.length; i < j; i++)
				{
					var iSource = iFrames[i].src;
					iFrames[i].src = '';
					iFrames[i].src = iSource;
				}
			}
		}
		else
		{
			if (debug_level > 8) alert("neither safari or opera or mozilla"  + iFrames.length) ;
			// For other good browsers.	$('iframe')
			try {
				iFrames.load(function()
					{
						if (debug_level > 8) alert("iFrames.load") ;
						// Set inline style to equal the body height of the iframed content.
						try {
							if (this.contentDocument)
								this.style.height = ((this.contentWindow.document.body.scrollHeight || this.contentWindow.document.body.offsetHeight) + 35) + 'px';
							else
								this.style.height = ((this.Document.body.scrollHeight || this.Document.body.offsetHeight) + 35) + 'px';
						}
						catch(err) {
							if (debug_level > 8) alert("Exception in iFrames.load " + err) ;
						}
					}
				);
			}
			catch(err) {
				if (debug_level > 8) alert("Exception in load " + err) ;
			}
		}
	}
