// genial.js
/**************************************************
        Make sure basepath is properly set!
**************************************************/

basepath = "/_downloads/uebungen/genial/genial1/";

// Retreive info about DOM support

function RetreiveDOM() {

	var browser = "unknown";
	var version = "0";
	var valid = false;

	browser_identity = window.navigator.userAgent.toLowerCase();

	if      (browser_identity.indexOf('opera')   != -1) browser = "opera";

	else if (browser_identity.indexOf('mozilla') != -1
	      && browser_identity.indexOf('opera')   == -1
	      && browser_identity.indexOf('msie')    == -1) browser = "netscape";

	else if (browser_identity.indexOf('msie')    != -1
	      && browser_identity.indexOf('opera')   == -1) browser = "iexplorer";

	switch (browser) {
		case "opera": {

			var temp = window.navigator.appVersion.split(" (");
			version = parseFloat(temp[0]);
			valid = false;                 // proper DOM not supported yet (as of v7.00b2)
		}; break;
		case "iexplorer": {

			var temp = window.navigator.appVersion.split("; ");
			var temp = temp[1].split(" ");
			version = parseFloat(temp[1]);
			valid = ((window.navigator.platform == "MacPPC" && version >  5)
			      || (window.navigator.platform != "MacPPC" && version >= 5)) ? true : false;
		}; break;
		case "netscape": {

			var temp = window.navigator.appVersion.split(" [");
			version = temp[0].substr(0,3); // not tested properly yet, but ...
			valid = false;                 // ... it doesn't support DOM in any version anyways ;)
		}; break;
		default: {

			valid = false;
		}; break;
	};

	return ( browser != "netscape"
	    && ((browser == "opera"
	    ||   browser == "iexplorer") && valid == true))
	? true : false;
}

// Open Help-Window

function Help(ub,exc) {

	window.open(
		(basepath + "src/help.html?" + "help" + ub + "_" + exc),
		("genial_online_help"),
		("menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no,location=no,top=0,left=0,width=1,height=1")
	);
}

// Open SystemPrefs Window

function SystemPrefs() {

	window.open((basepath + "src/systemprefs.html"),"systemprefs","menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no,location=no,top=0,left=0,width=1,height=1");
}

// Open UB Windows

function openUBWindow(ubnr) {
	NewWindowUB = false;
	NewWindowUB = window.open((basepath + "ub" + ubnr + "/f_uebung.html"),"Uebungen","menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no,location=no,top=0,left=0,width=700,height=560");
	NewWindowUB.moveTo(screen.width/2-350,screen.height/2-280);
}

// Open Kommentare Windows

function openKommWindow(ubnr) {
	NewWindowUB = false;
	NewWindowUB = window.open((basepath + "komm/komm" + ubnr + "/f_komm" + ubnr + ".html"),"Kommentare","menubar=no,resizable=no,status=no,toolbar=no,scrollbars=no,location=no,top=0,left=0,width=700,height=560");
	NewWindowUB.moveTo(screen.width/2-350,screen.height/2-280);
}

// Generate code for Shockwave files

function ShockwaveCode(id,tabs) {

	var tabstops = "";
	while (tabstops.length < (tabs*2)) tabstops += "\t";
	var filename = basepath + "sound/" + audio[id] + ".dcr";

	var width = 0;
	var height = 0;
	width = height = (audio[id].indexOf("tanja") == -1 && audio[id].indexOf("hoertext") == -1) ? 14 : 24;

	document.writeln(tabstops + "<OBJECT CLASSID=\"clsid:166B1BCA-3F9C-11CF-8075-444553540000\" CODEBASE=\"http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0\" ID=\"" + audio[id].substr(5,audio[id].length) + "\" WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\">");
	document.writeln(tabstops + "\t<PARAM NAME=\"src\" VALUE=\"" + filename + "\">");
	document.writeln(tabstops + "\t<PARAM NAME=\"swRemote\" VALUE=\"swSaveEnabled='false' swVolume='false' swRestart='false' swPausePlay='false' swFastForward='false' swContextMenu='true'\">");
	document.writeln(tabstops + "\t<PARAM NAME=\"swStretchStyle\" VALUE=\"none\">");
	document.writeln(tabstops + "\t<PARAM NAME=\"bgColor\" VALUE=\"#ffdead\">");
	document.writeln(tabstops + "\t<PARAM NAME=\"progress\" VALUE=\"false\">");
	document.writeln(tabstops + "\t<PARAM NAME=\"logo\" VALUE=\"false\">\n");
	document.writeln(tabstops + "\t<EMBED SRC=\"" + filename + "\" BGCOLOR=\"#ffdead\" PROGRESS=\"false\" LOGO=\"false\" WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\" swRemote=\"swSaveEnabled='false' swVolume='false' swRestart='false' swPausePlay='false' swFastForward='false' swContextMenu='true'\" swStretchStyle=\"none\" TYPE=\"application/x-director\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/\">");
	document.writeln(tabstops + "</OBJECT>");
}

// Swap English / German instructions

function SwapDeEn(ub,exc,width,height) {

	mouse_in = (mouse_in) ? false : true;

	var path = basepath + "ub" + ub + "/img/";
	var file = "";

		file  = "aufg" + parseInt(exc.substring(0,2));
	if (exc.length > 2)
		file += exc.substring(2,exc.length);
	if (mouse_in)
		file += "e";
	        file += ".gif";

	var newimage = new Image(width,height);
	newimage.src = path + file;	

	var id = "ub" + ub + exc;

	var ptr = (DOM) ? document.getElementById(id) : document.images[id];
	ptr.src = newimage.src;
}

// Simple version

function Swap(id) {

	if (id.substring(0,2) == "ub") id = id.substring(2,id.length);

	var ub  = id.substring(0,2);
	var exc = id.substring(2,id.length);

	SwapDeEn(ub,exc,460,37);
}
