﻿

/*
author: Rob Eberhardt, www.slingfive.com
desc: hooks into DNN's broken autoIframe call
*/
function autoIframe(frameId){
	try{  
		document.domain='cjfed.org';   // TODO: auto-detect root domain
		
		var f=document.getElementsByTagName('IFRAME')[0];
		window.onresize = function(){ f.onload() }; // hookup to resize too

		var fw=f.contentWindow, fd=fw.document, fb=fd.body;
		fb.style.backgroundColor='transparent'; 
		fb.style.color = '#fff';
		
		if(fw.frames.length==0){
			if(!f._origHeight){f._origHeight = f.height};
			f.height = '';
			f.height = fb.scrollHeight;  
		}else{ // subframes are tricky, so just use fixed height 
			f.height = f._origHeight;  
			window.scrollTo(0,500);
	/*
			for(var i=0; i<fw.frames.length; i++){ // subframes
				var sf=fw.frames[i], sb=sf.document.body;
				sf.onload = function(){ autoIframe(frameId); } // capture & refire for subframe loads
				
				//alert(sb.scrollHeight);			
				if(sb.scrollHeight > f.height){ f.height = sb.scrollHeight; }
				
				sf.allowTransparency = true;
				sb.style.backgroundColor = 'transparent'; 
			}
	*/
		}


	}catch(err){
		window.status = err.message;
//		alert(err.message);		
	}		
}



/*

// how about a recursive solution for nested subframes...?

function flatten(f){
	var fw=f.contentWindow, fd=fw.document, fb=fd.body;
	
	for(var f=0; f<=fw.frames.length; f++){ // recurse subframes
		var sf=fw.frames[f], sw=sf.contentWindow, sd=sw.document, sb=sd.body;

		flatten(sf);
		
		f.height = sb.scrollHeight;
		sb.style.backgroundColor='transparent';
	}
	
}

*/