
var modActions2 = null;

function ContentLoader() {
	
	var backgDiv = null;
	var backgContentContainer = null;
	var backgContent = null;
	var reziseIntervall = null;
	var contentType = "iframe";
	
	var movie = "";
	var movieHeight = null;
	var movieWidth = null;
	
	var movieSmall = "";
	var smallHeight = null;
	var smallWidth = null;
	var smallJusti = 0;
	
	var f_width = null;
	var f_height = null;
	
	var color = "#FFFFFF";
	
	
	var isLogin = true;			//Wird für die Weiterleitung der Registrierung benötigt.
	var registerUrl = "";		//Registrierungs URL
	var goByClose = false		//Zeigt an ob der inhalt abhängig vom login nun bei schließen zur Reg springen soll.
	
	var questionObject = null;
	
	var closeCallback = null;	//CallBack beim Schließen
	var showCloser = true;		//Gibt an ob der Closer gezigt werden soll
	
	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;
	}
	
	this.setLogin = function(boolean, url) {
		isLogin = boolean;
		registerUrl = url;
	}
	
	this.setShowCloser = function(bool) {
		showCloser = bool;
	}
	
	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";
	}
	
	/**
	 * URL: die Adresse für dem Iframe
	 * Width/height: höhe / breite des Layers
	 * cType: ist "iframe" oder "ajax" oder "message"
	 * pars: getString für ajax
	 * fader: Mit Abdunklung des Contents
	 * noVideo: es wird kein Video gespielt (für Menü)
	 * gotToReg: Es wird beim Schließen zur Registrierung gesprungen.
	 * display: ob der inhalt angeizeigt werden soll.
	 * topPadding: Abstand nach oben bei Iframe
	 * Value für eine Message
	 */
	this.loadContent = function(url, width, height, ctype, pars, fader, noVideo, gotToReg, display, topPadding, message) {
		loadContent(url, width, height, ctype, pars, fader, noVideo, gotToReg, display, topPadding, message);
	}
	function loadContent(url, width, height, ctype, pars, fader, noVideo, gotToReg, display, topPadding, message) {
		setBackgProperty();

		if(topPadding) {
			backgContent.style.paddingTop = topPadding+"px";
		}else {
			backgContent.style.paddingTop = "0px";
		}
		
		
		if(ctype) {
			contentType = ctype;
		}
		
		if(gotToReg == 1) {
			goByClose = true;
		}else {
			goByClose = false;
		}
		
		f_width = width;
		f_height = height;	

		
		try {
			top.modController.closeAllMod(this);
		}catch(e) {}		
		
		try{
			top.modController.stopAllMovies();	
		}catch(e) {}
		
		
		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" style="display:'+( (showCloser==true)? "block":"none"  )+'"></div>'+
								'		<iframe id="contentFrame" name="contentFrame" height="'+height+'" width="'+width+'" frameborder="no" 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("#", "");
				try{
					pars += "&noVideo="+noVideo;
				}catch(e){}

				var myAjax = new Ajax.Request(
						url, 
						{
							method: 'post', 
							parameters: pars, 
							onComplete: showResponse
						});				
				
				break;
				
			case "message":
				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" style="display:'+( (showCloser==true)? "block":"none"  )+'"></div>'+
								'		<div class="logMessage" style="line-height:17px; height:'+height+'px; width:'+(width-2)+'px; border:1px solid #cccccc;" >'+
								'			<div style="padding:10px;">'+ message +'</div>'+
								'		</div>'+
								'	</div>';
								'</div>';
					
					backgContent.innerHTML = cont;
					backgContent.style.width = "";
					
					document.getElementById("contentCloser").onclick = closeContent;
						
					if(display != 1) {
						backgContentContainer.style.display = "block";
					}
					
				},600);				
				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" style="display:'+( (showCloser==true)? "block":"none"  )+'"></div>'+
		'		'+originalRequest.responseText+
		'	</div>';
		'</div>';
		
		
		backgContent.innerHTML = cont;
		backgContent.style.width = "";
		
		document.getElementById("contentCloser").onclick = closeContent;
		backgContentContainer.style.display = "block";
		
		if(document.getElementById('menuVideo')) {	
			
			modActions2 = new ModerationActions('modActions2');
			
			modActions2.setPlayerUrl('./mediaplayer/moderation.swf');
			modActions2.setMovieBig(movie);
			modActions2.setMovieSmall(movieSmall);
			modActions2.setHeight(movieHeight);
			modActions2.setWidth(movieWidth);
			modActions2.setSmallHeight(smallHeight);
			modActions2.setSmallWidth(smallWidth);
			modActions2.setSmallJustification(smallJusti);
			//modActions2.setMorphProz(50);
			
			modActions2.init('', 'menuVideo', 'menuVideoSwf');			
			
			/*
			var so = new SWFObject('./mediaplayer/moderation.swf','mpl','310','249','9');
			so.addParam('wmode','transparent');
			so.addVariable('video', movie);
			so.addVariable('callBack', 'void(0)');
			so.write('menuVideo');
			*/
		}
		
	}

	this.setMovie = function(m, w, h) {
		movie = m;	
		movieHeight = h;
		movieWidth = w;
	}
	
	this.setMovieSmall = function(m, w, h, j) {
		movieSmall = m;		
		smallWidth = w;
		smallHeight = h;
		smallJusti = j;
	}
	
	this.setContentType = function(t) {
		contentType = t;		
	}
	
	this.setColor = function(c) {
		color = c;	
	}
	
	
	this.setQuestionObject = function(obj) {
		questionObject = obj;
	}
	
	this.resetGoByClose = function() {
		goByClose = true;
	}
	
	this.closeContent = function(event) { closeContent(event); }
	function closeContent(event) {	
			
		
		try {
			if(contentFrame.ObjectProgress) {
				var p = contentFrame.ObjectProgress;
				window["modulSlider"].setProgressForModul( p );
			}
		}catch(e) {
			if(!window.location.search.match(/to=/)) {
				window.location.reload();
			}
		}
		
		if(goByClose && isLogin == false) {
			try {
				top.modController.closeAllMod(this);
			}catch(e) {}	
			
			try {
				if(questionObject.style.display != "block") {
					questionObject.style.display = "block";
					goByClose = false;
					return;
				}else {
					goByClose = false;
				}
			}catch(e) {}
		}
				
		try {
			closeCallback();
			if(closeCallback!=null) return;
		}catch(e) {}
		
		
		try {
			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 = "";
		}catch(e) {}
		
	}
	
	this.setCloseCallback = function(c) {
		closeCallback = c;		
	}
	
	
}



