
var contentLoader = null;
var oldCLload = window.onload;
window.onload = function() {
	try{ oldCLload(); }catch(e){}
	contentLoader = new ContentLoader();
}


function ContentLoader() {
	
	var backgDiv = null;
	var backgContentContainer = null;
	var backgContent = null;
	var reziseIntervall = null;
	var contentType = "iframe";
		
	var f_width = null;
	var f_height = null;
	
	var color = "#FFFFFF";
		
	var questionObject = null;
	
	init();
	function init() {
		var div = document.createElement("div");
		var id = document.createAttribute("id");
        id.nodeValue = "overBackg";
        
        div.setAttributeNode(id);
		document.getElementsByTagName("BODY")[0].appendChild(div);
		backgDiv = document.getElementById("overBackg");
		backgDiv.style.display = "none";		
				
		var div = document.createElement("div");
		var id = document.createAttribute("id");
        id.nodeValue = "contentBackgContainer";		
        div.setAttributeNode(id);
		document.getElementsByTagName("BODY")[0].appendChild(div);		
		backgContentContainer = document.getElementById("contentBackgContainer");
		
		var div = document.createElement("div");
		var id = document.createAttribute("id");
        id.nodeValue = "contentBackg";		
        div.setAttributeNode(id);
        backgContentContainer.appendChild(div);		
		backgContent = document.getElementById("contentBackg");		
		
		
		setBackgProperty();
		window.onresize = setBackgProperty;
		
		window.onscroll = setBackgProperty;
	}
	
	
	function setBackgProperty() {		
		try {
			//backgDiv.style.height = window.innerHeight+"px";
			backgDiv.style.width = window.innerWidth+"px";
			backgContentContainer.style.width = window.innerWidth+"px";
		}catch(e) {
			//backgDiv.style.height = document.body.clientHeight+"px";
			backgDiv.style.width = document.body.clientWidth+"px";	
			backgContentContainer.style.width = document.body.clientWidth+"px";	
		}
		
		//backgContentContainer.style.top = document.documentElement.scrollTop+"px";
		backgDiv.style.top = document.documentElement.scrollTop+"px";
	}
	
	this.openMission = function(url) {
		loadContent(url, 695, 475, "iframe", true, "100", true);	
	}
	
	/**
	 * URL: die Adresse fr dem Iframe
	 * Width/height: hhe / breite des Layers
	 * cType: ist "iframe" oder "ajax"
	 * pars: getString für ajax
	 * fader: Mit Abdunklung des Contents
	 * display: ob der inhalt angeizeigt werden soll.
	 * topPadding: Abstand nach oben bei Iframe
	 */
	this.loadContent = function(url, width, height, ctype, fader, topPadding, scroll, display, pars) {
		loadContent(url, width, height, ctype, fader, topPadding, scroll, display, pars);
	}
	function loadContent(url, width, height, ctype, fader, topPadding, scroll, display, pars) {
		setBackgProperty();

		if(topPadding) {
			backgContent.style.paddingTop = topPadding+"px";
		}else {
			backgContent.style.paddingTop = "0px";
		}
				
		
		if(ctype) {
			contentType = ctype;
		}
				
		f_width = width;
		f_height = height;	
					
		switch(contentType) {
		
			case "iframe":	
						
				if(fader) {
					backgDiv.style.display = "block";
					new Effect.Opacity(backgDiv, { from: 0.0, to: 0.7, duration: 0.5 });
				}
				
				setTimeout(function() {
					var cont = 	'<div style="position:relative; padding-top:20px; margin: 0 auto; width:'+(width+2)+'px;">'+
								'	<div style="border:1px solid #ffffff; background-color:#ffffff;">'+
								'		<div id="contentCloser" class="pngtrans"></div>'+
								'		<iframe id="contentFrame" name="contentFrame" height="'+height+'" width="'+width+'" frameborder="no" '+(  (scroll==true)? '':'scrolling="no"'  )+' src="'+url+'"></iframe>'+
								'	</div>';
								'</div>';
					
					backgContent.innerHTML = cont;
					backgContent.style.width = "";
					
					document.getElementById("contentCloser").onclick = closeContent;
						
					if(display != 1) {
						backgContentContainer.style.display = "block";
					}
					
				},600);
				break;
				
				
			case "ajax":
				
				if(fader) {
					backgDiv.style.display = "block";
					new Effect.Opacity(backgDiv, { from: 0.0, to: 0.7, duration: 0.5 });
				}
				
				pars = pars + "&color=" + color.replace("#", "");

				var myAjax = new Ajax.Request(
						url, 
						{
							method: 'post', 
							parameters: pars, 
							onComplete: showResponse
						});				
				
				break;
		}
	}
	
	function showResponse(originalRequest) {
				
		var cont = 	'<div style="position:relative; padding-top:20px; margin: 66px auto 0 auto; width:'+f_width+'px;">'+
		'	<div>'+
		'		<div id="contentCloser" class="pngtrans"></div>'+
		'		'+originalRequest.responseText+
		'	</div>';
		'</div>';
		
		
		backgContent.innerHTML = cont;
		backgContent.style.width = "";
		
		document.getElementById("contentCloser").onclick = closeContent;
		backgContentContainer.style.display = "block";
				
	}

	this.setContentType = function(t) {
		contentType = t;		
	}
	
	this.setColor = function(c) {
		color = c;	
	}
	
	this.setQuestionObject = function(obj) {
		questionObject = obj;
	}
		
	this.closeMission = function(url) {
		closeContent(null);
		
		if(url!=null) {
			setTimeout(function() {
				window.loaction.href = url;
			}, 1000);
		}
	}	
		
		
	this.closeContent = function(event) { closeContent(event); }
	function closeContent(event) {	
		
		backgContentContainer.style.display = "none";
		
		new Effect.Opacity(backgDiv, { from: 0.7, to: 0.0, duration: 0.5 });
		setTimeout(function() {
			backgDiv.style.display = "none";			
		},600);
		backgContent.innerHTML = "";
	}
	
	
}




