﻿function ThickBox(boxid, options, events)
{
	this.element = jQuery('#' + boxid)[0];
	this.element.control = this;
	if (options.useIframe) {
		this.voile = this.element.getElementsByTagName('iframe')[0];
		this.child = this.element.getElementsByTagName('div')[0];
	}
	else {
		this.voile = this.element.getElementsByTagName('div')[0];
		this.child = this.element.getElementsByTagName('div')[1];
	}
	if (events) {
		this.onShown = events.onShown;
		this.onHidden = events.onHidden;
	}
}

ThickBox.prototype = {
show: function() {
	jQuery(this.element).remove();
	jQuery(this.element).appendTo(document.forms[0]);
	jQuery(this.child).css('z-index', '1');
	jQuery(this.element).css('z-index', '1');
	this.element.style.display = '';
	jQuery(this.voile).fadeTo(0, 0); //TODO: refine this
	this.voile.style.display = '';
	var child = this.child;
	var voile = this.voile;
	var thiz = this;
	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 = '';
		if (thiz.onShown) thiz.onShown();
	});
},
hide: function() {
	this.child.style.display = 'none';
	var thiz = this;
	jQuery('#' + this.voile.id).fadeOut("normal", function() {
		jQuery(thiz.element).css('z-index', '-1');
		thiz.element.style.display = 'none';
		if (thiz.onHidden) thiz.onHidden(); 
	});
}
}