// hackish , would require an upgrade to mootools 1.2 beta for proper support of IFrame
var IFrame = new Class({
	iframe :        false,
	load_code :     null,

	options : {
		load_code : null,
		completion_id : "",
		autoHeightHideFooterSize : 0
	},

 	initialize : function(iframe_id, options) {
		this.setOptions(options);

		this.iframe = $(iframe_id);
		this.load_code = this.options.load_code;
		this.iframe.addEvent('load', this.onload.bind(this));
	},

	onload : function() {
		var oDoc = this.iframe.contentWindow || this.iframe.contentDocument;
		
		if (oDoc.document) {
			oDoc = oDoc.document;
		}

		try {var location = this.iframe.contentWindow.location.href;} catch(e){ var location = false;}
		var text = oDoc.getElementsByTagName('body').item(0).innerHTML;
		if (text.trim() != "" && !text.test(this.options.completion_id)) {
			this.fireEvent('onFailure', [text, location], 20);
		} else {
			this.fireEvent('onSuccess', [text, location], 20);
		}
		if($type(this.load_code) == 'function') {
			this.load_code.call(this);
		}
	},

	autoHeight : function() {
		var oDoc = this.iframe.contentWindow || this.iframe.contentDocument;
		if (oDoc.document) {
			oDoc = oDoc.document;
		}

		var offsetHeight = oDoc.getElementsByTagName('body').item(0).offsetHeight;
		if(offsetHeight == null)
			offsetHeight = oDoc.getElementsByTagName('body').item(0).scrollHeight;
	
			
		if(offsetHeight != null) {
			this.iframe.setAttribute('height', offsetHeight - this.options.autoHeightHideFooterSize);
			this.iframe.setStyle('height', (offsetHeight - this.options.autoHeightHideFooterSize)+15+"px");
		}
	}
});
IFrame.implement(new Options, new Events);


var ifrlayer = {
	ie: document.all && window.print && !window.opera && document.getElementById,
	$: function(obj) { 
		if (!obj) return null;
		return (typeof(obj)=="string") ? document.getElementById(obj) : obj; 
	},
	make: function(obj) {
		return;
		obj = this.$(obj);
		if(!obj) return;
		if(this.ie) {
			if (!obj.iframelayer) {
				var ifr = document.createElement('iframe');
				ifr.src = "javascript:false";
				obj.parentNode.insertBefore(ifr, obj);
				obj.iframelayer = ifr;
			}
			var ifr = obj.iframelayer;
			if(obj.currentStyle.zIndex != "" && parseInt(obj.currentStyle.zIndex) > 1) {
				ifr.style.zIndex = parseInt(obj.currentStyle.zIndex)-1;
			}
			with(ifr.style) {
				filter = "mask()";
				position = "absolute";
			}
			obj.iframelayer.style.visibility = "visible";
			ifrlayer.move(obj,true);
		}
	},
	hide: function(obj) {
		obj = this.$(obj);
		if(!obj) return;
		if(obj.iframelayer) {
			obj.iframelayer.style.visibility = "hidden";
		}
	},
	kill: function(obj) {
		obj = this.$(obj);
		if(!obj) return;
		if(obj.iframelayer) {
			obj.iframelayer.parentNode.removeChild(obj.iframelayer);
			obj.iframelayer = null;
		}
	},
	move: function(obj, size) {
		obj = this.$(obj);
		if(obj && obj.iframelayer) {
			with(obj.iframelayer.style) {
				top = obj.offsetTop + "px";
				left = obj.offsetLeft + "px";
				if(size) {
					width  =  obj.offsetWidth + "px";
					height =  obj.offsetHeight + "px";
				}
			}
		}
	}
};
