var DHTML = 0, DOM = 0, MS = 0, NS = 0, OP = 0;
function DHTML_init() {
 if (window.opera) {
     OP = 1;
 }
 if(document.getElementById) {
   DHTML = 1;
   DOM = 1;
 }
 if(document.all && !OP) {
   DHTML = 1;
   MS = 1;
 }
 if (window.netscape && window.screen && !DOM && !OP){
   DHTML = 1;
   NS = 1;
 }
}
function getElem(p1,p2,p3) {
 var Elem;
 if(DOM) {
   if(p1.toLowerCase()=="id") {
     if (typeof document.getElementById(p2) == "object")
     Elem = document.getElementById(p2);
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="name") {
     if (typeof document.getElementsByName(p2) == "object")
     Elem = document.getElementsByName(p2)[p3];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="tagname") {
     if (typeof document.getElementsByTagName(p2) == "object" ||
        (OP && typeof document.getElementsByTagName(p2) == "function"))
     Elem = document.getElementsByTagName(p2)[p3];
     else Elem = void(0);
     return(Elem);
   }
   else return void(0);
 }
 else if(MS) {
   if(p1.toLowerCase()=="id") {
     if (typeof document.all[p2] == "object")
     Elem = document.all[p2];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="tagname") {
     if (typeof document.all.tags(p2) == "object")
     Elem = document.all.tags(p2)[p3];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="name") {
     if (typeof document[p2] == "object")
     Elem = document[p2];
     else Elem = void(0);
     return(Elem);
   }
   else return void(0);
 }
 else if(NS) {
   if(p1.toLowerCase()=="id" || p1.toLowerCase()=="name") {
   if (typeof document[p2] == "object")
     Elem = document[p2];
     else Elem = void(0);
     return(Elem);
   }
   else if(p1.toLowerCase()=="index") {
    if (typeof document.layers[p2] == "object")
     Elem = document.layers[p2];
    else Elem = void(0);
     return(Elem);
   }
   else return void(0);
 }
}
function getCont(p1,p2,p3) {
   var Cont;
   if(DOM && getElem(p1,p2,p3) && getElem(p1,p2,p3).firstChild) {
     if(getElem(p1,p2,p3).firstChild.nodeType == 3)
       Cont = getElem(p1,p2,p3).firstChild.nodeValue;
     else
       Cont = "";
     return(Cont);
   }
   else if(MS && getElem(p1,p2,p3)) {
     Cont = getElem(p1,p2,p3).innerText;
     return(Cont);
   }
   else return void(0);
}
function getAttr(p1,p2,p3,p4) {
   var Attr;
   if((DOM || MS) && getElem(p1,p2,p3)) {
     Attr = getElem(p1,p2,p3).getAttribute(p4);
     return(Attr);
   }
   else if (NS && getElem(p1,p2)) {
       if (typeof getElem(p1,p2)[p3] == "object")
        Attr=getElem(p1,p2)[p3][p4]
       else
        Attr=getElem(p1,p2)[p4]
         return Attr;
       }
   else return void(0);
}
function setCont(p1,p2,p3,p4) {
   if(DOM && getElem(p1,p2,p3) && getElem(p1,p2,p3).firstChild)
     getElem(p1,p2,p3).firstChild.nodeValue = p4;
   else if(MS && getElem(p1,p2,p3))
     getElem(p1,p2,p3).innerText = p4;
   else if(NS && getElem(p1,p2,p3)) {
     getElem(p1,p2,p3).document.open();
     getElem(p1,p2,p3).document.write(p4);
     getElem(p1,p2,p3).document.close();
   }
}
DHTML_init();

var pic_count  = 8;
var pic_number = 0;
var pic_ch1 = new Image(); pic_ch1.onLoad = PicLoaded(); pic_ch1.src = "../images/chapter1.jpg";
var pic_ch2 = new Image(); pic_ch2.onLoad = PicLoaded(); pic_ch2.src = "../images/chapter2.jpg";
var pic_ch3 = new Image(); pic_ch3.onLoad = PicLoaded(); pic_ch3.src = "../images/chapter3.jpg";
var pic_ch4 = new Image(); pic_ch4.onLoad = PicLoaded(); pic_ch4.src = "../images/chapter4.jpg";
var pic_ch5 = new Image(); pic_ch5.onLoad = PicLoaded(); pic_ch5.src = "../images/chapter5.jpg";
var pic_ch6 = new Image(); pic_ch6.onLoad = PicLoaded(); pic_ch6.src = "../images/chapter6.jpg";
var pic_ch7 = new Image(); pic_ch7.onLoad = PicLoaded(); pic_ch7.src = "../images/chapter7.jpg";
var pic_log = new Image(); pic_log.onLoad = PicLoaded(); pic_log.src = "../images/logo.jpg";

var video_da = 0;
function PicLoaded() {
    pic_number++;
}

function ShowMenue() {

    if (pic_number == pic_count) {
        getElem("id", "menue", null).style.visibility = "visible";
        getElem("id", "preloader", null).style.visibility = "hidden";
    } else {
	    setTimeout("ShowMenue()", 500);
	} /**/ return;
}

// ### Kapitelwechsel ###
var currentChapter,
    newChapter,
    currentSubchapter,
    newSubchapter,
    viewportWidth,
    leftOffset,
    currentPos,
    newPos,
	menueStyle,
	footStyle,
	videoStyle,
	currentChapterStyle,
	pos,vstart,vstop,vcounter, vstep,video_da,s1,
	newChapterStyle,lastsub;

// Erster Schritt: Menue nach Links aus dem Viewport bewegen und ausblenden
function MoveMenueLeft(start, stop, step, speed){
	if (video_da > 0) {
		document.getElementById('video').style.top  = -300+"px";
		video_da = 0;
		player.sendEvent('STOP');
		document.getElementById('chap'+currentChapter).style.visibility  = "visible";
	}
  	
    if (currentChapter != 0) {
    	  if (currentChapter != 7) {
    	  		document.getElementById('ctrl'+currentChapter).style.visibility  = "hidden";
    	  }
    	  if (currentChapter == 1) {
    	  		document.getElementById('ctrl'+currentChapter).style.width="1px";
    	  }
    	  if (newChapter == 1) {
    	  		document.getElementById('ctrl'+newChapter).style.width="40px";
    	  }
        currentChapterStyle.fontWeight = "bold";				
        currentChapterStyle.color = "#0066cc";
        currentChapterStyle.fontSize = "100%";
        newChapterStyle.fontWeight = "normal";			
        newChapterStyle.color = "#ffffff";
        newChapterStyle.fontSize = "200%";
    }
    if (start >= stop){
        menueStyle.left = start+"px";
        footStyle.left = start+"px";
        start = start - step;
        setTimeout("MoveMenueLeft("+start+","+stop+","+step+","+speed+")",speed);
    } else {
        menueStyle.visibility = "hidden";
        ScrollChapter(currentPos, newPos, 20, 0, 0);
    }
    //window.status = "MoveMenueLeft ==> currentChapter: "+currentChapter+" newChapter: "+newChapter+" start: "+start+" stop: "+stop+" cPos: "+currentPos+" nPos: "+newPos;
}

// Zweiter Schritt: zum neuen Kapitel scrollen
function ScrollChapter(start, stop, time, step, direction) {
	 lastsub=0;
    if (direction == 0) {
        if (start <= stop) {
            direction = 1; // nach Rechts scrollen
            step = Math.round((stop - start) / time);
		} else {
            direction = -1; // nach Links scrollen
            step = Math.round((start - stop) / time);
		}
    }
	if (direction == -1) {
        if (start > stop) {
		    start = start - step;
    		if (start < stop) {start = stop;}
	    	    scrollTo(start,0);
		    	setTimeout("ScrollChapter("+start+","+stop+","+time+","+step+","+direction+")", time);
            } else {
			    menueStyle.visibility = "visible";
 // controle wird erst nach dem wiederreinscrollen eingeschaltet
	    if (newChapter != 7) {
	     		document.getElementById('ctrl'+newChapter).style.visibility  = "visible";
	    }
               MoveMenueRight(newPos - viewportWidth + leftOffset, newPos + leftOffset, 25, 1);
            }
    }
    if (direction == 1) {
        if (start < stop) {
		    start = start + step;
    		if (start > stop) {start = stop;}
	   		scrollTo(start,0);
	    	setTimeout("ScrollChapter("+start+","+stop+","+time+","+step+","+direction+")", time);
	    } else {
            menueStyle.visibility = "visible";	
// contole wird erst nach dem wiederreinscrollen eingeschaltet
	    if (newChapter != 7) {
	     		document.getElementById('ctrl'+newChapter).style.visibility  = "visible";
	    }

            MoveMenueRight(newPos - viewportWidth + leftOffset, newPos + leftOffset, 25, 1);
        }
    }
    //window.status = "ScrollChapter ==> currentChapter: "+currentChapter+" newChapter: "+newChapter+" start: "+start+" stop: "+stop+" cPos: "+currentPos+" nPos: "+newPos;
}

// Dritter Schritt: Menue nach rechts in den Viewport hineinscrollen
function MoveMenueRight(start, stop, step, speed){
    if (start <= stop){
        menueStyle.left = start+"px";
        footStyle.left = start+"px";
        start = start + step;
        setTimeout("MoveMenueRight("+start+","+stop+","+step+","+speed+")",speed);
    } else {
        menueStyle.left = stop+"px";
        footStyle.left = stop+"px";
        currentChapter = newChapter;
		if (currentChapter == 7) {
            getElem("id", "inp_text", null).focus();		
		
		}
    }
    //window.status = "MoveMenueRight ==> currentChapter: "+currentChapter+" newChapter: "+newChapter+" start: "+start+" stop: "+stop+" cPos: "+currentPos+" nPos: "+newPos;
}

function Chapter(chapter) {
    newChapter = chapter;
    currentPos = (currentChapter - 1) * viewportWidth;
    newPos     = (newChapter - 1) * viewportWidth;	
	currentChapterStyle = getElem("id", "nav"+currentChapter, null).style;
	newChapterStyle     = getElem("id", "nav"+newChapter, null).style;
    MoveMenueLeft(currentPos, currentPos - viewportWidth, 500, 1);
    getElem("id", "sub"+currentSubchapter, null).style.visibility  = "hidden";
    
    
}

function SubChapter(subchapter) {
    newSubchapter = subchapter;
    if (newSubchapter == currentSubchapter) {
        getElem("id", "sub"+currentSubchapter, null).style.visibility  = "hidden";
        currentSubchapter = 0;
    } else {
        getElem("id", "sub"+currentSubchapter, null).style.visibility  = "hidden";
        getElem("id", "sub"+newSubchapter, null).style.visibility  = "visible";
        currentSubchapter = subchapter;
    }
}

// ## Initialisierung ##
function Init() {
    currentChapter    = 1; newChapter    = 1;
    currentSubchapter = 0; newSubchapter = 0;
    viewportWidth  = 850; viewportHeight = 600;
    leftOffset     = 20;
	menueStyle = getElem("id", "menue", null).style;
	footStyle  = getElem("id", "foot", null).style;
    getElem("id", "nav1", null).style.fontWeight = "normal";
    getElem("id", "nav1", null).style.color = "#ffffff";
    getElem("id", "nav1", null).style.fontSize = "200%";
    //window.status = "Init ==> currentChapter: "+currentChapter+" newChapter: "+newChapter+" cPos: "+currentPos+" nPos: "+newPos;
	ShowMenue();
}
      var player = null;

      function playerReady(obj)
      {
        player = document.getElementsByName(obj.id)[0];
      };

function playVideo(chapter,dir) {
	vstart = -300;
	vstop = 190;
	vcounter = 0;
	vstep = 10;
	if (!dir) {
		moveVideoOut();
		setTimeout("waitawhile("+chapter+")",1000);
	}
	else {
		video_da = 1;
		videoposx = 267+((chapter-1)*viewportWidth);
		videoposy = vstart;
		//alert(videopos);	
		document.getElementById('video').style.left = videoposx+"px";
		document.getElementById('video').style.top = videoposy+"px";
		var s1 = new SWFObject("../video/player.swf","ply","316","237","9","#FFFFFF");
		s1.addParam("allowfullscreen","true");
		s1.addParam("allowscriptaccess","always");
		s1.addParam("flashvars","file=../video/video"+chapter+".flv&autostart=true&controlbar=over");
		s1.write("video");
		setTimeout("moveVideoIn(1,"+chapter+")",500);
	}
}

function moveVideoOut() {
	if ((vstop-(vcounter*vstep)) >=vstart){
		vcounter++;
		pos = vstop-(vcounter*vstep);
		document.getElementById('video').style.top = pos+"px";
		setTimeout("moveVideoOut()",1);
	}
}
	
	
function moveVideoIn(flag,chapter) {
	if (flag>0) {
		document.getElementById('video').style.visibility  = "visible";
	}
	if ((vstart+(vcounter*vstep)) <= vstop){
		vcounter++;
		pos = vstart+(vcounter*vstep);
		document.getElementById('video').style.top = pos+"px";
		setTimeout("moveVideoIn(0,"+chapter+")",1);
	}
	else {
		if (chapter == 1) {
			document.getElementById('chap'+chapter).style.visibility  = "hidden";
		}
		else {
			div_blende('chap'+chapter, 420, 235, 'aus');
		}
		switchofsubs();
	}
}
function waitawhile(chapter) {
	// Kapiteltext wieder anzeigen (Kapitel 1 = Bug, deshalb kein verz�gertes Ein-Ausblenden
	if (chapter == 1) {
		document.getElementById('chap'+chapter).style.visibility  = "visible";
	}
	else {
		div_blende('chap'+chapter, 420, 235, 'ein');
		// linke Seite (blaue Unterkapitel) einblenden
		if (document.getElementById('sub'+lastsub)) 
			document.getElementById('sub'+lastsub).style.visibility = "visible";
		lastsub=0;
		
	}
	document.getElementById('video').style.visibility  = "hidden";
	player.sendEvent('STOP');
	
}

/* w�hrend das video l�uft wird der Text ausgeblendet */
var reentrant = 0, h = 0, b = 0;
 function div_blende(id, breite, hoehe, aktion)
{
 if( ! reentrant ) {
    reentrant = 1;
    var move = 0, element = document.getElementById(id);
    
    if( aktion == 'ein' ) {
       if(h < hoehe ){ h += 50; move++ }
       if(b < breite){ b += 50; move++ }
       element.style.visibility = 'visible';
    }
    else if( aktion == 'aus' ) {
       if(h > 0 ){ h -= 50; move++ }
       if(b > 0 ){ b -= 50; move++ }
       element.style.visibility = (b > 0 && h > 0) ? 'visible' : 'hidden';
    }
    
    if( move ) { 
       element.style.height =  h + 'px';
       element.style.width  =  420 + 'px';
       window.setTimeout( function(){ div_blende(id,hoehe,breite,aktion) }, 20 );
    }
    reentrant = 0;
 }
}

function show (ebene,ebene2,ebene3,ebene4,ebene5) {
	if (document.getElementById('sub'+ebene).style.display=='block') {
   	document.getElementById('sub'+ebene).style.display= 'none' ;
	}
	else {
		document.getElementById('sub'+ebene).style.display= 'block' ;
		document.getElementById('sub'+ebene2).style.display= 'none' ;
		document.getElementById('sub'+ebene3).style.display= 'none' ;
		document.getElementById('sub'+ebene4).style.display= 'none' ;
		document.getElementById('sub'+ebene5).style.display= 'none' ;
	}
}

// Unterkapitel ausblenden
function switchofsubs() {
   var subs = new Array('1','11','22','2','3','4','5','6','7','224','222','223','225','221','22111','2222','2231','2232','2242','2243','22112','2214','22211','22212','22222','2231','2232','2242','2243');
   for(i=0;i<subs.length;i++) {
   	if (document.getElementById('sub'+subs[i])) { // alert(subs[i]);
			if (document.getElementById('sub'+subs[i]).style.visibility == "visible") {
				document.getElementById('sub'+subs[i]).style.visibility = "hidden";
				lastsub = subs[i];
			}
   	}
	}
}

function getXMLHTTP() { 
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
	return xmlhttp;
}
function sendForm(phpFile,filldiv) { 
	data = getString(); 
	var req = getXMLHTTP(); 
	if (req) {
		req.onreadystatechange = function()	{
		if (req.readyState == 4) { //Datenübertragung
			if (req.status == 200) { // Status ok                   
			 	document.getElementById(filldiv).innerHTML=req.responseText;
			}
			else { 
				alert('Fehler hier\n');
			}
		}            
	}        
	req.open('GET', phpFile+data, true); 
   req.setRequestHeader("Content-Type", "content-type: text/html; charset=iso-8859-1"); 
	req.send(null);
	}
}

function getString() {
	
		var outstr = '';
		var len = document.formular.elements.length;
		for(var i=0;i<len;i++) {
			if (document.formular.elements[i].type == "checkbox") {
				if(document.formular.elements[i].checked == true) {
					outstr += '&'+document.formular.elements[i].name+'='+escape(encodeURI(document.formular.elements[i].value));
				}
			}
			else {
				outstr += '&'+document.formular.elements[i].name+'='+escape(encodeURI(document.formular.elements[i].value));
			}
		}	
		return outstr;
}