BoxLoader = new function BoxLoader()
{
	this.background_grau = background_grau;
	this.isIE = isIE;
	this.openWindow = openWindow;
}

function openWindow(width, height, type, src)
{
	if (width == null)
	{
		width = 300;
	}
	if (height == null)
	{
		height = 300;
	}
	if (type == null)
	{
		type = 'iframe';
	}
	if (src == null)
	{
		src = 'http://www.google.de';
	}
	this.background_grau();
	var first = getBody().firstChild;
	var div = document.createElement("div");
	div.id='box_content';
	div.innerHTML = '<div id="box_loader_header" align="right"><a href="javascript:hideWindow();" id="close_button"></a></div>';
	
	
	if (type == 'multimedia')
	{
		div.innerHTML += '<div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>';
		

	} else if (type == 'image')
	{
		var image = new Image();
		image.src = src;
		width = image.width;
		height = image.height + 45;
		div.innerHTML += '<img src="'+src+'" alt="'+src+'">';
	} else
	{
		div.innerHTML += '<iframe style="width: 100%;border: none; height: '+(height - 45)+'px;" src="'+src+'"></iframe>';
	} 
	
	var left = (document.body.clientWidth/2) - (width/2);
	if (isIE())
	{
		var top = (document.documentElement.clientHeight/2) - (height/2);
		if (top < 0)
		{
			top = 0;
		}
		div.style.setAttribute("height", height, false);
		div.style.setAttribute("width", width, false);
		div.style.setAttribute("left", left, false);
		div.style.setAttribute("top", top, false);
	} else
	{

		var top = (window.innerHeight/2) - (height/2);
		if (type != "multimedia")
		{
			div.style.height = height+"px";
			div.style.width = width+"px";
		}
			div.style.left = left+"px";
			div.style.top = top+"px";
	}
	
	getBody().appendChild(div, first);
	var s1 = new SWFObject("http://img.stadtus.de/player-viral.swf","ply",width,height,"9","#FFFFFF");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allownetworking","all");
	s1.addParam("allowscriptaccess","never");
	s1.addParam("flashvars","file="+src);
	s1.write("container");

}

function hideWindow()
{
	var box_content = document.getElementById('box_content');
	getBody().removeChild(box_content);
	background_normal();
}

function background_normal()
{
	var first = getBody().firstChild;
	if (first.id == 'box_overlay')
	{
		getBody().removeChild(first);
	}
}

function getBody()
{
	return document.getElementsByTagName("body")[0];
}

function background_grau()
{
	var elm = getBody();
	var first = elm.firstChild;
	if (first.id != 'box_overlay')
	{
		var div = document.createElement("div");
		div.id='box_overlay';
		var width = document.body.clientWidth;
		var height = document.body.clientHeight;
		if (document.documentElement.clientWidth > width)
		{
			width = document.documentElement.clientWidth;
		}
		if (document.documentElement.clientHeight > height)
		{
			height = document.documentElement.clientHeight;
		}
		if (isIE())
		{
			div.style.setAttribute("height", height, false);
			div.style.setAttribute("width", width, false);
		} else
		{

			div.style.height = "100%";
			div.style.width = "100%";
		}
		var p = 0.7;
		div.style.opacity=p;
		div.style.filter="alpha(opacity="+p*100+")";
		elm.insertBefore(div, first);

	}
	
}
function isIE()
{
	return (navigator.userAgent.toLowerCase().indexOf("msie")!=-1&&navigator.userAgent.toLowerCase().indexOf("opera")==-1);
}
