
function BildObjekt(a,b,c){
    this.b=[new Image(),new Image(),new Image()];
    this.b[0].src=a; this.b[1].src=b; this.b[2].src=c; 
	this.b1=[a,b,c];
}
function BildObj (a,b,c,d,e,f){

}
function Lernprogramm(){
//	var xxx=[1,3,4,5,6,7,28];
	var ico = [
			["./img/menu001.png","./img/menu001.png"],   // zu- aufgeklappt lernprogrammebene
			["./img/menu001.png","./img/menu001.png"],   // zu- aufgeklappt Kapitelebene
			["./img/menu010.png","./img/menu010.png"],   // zu- aufgeklappt lerneinheitebene
			["./img/menu100.png","./img/menu100.png"]];  // frei
	var sta = [
			["./img/status000.png","./img/status001.png","./img/status002.png","./img/status003.png","./img/status004.png"], // lernprogrammebene, nix, gesehen, abgehakt, fehler, bestanden
			["./img/status010.png","./img/status011.png","./img/status012.png","./img/status013.png","./img/status014.png"],
			["./img/status100.png","./img/status101.png","./img/status102.png","./img/status103.png","./img/status104.png"],
			["./img/status100.png","./img/status100.png","./img/status100.png","./img/status100.png","./img/status100.png"]];
	var text="";
	var text1="";
	var oldM=null; // vorherige Kapitelmarkierung, kann auf Zeile oder Text stehen, 
	var oldMM=null // markierung, wenn restart 
	var nnn=0;
	var gebene=0;
	this.l=null;
	var aktKap=null;
	var neben=new Array();
	var n=0;
	var restart="anrichten-statt-portionieren";
	var menuObj=null;
	var glfdNo=1;
//	var statusstr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
//	var fh=null;
//	this.gettext=function(){return text+'\n\ranzahl states:'+n;}
	this.set=function(fh){
		text="";
		this.l.set(fh);
		}

	this.state=function (id1, t3){
		n++;
		this.id=id1;
		this.titel=t3;
		this.f0=function(){this.titel=this.id;}
		this.f1=function(){this.titel='f1()';}
		this.f2=function(){this.titel='f2()';}
		this.f3=function(){this.titel='f3()';}
	}
//		parameter: titel, stateliste, kapitelliste, {le/kap, neu/begonnen/fertig} 

	this.kap=function  (c, t, s, k){
		this.pfad='xxx';
		var vorgaenger=null;
		this.titel=t;
		var t1=t;
		var s1=s;		// Liste der States
		var k1=k;   	// liste der nachfolgenden Kapitel
		var zeile;		// zeiger auf DIV-objekt (Zeile)
		var aktM=null;	// aktuelle Kapitelmarkierung, kann auf Zeile oder Text stehen, 
		var bild=null;  // Zeiger auf IMG-Objekt (Icon)
		var ukap=null;	// Zeiger auf DIV-Objekt (Unterkapitel, Lerneinheit)
//		var dummy = null;
		var kText=null;	// Zeiger auf SPAN-Objekt (Kapitelüberschrift)
		var i, j=0;
		var ebene=0;
		var typ=c;  // 0=lp, 1=kap, 2=le
		var sichtbar=0;
		var status=0; // 0 nix, 1 gesehen 2 fehler 3 abgehakt
		var selber=null;  // Zeiger auf div-objekt zeile
		var eigen=this;
		var lfdNo=glfdNo++;

		this.getCookie=function(){ text=text+sichtbar; text1=text1+status;
			if (k1){for (j=0; j<k1.length; j++) k1[j].getCookie();}
//alert(text);
		}

		this.Init=function(v){
			var len;
//			if(statusstr.length>lfdNo)status=statusstr[lfdNo];
//			status=gScorm.getStanda(lfdNo);	
//			else status=0;
			ebene=gebene;
			if (!neben[ebene]) neben[ebene]=new Array();
			len=neben[ebene].length;
			neben[ebene][len]=this;
			vorgaenger=v;
			if (k1){gebene++;for (j=0; j<k1.length; j++) k1[j].Init(this);gebene--;}
		}
		this.getStatus = function() {return status;}
		this.setStatus = function(s) {status = s; bild.src=sta[typ][status]; gScorm.setStanda(lfdNo, s);}
		this.getText = function() {return t1;}
		this.getVorgaenger = function() {return vorgaenger;}
		this.set=function(fh){
			for (i=0; i<s1.length; i++) s1[i][fh](); // function, die als Parameter übergeben wird, aufrufen
			if (k1){for (j=0; j<k1.length; j++) k1[j].set(fh);} // Rekursion
		}

		function setZeile (obj, t){
			bild = gMenu.contentWindow.document.createElement("img");
		    bild.src = sta[typ][status];
//	alert(status+ ' ' + lfdNo + '   ' + t1);
		    bild.onclick=function (){swap(-1);};
			kText = gMenu.contentWindow.document.createElement("span");
//			kText.style.display='inline-block';
			kText.style.marginLeft='3px';
			kText.style.width='83px';
			kText.appendChild(gMenu.contentWindow.document.createTextNode(t));
		    kText.onclick=function (){swap(0);};
		    zeile = gMenu.contentWindow.document.createElement("div");
		    zeile.id="zeile"+typ;
		    zeile.title=""+ s1[0].titel;
//			zeile.Class="zeile";
			zeile.style.backgroundColor=gPara.menu.bg[ebene];
//			zeile.style.backgroundColor='#ff0000';
			zeile.style.backgroundImage = "url("+ico[typ][sichtbar]+")"; 
			zeile.style.backgroundRepeat="no-repeat";
			zeile.style.vAlign="top";
		    zeile.onclick=function (){ setSeite();};
		    zeile.appendChild(bild);
		    zeile.appendChild(kText);
//		    zeile.onclick=function (){swap(-1)};
//		    aktM=oldM=zeile;	// Kapitelzeile mit Bild markieren
		    aktM=oldM=kText;	// Kapitelzeile ohne Bild markieren
			if (oldMM) oldM=oldMM; 
		    obj.appendChild(zeile);
		}

		this.setMenu=function(obj){
			selber=obj;
			if(selber)	selber.style.backgroundColor=gPara.menu.bg[ebene];
			var j, p=null;
			var t=this.titel; //+('..............'.slice(0, ebene));
		    if ((typ<3) && (gPara.menu.start>ebene)) sichtbar=1;
			setZeile(obj, t);
			if (k1){
			    ukap = gMenu.contentWindow.document.createElement("div");
			    ukap.id="ukap";
				ukap.style.marginLeft=gPara.menu.Einrueckung;
			    ukap.style.width=gPara.menu.Breite - ((2+ebene)*gPara.menu.Einrueckung)-10+'px';
				ukap.style.backgroundColor=gPara.menu.bg[ebene];
		    	obj=selber.appendChild(ukap);
			    for (j=0; j<k1.length; j++) k1[j].setMenu(obj); // recursion
			}

			if (ukap && (sichtbar==0))	ukap.style.display='none';
			
// FEHLER bei FireFox			
			if (s1[0].id==gScorm.GetRestart())  {
//				restart=s1[0].id;
//alert(restart);				
				var v=this.getVorgaenger();
				while (v!=null) {v.aufklappen(); v=v.getVorgaenger();}
//				swap(0);  // letzte, aktuelle Ebene aufklappen und markieren
				oldMM=kText;
				aktKap=eigen;
				setPfad();
			}
			return restart;
			//if (restart>0) return restart;
			//else return s1[0].id;
		}
		
		this.aufklappen = function(){ swap(0);}
		this.zuklappen = function(v){ // wenn nur eine Ebene erlaubt ist!!!!!!!!!!!
			if(ukap &&(lfdNo!=v)) {
				ukap.style.display='none';
				sichtbar=0;
				zeile.style.backgroundImage = "url(" + ico[typ][sichtbar] + ")"; 
				bild.src=sta[typ][status];

			}
		}

		function swap(s){
			var j;
			if(s>-1) sichtbar=s;
			if (oldM==aktM) sichtbar=0;  // wenn darselbe menupunkt angeklickt wird 
			if(ukap) {

				if(sichtbar==0) {
					ukap.style.display='block';
					sichtbar=1;
				}
				else {
					ukap.style.display='none';
					sichtbar=0;
				}	
			}
			else{  // nicht ukap
				if(sichtbar==0) sichtbar=1; else sichtbar =0;
				sichtbar=1;
			}
			if (gPara.menu.swapmodus && ukap){
				for (j=0; j<neben[ebene].length; j++) neben[ebene][j].zuklappen(lfdNo);
				}
			if (typ<2)	zeile.style.backgroundImage = "url(" + ico[typ][sichtbar] + ")"; 
//			oldM.style.backgroundColor=gPara.menu.bg[ebene];
			oldM.style.backgroundColor=oldM.parentElement.style.backgroundColor;
			aktM.style.backgroundColor=gPara.menu.bgm;
			oldM=aktM;
		}
		function setSeite(){
			gScorm.SetRestart(s1[0].id);  // restart setzen
			setPfad();
			gLektion.src=s1[0].id+".html";
			bild.src=sta[typ][status];
//			debugger;
//			oldM.style.backgroundColor=gPara.menu.bg[ebene];
			oldM.style.backgroundColor=oldM.parentElement.style.backgroundColor;
			aktM.style.backgroundColor=gPara.menu.bgm;
			oldM=aktM;
			aktKap=eigen;
			if (lp.getStatus()<1) lp.setStatus(1);
		}

		function setPfad(){
			text=t1;
			var v=vorgaenger; while (v!=null) {text = v.getText() + '   |   ' +text; v=v.getVorgaenger();}
			document.getElementById("pfad").firstChild.data=text;
		}

		function setAusgabe(){
			text=t1;
			for (i=0; i<s1.length; i++) text+=('\n\r'+s1[i].id);
			document.getElementById("ausgabe").firstChild.data=text;
		}

		this.Completed=function(){
			if (k1){
				for (j=0; j<k1.length; j++) k1[j].Completed();  // recursion 
				var h1x=true;	
				for (i=0; i<k1.length; i++) {if (k1[i].getStatus()<2) h1x=false;}
				if (h1x) this.setStatus(2);  // Kapiteleben abhaken
			}
		}
		
		this.alles_abhaken=function(){
			if (k1){
				for (j=0; j<k1.length; j++) k1[j].alles_abhaken();  // recursion 
//				var h1x=true;	
				for (i=0; i<k1.length; i++) {k1[i].setStatus(2);}
//				if (h1x) this.setStatus(2);  // Kapiteleben abhaken
				
			}
		}
	}
//****************************************  Ende von Kapitel *******************************************************************	
	this.Init = function() {
		var h=gScorm.getStand().split(",");
		if (h.length>3)	statusstr=h;
		this.l.Init(null);
		aktKap=this.l;
//		gWin.style.left=gPara.lektion.Links+'px'; 
//		gWin.style.top=gPara.lektion.Oben+'px'; 
		gWin.style.width=gPara.lektion.Breite+'px'; 
		gWin.style.height=gPara.lektion.Hoehe+'px'; 

		gPfadp.style.top=gPara.Lernpfad.Oben+'px'; 
//		gPfadp.style.width=gPara.lektion.Breite+'px'; 
//		gPfad.style.marginLeft=gPara.Lernpfad.Links+'px'; 
		
		gLektion.style.left=gPara.ausgabe.Links+'px'; 
		gLektion.style.top=gPara.ausgabe.Oben+'px'; 
		gLektion.style.width=gPara.ausgabe.Breite+'px'; 
		gLektion.style.height=gPara.ausgabe.Hoehe+'px'; 
		gMenu.style.top=gPara.menu.Oben+'px'; 
		gMenu.style.left=gPara.menu.Links+'px'; 
		gMenu.style.width=gPara.menu.Breite+'px'; 
		gMenu.style.height=gPara.menu.Hoehe+'px'; 
//		gMenu.style.visibility=visible; 
//		gMenu.contentWindow.document.body.style.backgroundColor=gPara.menu.bg[ebene];  // Fehler bei Localhost, warum??????
//		neuAufbau();
	}

	this.Completed=function (){
		this.l.Completed();  // kapitelebene abhaken
		var wert=true;
		for (j=0; j<neben[1].length-3; j++) { if (neben[1][j].getStatus() < 2) {wert = false; break; }}
		return wert;
	}

	this.setStatus = function(s) { aktKap.setStatus(s);}
	this.getStatus = function(s) {return aktKap.getStatus();}
	this.setMenu=function(){
		var o=gMenu.contentWindow.document.getElementById("menu");
		for (i=0; i<100; i++) {
			if (o) break;
			o=gMenu.contentWindow.document.getElementById("menu");
		}
		restart = this.l.setMenu(o);
//		restart='1000';
//		if (restart.length<2) restart='1000';
		gLektion.src=restart+".html";
	}
}


var fenster=null;
function openWin()
{

	lektion=window.open('../aufgegabelt/start.htm','_blanc','width=580,height=600,resizable=no,scrollbars=no,toolbar=no,status=no,directories=no,menubar=no,location=no,dependent=yes');
}

function startFenster(url)
{
fenster=window.open(url,'fenster','width=580 height=500 resizable=no scrollbars=no toolbar=no status=no directories=no menubar=no location=no');
}

//function Fenster(url)
//{}


function Fenster_auf(url)
{
	if (fenster==null) {startFenster(url); return;}
	if (fenster.closed==true) {startFenster(url);  return;}
	else 
	{
		fenster.focus(); 
		startFenster(url);
		return;
	}
}

function Fenster_zu()
{
	if (fenster!=null) fenster.close();
}

function neuAufbau () 
{
    function Fensterweite () {
	if (window.innerWidth) {return window.innerWidth;} 
	else if (document.body && document.body.offsetWidth) {return document.body.offsetWidth;} 
	else {return 0;}
    }

    function Fensterhoehe () {
	if (window.innerHeight) {return window.innerHeight;} 
	else if (document.body && document.body.offsetHeight) {return document.body.offsetHeight;} 
	else {return 0;}
    }
    var obj = document.getElementById("MainWin").style;
    var Weite = (Fensterweite()-parseInt(obj.width))/2;
    var Hoehe = (Fensterhoehe()-parseInt(obj.height))/2;
    if (Weite<0) Weite=0;
    if (Hoehe<0) Hoehe=0;
    obj.top=Hoehe;
    obj.left=Weite;
}