/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-03-07 15:07:51 -0600 (Wed, 07 Mar 2007) $
 * $Rev: 1505 $
 */

(function($){
/**
 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 */
$.fn.bgIframe = jQuery.fn.bgiframe = function(o) {
	// This is only for IE6
	if ( !($.browser.msie && typeof XMLHttpRequest == 'function') ) return this;
	o = $.extend({ 
		top    : 'auto', // auto == .currentStyle.borderTopWidth
		left   : 'auto', // auto == .currentStyle.borderLeftWidth
		width  : 'auto', // auto == offsetWidth
		height : 'auto', // auto == offsetHeight
		src    : 'javascript:false;'
	}, o || {});
	var prop = function(n){return n&&n.constructor==Number?n+"px":n;},
	    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+o.src+'"'+
	               'style="display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');'+
				       'top:'+(o.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(o.top))+';'+
				       'left:'+(o.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(o.left))+';'+
				       'width:'+(o.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(o.width))+';'+
				       'height:'+(o.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(o.height))+';'+
				'"/>';
	return this.each(function() {
		if ( !$('iframe.bgiframe', this)[0] )
			this.insertBefore( document.createElement(html), this.firstChild );
	});
};

})(jQuery);