var xmlHttp, sideWidth, sideHeight, jump2Menu, opened, wait, fullviewcopy;

function startup(){

	measure();
	
}

function closeAll(){
	
	document.getElementById("whitecontent").innerHTML = "";
	document.getElementById("blackcontent").innerHTML = "";
	document.getElementById("imgWhite").style.display = "none";
	document.getElementById("imgBlack").style.display = "none";
	
	
}


function show(file,ext){
	
	if( !ext ) ext = 'html';
	emptyContent();
	
	doXML();
	if(xmlHttp){
		xmlHttp.open('GET', '/'+file+'.'+ext+'?raw=1' , true);
		xmlHttp.onreadystatechange = function() {
			
			if (xmlHttp.readyState == 4 ) {
				
				document.getElementById("imgWhite").style.display = "none";
				document.getElementById("imgBlack").style.display = "none";
				
				document.getElementById("content").className = file;
				document.getElementById("content").innerHTML = xmlHttp.responseText;
				
				if( file != 'menu'  ){
					jump2Menu = document.createElement("div");
					jump2Menu.innerHTML = "<a href='menu.html' onclick='return show(\"menu\");'>&Uuml;bersicht // Summary</a>";
					jump2Menu.className = "jump2Menu";
					document.getElementById("content").appendChild(jump2Menu);
				}
				
				xmlHttp = null;					
			}
		};
		xmlHttp.send(null);
		return false;
	}
	
	
}

function emptyContent(){
	document.getElementById("whitecontent").innerHTML = "";
	document.getElementById("blackcontent").innerHTML = "";
	document.getElementById("content").className = null;
	document.getElementById("content").innerHTML = "";
}

function wait(){
	
	document.getElementById("wait").style.display = "block";
		
}

function goon(){
	
	document.getElementById("wait").style.display = "none";
		
}

function project(id){
	
	emptyContent();
	wait();
	
	doXML();
	if(xmlHttp){
		xmlHttp.open('GET', '/works.php?xml=true&pid='+id+'&w='+sideWidth+'&h='+sideHeight , true);
		xmlHttp.onreadystatechange = function () {
			
			if (xmlHttp.readyState == 4 ) {
				
				goon();
				if( xmlHttp.responseText != "" ){
					var text = xmlHttp.responseText.split("|||");
					document.getElementById("whitecontent").innerHTML = text[0];
					document.getElementById("blackcontent").innerHTML = text[1];
					text = null;
				}
				xmlHttp = null;					
			}
		};
		xmlHttp.send(null);
		return false;
	}
	
	
}

function work(id){
	
	emptyContent();
	wait();
	
	doXML();
	if(xmlHttp){
		xmlHttp.open('GET', '/works.php?xml=true&id='+id+'&w='+sideWidth+'&h='+sideHeight , true);
		xmlHttp.onreadystatechange = function () {
			
			if (xmlHttp.readyState == 4 ) {
				
				goon();
				if( xmlHttp.responseText != "" ){
					var text = xmlHttp.responseText.split("|||");
					document.getElementById("whitecontent").innerHTML = text[0];
					document.getElementById("blackcontent").innerHTML = text[1];
					text = null;
				}
				xmlHttp = null;					
			}
		};
		xmlHttp.send(null);
		return false;
	}
	
	
}

function fullview(id,col,gif){
	
	if( gif != null ){
		document.getElementById('fullimg').src = "/res/"+gif;
	} else {
		gif = "";
		document.getElementById('fullimg').src = "/img.php?size=large&gif="+gif+"&id="+id;
	}
	document.getElementById("all").style.display = "none";
	document.getElementById('body').className = col;
	document.getElementById('fullview').style.display = "block";
	return false;
}

function movie(file,type,name,width,height,col){
	
	fullviewcopy = document.getElementById('fullview').innerHTML;
	var html;
	if( ! width ) width = 320;
	if( ! height ) height = 250;
	
	if( type == 'mov' ){
		
		html = '<embed src="/res/'+file+'" Pluginspage="http://www.apple.com/quicktime/" width="'+width+'" height="'+height+'" controller="true" loop="false" autoplay="false" name="'+name+'"></embed>';
		
	} else if( type == 'swf' ){
		
		html = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
		+ 'WIDTH="'+width+'" HEIGHT="'+height+'"'
		+ 'CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">'
		+ '<PARAM NAME="MOVIE" VALUE="/res/'+file+'">'
		+ '<PARAM NAME="PLAY" VALUE="false">'
		+ '<PARAM NAME="QUALITY" VALUE="best">'
		+ '<PARAM NAME="LOOP" VALUE="false">'
		+ '<EMBED SRC="/res/'+file+'" WIDTH="'+width+'" HEIGHT="'+height+'" PLAY="false" LOOP="false" QUALITY="best"'
		+ 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' 
		+ '</EMBED>'
		+ '</OBJECT>';
		
	} else {
		
		/* Windows Media Player */
		html = '<object id="player" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"' 
		+ 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"'
		+ 'standby="Loading Windows Media Player components..." type="application/x-oleobject" width="'+width+'" height="'+height+'">'
		+ '<param name="fileName" value="/res/'+file+'">'
		+ '<param name="animationatStart" value="true">'
		+ '<param name="transparentatStart" value="true">'
		+ '<param name="autoStart" value="true">'
		+ '<param name="showControls" value="false">'
		+ '<param name="Volume" value="-450">'
		+ '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="/res/'+file+'" name="player"'
		+ 'width='+width+' height='+height+' autostart=1 showcontrols=0 volume=-450>'
		+ '</object>';
		
		/* QT 
		html = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+height+'" width="'+width+'" name="player" align="center">'
		+ '<param name="src" value="/res/'+file+'">'
        + '<param name="autoplay" value="true">'
        + '<param name="controller" value="true">'
        + '<embed height="'+height+'" width="'+width+'" align="center" src="/res/'+file+'" autoplay="false" controller="true">'
        + '</embed>'
        + '</object>';
		*/
		
	}
	document.getElementById('fullview').innerHTML = html+'<br /><a href="#" onclick="return closeMovie();">schlie&szlig;en</a>';
	
	document.getElementById("all").style.display = "none";
	document.getElementById('body').className = col;
	document.getElementById('fullview').style.display = "block";
	return false;

}

function closeFullview(){
	
	document.getElementById('fullimg').src = null;
	document.getElementById('body').className = null;
	document.getElementById('fullview').style.display = "none";
	document.getElementById("all").style.display = "block";
	return false;
}

function closeMovie(){
	
	document.getElementById('fullview').innerHTML = fullviewcopy;
	fullviewcopy = null;
	document.getElementById('body').className = null;
	document.getElementById('fullview').style.display = "none";
	document.getElementById("all").style.display = "table";
	return false;
}

function measure(){
	sideWidth = document.getElementById("whiteside").offsetWidth;
	sideHeight = document.getElementById("whiteside").offsetHeight;
}

function doXML(){
	
	if( xmlHttp == null ){
		try {
			// Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			try {
				// MS Internet Explorer (ab v6)
				xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				try {
					// MS Internet Explorer (ab v5)
					xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					xmlHttp  = null;
				}
			}
		}
	}
	
}

