
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");
	backgContentContainer.onmousedown = function() {
	    closeContent();
	}
	$('contentBackgContainer').hide();

	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;
		
	//dojo.connect(dojo.global,"onscroll",null,"setBackgProperty");		
	
	var alt = window.onScroll;
	window.onscroll = function() {
	    try{ alt(); } catch(e) {}
	    setBackgProperty();
	}
    }
	
    this.setLogin = function(boolean, url) {
	isLogin = boolean;
	registerUrl = url;
    }
	
    this.setShowCloser = function(bool) {
	showCloser = bool;
    }
	
    this.setBackgProperty = function() { setBackgProperty(); }
    function setBackgProperty() {
	try {
	    //backgDiv.style.height = window.innerHeight+"px";
	    backgDiv.style.width = window.innerWidth+"px";
	    backgContentContainer.style.width = window.innerWidth+"px";
	    if(navigator.appVersion.match(/Safari/)) {
		backgContentContainer.style.height = "3000px";
	    } 
	}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";
	backgContent.style.paddingTop = parseInt(document.documentElement.scrollTop)+"px";
	
	if(navigator.appVersion.match(/Safari/)) {
	    backgDiv.style.top = document.body.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, sc) {
	loadContent(url, width, height, ctype, pars, fader, noVideo, gotToReg, display, topPadding, message, sc);
    }
	
    function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	 
	if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
    }
	
    function loadContent(url, width, height, ctype, pars, fader, noVideo, gotToReg, display, topPadding, message, sc) {
	setBackgProperty();
	$('contentBackgContainer').show();

	if(topPadding) {
	    backgContent.style.paddingTop = (getScrollXY()[1]+topPadding)+"px";
	//backgContent.style.marginLeft = "-152px";
	}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) {}
		
	/*
		 * Flag das angibt ob der Drucken Knopf bei cn_iframe Content angezeigt
		 * werden soll.
		 */
	var showPrintOption = true;
		
	switch(contentType) {
		
	    case "iframe":
		if(fader) {
		    document.getElementsByTagName("BODY")[0].style.overflowX = "hidden";
		    //document.getElementsByTagName("BODY")[0].style.overflowY = "hidden";
		    backgDiv.style.display = "block";
		    new Effect.Appear(backgDiv, {
			from: 0.0, 
			to: 0.9, 
			duration: 0.1
		    });
		    setTimeout(function() {backgDiv.style.opacity = "0.7" }, 200);
		    
		}
				
		setTimeout(function() {
		    var cont = 	'<div style="position:relative; padding-top:20px; margin: 0 auto; width:'+(width)+'px;">'+
				'	<div style="background-color:#ffffff; border: 0px solid #dddddd;">'+
				'		<div id="contentCloser" class="pngtrans" style="display:'+( (showCloser==true)? "block":"none"  )+'; '+( (sc==false)? "background-image: url(/img/trans.gif);":""  )+'"></div>'+
				'		<iframe id="contentFrame" scrolling="no" name="contentFrame" height="'+height+'" width="'+width+'" frameborder="no" src="'+url+'"></iframe>'+
				'	</div>';
				'</div>';
					
		    backgContent.innerHTML = cont;
		    backgContent.style.width = "";
					
		    document.getElementById("contentCloser").onclick = closeContent;
						
		    if(display != 1) {
			backgContentContainer.style.display = "block";
		    }
			setBackgProperty();		
		},600);
		break;

	    case "cn_iframe_noprint":
		showPrintOption = false;
	    case "cn_iframe":
		if(fader) {
		    document.getElementsByTagName("BODY")[0].style.overflowX = "hidden";
		    //document.getElementsByTagName("BODY")[0].style.overflowY = "hidden";
		    backgDiv.style.display = "block";
		    new Effect.Opacity(backgDiv, {
			from: 0.0, 
			to: 0.9, 
			duration: 0.5
		    });
		}
		backgContentContainer.onmousedown = function() {
		    return false;
		}
		setTimeout(function() {
		    var cont = 	'<div style="position:relative; top:20px; margin: 0 auto; width:'+(width)+'px; border:1px solid #dcdcd9;">'+
				'	<div style="background-color:#ffffff;">'+
				'		<div style="height:36px; width:'+(width)+'px; border-bottom:2px solid #dcdcd9; background-color: #fcfcfa;">'+
				'			<div class="cn_closer" onclick="contentLoader.closeContent();"></div>'+
				'		</div>'+
				'		<div id="contentCloser" class="pngtrans" style="display:none"></div>'+
				'		<iframe id="contentFrame" name="contentFrame" height="'+height+'" width="'+width+'" frameborder="no" src="'+url+'"></iframe>'+
				'		<div style="height:36px; width:'+(width)+'px; border-top:2px solid #dcdcd9; background-color: #ebebeb;">'+
				'			<div class="cn_closer" onclick="contentLoader.closeContent();"></div>'+
				(showPrintOption ? '<div class="cn_print" onclick="contentFrame.print(); return false;"></div>': '') +
				'		</div>'+
				'	</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.9, 
			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.9, 
			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) {	
	$('contentBackgContainer').hide();	
		
	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.9, 
		to: 0.0, 
		duration: 0.5
	    });
	    setTimeout(function() {
		document.getElementsByTagName("BODY")[0].style.overflowX = "auto";
		document.getElementsByTagName("BODY")[0].style.overflowY = "auto";
		backgDiv.style.display = "none";			
	    },600);
	    backgContent.innerHTML = "";
	}catch(e) {}
		
    }
	
    this.setCloseCallback = function(c) {
	closeCallback = c;		
    }
	
	
}




