﻿function ThickBox(boxid, options)
{
	this.el = jQuery('#' + boxid)[0];
	this.el.control = this;
	if (options.useIframe) {
		this.voile = this.el.getElementsByTagName('iframe')[0];
		this.child = this.el.getElementsByTagName('div')[0];
		jQuery(this.child).css('z-index',1);
	}
	else {
		this.voile = this.el.getElementsByTagName('div')[0];
		this.child = this.el.getElementsByTagName('div')[1];
	}
	
}

ThickBox.prototype.show = function() {
	jQuery(this.el).remove();
	jQuery(this.el).appendTo(document.forms[0]);
	jQuery(this.el).css('z-index', '1');
	this.el.style.display = '';
	jQuery(this.voile).fadeTo(0, 0); //TODO: refine this
	this.voile.style.display = '';
	var child = this.child;
	var voile = this.voile;
	jQuery(this.voile).fadeTo("slow", 0.75, function() {
		var height = jQuery(child).height();
		var wHeight = Math.min(jQuery(window).height(), jQuery('body').height());
		var top = (wHeight / 2) - (height / 2) + jQuery('html').scrollTop();
		jQuery(child).css('top', top + 'px');
		child.style.display = '';
	});
}

ThickBox.prototype.hide = function() {
	this.child.style.display = 'none';
	var thiz = this;
	jQuery('#' + this.voile.id).fadeOut("normal", function() { jQuery(thiz.el).css('z-index', '-1'); });
}