/**
 * IframeShim
 * 
 * Defines IframeShim, a class for obscuring select lists and flash objects in IE.
 * 
 * @license http://clientside.cnet.com/wiki/cnet-libraries#license
 */	
var IframeShim = new Class({
	Implements: [Options, Events],
	options: {
		name: '',
		className: 'iframeShim',
		display: false,
		browsers: (Browser.Engine.trident4 || (Browser.Engine.gecko && !Browser.Engine.gecko19 && Browser.Platform.mac))
	},
	initialize: function (element, options){
		this.setOptions(options);
		this.element = $(element);
		this.makeShim();
		return;
	},
	makeShim: function(){
		if (!this.options.browsers) {
			return this;
		}
		
		/* Determine id */		
		this.id = this.options.name || new $time()+'_shim';
		
		/* Determine z-index */
		if (this.element.getStyle('z-index').toInt()<1 || isNaN(this.element.getStyle('z-index').toInt())) {
			this.element.setStyle('z-index', 5);
		}
		var z = this.element.getStyle('z-index')-1;
		
		/* Create shim */
		this.shim = new Element('iframe', {
			'src': "javascript:'';",
			'frameborder': '0',
			'scrolling': 'no',
			'id': this.id,
			'class': this.options.className,
			'styles': {
				'width': 0,
				'height': 0,
				'left': 0,
				'top': 0,
				'position': 'absolute',
				'z-index': z,
				'border': 'none',
				'filter': 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
			}
		});
		this.element.store('shim', this);

		/* Inject shim */
		var inject = function(){
			this.shim.inject(this.element, 'after');
			if (this.options.display) {
				this.show();
			} else {
				this.hide();
			}
		};
		if (Browser.Engine.trident && !IframeShim.ready) {
			window.addEvent('load', inject.bind(this));
		} else {
			inject.run(null, this);
		}
	},
	position: function(shim){
		if (!this.options.browsers || !IframeShim.ready) {
			return this;
		}
		
		/* Size shim */
		var size = this.element.getSize();
 		this.shim.setStyles({
			'width': size.x,
			'height': size.y,
			'left': this.element.offsetLeft,
			'top': this.element.offsetTop
		});
		return this;
	},
	hide: function(){
		if (this.options.browsers) {
			this.shim.setStyle('display', 'none');
		}
		return this;
	},
	show: function(){
		if (this.options.browsers) {
			this.shim.setStyle('display', 'block');
		}
		return this.position();
	},
	dispose: function(){
		if (this.options.browsers) {
			this.shim.dispose();
		}
		return this;
	}
});
window.addEvent('load', function(){
	IframeShim.ready = true;
});