/**************************************************
 The relative path to the document fragment loaded 
 into the iframe from the current document
 
 HoweverI would recommend using an absolute path in a 
 production environment so no page gets left behind
 **************************************************/
var SI_url = 'js/si_.html';


/**************************************************
 SI_clearAbsolutes() v1.5
 
 Function called initially in source order and 
 called each time the iframe is resized (so place
 immediately before the closing body tag--this 
 actually improves rendering since technically 
 it runs before the browser's initial page draw) 
 **************************************************/
function SI_clearAbsolutes() {
	var d=document;
	if (!d.getElementsByTagName) return;
	var divs = d.getElementsByTagName('div');
	
	// Reset all divs heights
	for (i=0; i<divs.length; i++) { divs[i].style.height='auto'; }
	
	// Now loop through them all in reverse
	for (i=divs.length-1;i>=0;i--) {
		var div = divs[i];
		var containsDivs = false;
		for (j=0; j<div.childNodes.length; j++) {
			if (div.childNodes[j].nodeName=='DIV') {
				containsDivs = true;
				break;
				}
			}
		if (containsDivs) {
			//w('#'+div.id+'.'+div.className+' at depth: '+SI_getNestingDepth(div)+', source order: '+i);
			var oh = []; 
			for (j=0;j<div.childNodes.length;j++) { c = div.childNodes[j]; 
				if (c.nodeName=='DIV') { 
					// Add this height to our array of rendered heights
					oh[oh.length] = parseInt(c.offsetHeight); 
					}
				}
				
			// Determine the max height
			var h = 0; for (k=0;k<oh.length;k++) { h = (oh[k]>h)?oh[k]:h;}
			// Determine sum of contained elements heights
			var sh = 0; for (l=0;l<oh.length;l++) { sh +=oh[l]; }
			
			/* getComputedStyle is not supported in Safari 1.2-older so we need to work around detecting the positioning of each element
			 * (
			 * div.offsetHeight==0	: if the containing element only has absolutely positioned elments inside of it it will collapse and have no offsetHeight
			 * &&
			 * h!=0					: contains at least one element (in this case `div`) with an offsetHeight
			 * )					: combined expression should detect only an element whose children are all absolutely positioned
			 * ||
			 * (
			 * div.offsetHeight<sh	: if the offset height is less than the sum of the contained elements height then something has been taken out of the flow of content by positioning
			 * )					: this expression should detect when contained elements are of mixed positioning ie. one child absolute and the other static or relative
			 */
			if ((div.offsetHeight==0 && h!=0) || div.offsetHeight<=sh) {
				// Extend shorter elements (Breaks redraw with resizable text)
				for (m=0;m<div.childNodes.length;m++) { c = div.childNodes[m]; if (c.nodeName=='DIV') { c.style.height = h+'px'; }}
				// Set the height of the containing element
				div.style.height = h+'px';
				
				}
			}
		}
	} SI_clearAbsolutes();

/**************************************************
 This code block cannot go in a function without
 breaking the back button in Mozilla browsers
 **************************************************/
var io;
var failed = false;
var d  = document;
if (d.createElement) {
	var n = d.createElement('iframe');
	n.setAttribute('id','SI_frame');
	
	// For some reason the iframe needs to be in the viewport for 
	// the onresize event to fire in Safari so the position is set
	// to fixed
	n.style.position	= (d.all)?'absolute':'fixed';
	n.style.top		= '0px';
	
	// Setting the left to a negative number results in Safari
	// ignoring or missing the iframe onresize event
	n.style.visibility	= 'hidden';
	
	// Smaller than 10em and Safari doesn't registe...you get the idea.
	n.style.width		= '10em';
	n.style.height		= '10em';
		
	var i = d.body.appendChild(n);
	
	// Handle IE 5 Mac and b0rk3n IE 5.0 PC
	try { if (d.frames) { i = d.frames['SI_frame']; } }
	catch(exception) { failed=true; }
	
	if (i.contentDocument) {
		// alert('w3c');
		io = i.contentDocument;
		}
	else if (i.contentWindow) {
		// alert('ie5.5-6p');
		io = i.contentWindow.document;
		}
	else if (i.document && !failed) {
		// alert('ie5m');
		io = i.document;
		}
	else {
		// alert('Houston we have an IE 5.0 PC.');
		i.onresize = SI_clearAbsolutes;
		}
	if (!failed) io.location.replace(SI_url);
	}