if(jQuery)
{
	var medmudbox = new mudbox();
}

/**
 * mudbox Klasse (quasi lightbox mit jQuery und Prototype, und dynamischem inhalt)
 * @author Marcel Siewert
 * @copyrights Marcel Siewert 2009
 */

function mudbox()
{
	//Private
	var _this = this;
	var eBackground;
	var eContent;
	var bVisible;
	this.bWasInit = false;
	
	//Public
	this.idBg = "med_mudboxbg";
	this.idContent = "med_mudbox";
	this.cssBg = {'position': 'absolute', 'background': '#000', 'z-index': 999990};
	this.cssContent = {'position': 'absolute', 'background': 'white', 'width': 800, 'height':406, 'z-index': 999999};
	this.forceHCentered = true;
	this.forceVCentered = true;
	this.transparency = .7;
	this.speedIn = .3;
	this.speedOut = 0;
	this.innerHtml = '';
	
	//Methods
	this.init = function()
	{
		if(!jQuery)
		{
			return;
		}
		var _this = this;
		this.eBackground = jQuery('<div/>').attr({'id':this.idBg});//new Element('div', {'id':this.idBg});
		this.eContent =  jQuery('<div/>').attr({'id':this.idContent});//new Element('div', {'id':this.idContent});
		jQuery('body').append(_this.eBackground).append(_this.eContent);
		jQuery(this.eBackground).hide().fadeTo(0,0);
		jQuery(this.eContent).hide();
        jQuery(window).scroll(function(){if(bVisible)_this.arrange()});
		jQuery(window).resize(function(){if(bVisible)_this.arrange()});
		_this.arrange();
		this.bWasInit = true;
		/*jQuery(document).ready(function(){
				jQuery('body').append(_this.eBackground).append(_this.eContent);
				jQuery(window).scroll(function(){if(bVisible)_this.arrange()});
				jQuery(window).resize(function(){if(bVisible)_this.arrange()});
				_this.arrange();
				bWasInit = true;
		});
		_this.arrange();*/
	}
	this.arrange = function()
	{
		
		if(!this.eBackground || !this.eContent)return;
		var pos = document.viewport.getScrollOffsets();
		var height= document.viewport.getHeight();
		var width = document.viewport.getWidth();
		jQuery(this.eBackground).css({'width': width, 'height': height, 'left': pos.left, 'top': pos.top}).css(this.cssBg);
		jQuery(this.eBackground).fadeTo(0,this.transparency);
		jQuery(this.eContent).css({'width': width, 'height': height, 'left': pos.left, 'top': pos.top}).css(this.cssContent);
		if(this.forceHCentered)
			jQuery(this.eContent).css('left' , (( pos.left + (width/2)) - jQuery(this.eContent).width()/2));
		if(this.forceVCentered)
			jQuery(this.eContent).css('top' , ((pos.top +(height/2)) - jQuery(this.eContent).height()/2));
		
	}
	this.show = function()
	{
		if(bVisible || !this.bWasInit)return;
		jQuery(this.eContent).html(this.innerHtml);
		this.arrange();
		jQuery(this.eBackground).show().fadeTo(this.speedIn,this.transparency);
		jQuery(this.eContent).show();
		bVisible = true;
	}
	this.hide = function()
	{
		if(!this.bWasInit)return;
		//jQuery(this.eBackground).fadeTo(this.speedOut,0,function(){});
		jQuery(this.eBackground).hide();		
		jQuery(this.eContent).hide();
		bVisible = false;
	}
	this.load = function(url)
	{
		if(!this.bWasInit)return;
		jQuery.get(url,function(data){jQuery(_this.eContent).append(data)});
		this.show();
	}
}

