/*******************************************************************************************************
 * iFrameShim.js
 * Author: Paul Chilton
 * Based on shadower.js, uses Prototype library 1.5.0 or greater
 * look at ui_effects.js for usage (does a browser check, then runs shim if required)
 *******************************************************************************************************/
var iFrameShim =
{
	shim: function(element)
	{
		Prototype.Browser.IE7 = Prototype.Browser.IE && (typeof document.body.style.maxHeight != "undefined"); 	
		// do not bother unless we are IE6
		if (! Prototype.Browser.IE || Prototype.Browser.IE7) return;
		
		element = $(element);
		var tiframe = $('tiframe');
		
		// if we aren't found, create a blank iframe for the document
		var requires_insert = false;
		if(tiframe == null) {
			tiframe = document.createElement('iframe');
			tiframe.id = 'tiframe';
			tiframe.src = 'blank.html';
			tiframe.name = 'tiframe';
			requires_insert = true;
		}
		
		tiframe.style.position = 'absolute';
		tiframe.style.margin = '0';
		tiframe.style.border = '0';
		
		var dimensions = element.getDimensions();
		var offsets = Position.positionedOffset(element);
		
		tiframe.style.top = offsets[1] + 'px';
		tiframe.style.left = offsets[0] + 'px';
		tiframe.style.width = element.offsetWidth + 'px';
		tiframe.style.height = element.offsetHeight + 'px';
		
		// insert it into the DOM after it has been positioned
		if(requires_insert) {
			document.body.appendChild(tiframe);
		}
	},
	
	// destroy the tiframe object
	unshim: function(id)
	{
		Prototype.Browser.IE7 = Prototype.Browser.IE && (typeof document.body.style.maxHeight != "undefined"); 	
		if (! Prototype.Browser.IE || Prototype.Browser.IE7) return;
		var tiframe = $('tiframe');
		if(tiframe != null) {
			tiframe.remove();
		}
	}
}

// check for prototype.js
if ((typeof Prototype == 'undefined') ||
    (typeof Element == 'undefined') ||
    (typeof Element.Methods == 'undefined') ||
    parseFloat(Prototype.Version.split(".")[0] + "." +
               Prototype.Version.split(".")[1]) < 1.5)
	throw("iFrameShim requires the Prototype JavaScript framework >= 1.5.0");
	
