/* 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-06-19 20:25:28 -0500 (Tue, 19 Jun 2007) $
 * $Rev: 2111 $
 *
 * Version 2.1
 */
(function($) {
	$.fn.bgIframe = $.fn.bgiframe = function(s) {
		if ($.browser.msie && parseInt($.browser.version) <= 6) {
			s = $.extend({top: '0', left: '0', width: 'auto', height: 'auto', opacity: true, src: 'javascript:false;'}, s || {});
			var prop = function(n) {
				return n && n.constructor == Number ? n+'px' : n;
			}, html=[
				'<iframe class="bgiframe" frameborder="0" tabindex="-1" src="',
				s.src,
				'"',
				'style="display: block; position: absolute; z-index: -1;"/>'].join("");
			
			return this.each(function() {
				var fid = "frame_" + new Date().getTime();
				if (!this.hasFrame)
				{
					var thtml = html.replace(/class=/, 'id="' + fid + '" class=');
					$(this).append(thtml);
					$("#" + fid).get(0).element = this;
					
					// $(this).addClass(fid);
					
					this.hasFrame = true;
					
					var frame = $("#" + fid).get(0);
					frame.style.filter = 'Alpha(Opacity=0)';
					frame.style.top = s.top;
					frame.style.left = s.left;
					frame.style.width = s.width;
					frame.style.height = s.height;
					if (s.top == 'auto')
						frame.style.setExpression('top', '($(this.element).offset().top + (((parseInt(this.element.currentStyle.borderTopWidth) || 0) * -1)) + "px")');
					if (s.left == 'auto')
						frame.style.setExpression('left', '($(this.element).offset().left + (((parseInt(this.element.currentStyle.borderLeftWidth) || 0) * -1)) + "px")');
					if (s.width == 'auto')
						frame.style.setExpression('width', '(this.element.offsetWidth + "px")');
					if (s.height == 'auto')
						frame.style.setExpression('height', '(this.element.offsetHeight + "px")');
					frame.style.setExpression('zIndex', '(this.element.currentStyle.zIndex - 1)');
				}
			});
		}
		return this;
	};
	if (!$.browser.version)
		$.browser.version = navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];
})(jQuery);

