// Project: Switch, meine wunderschoenen Schalter
// (C) Johannes A. Norz, all code is available under the terms of the GNU Free Documentation License.
// coded in Java Script by Johannes A. Norz (http://www.norz.at) december 2008
// costumer: Prof. DI Heimo Müller


// =======================
function lDimmed () {
	// is the navigation frame dimmed?
	// (right frame only gets dimmed if left frame is allready dimmed)
	// I just got to check it's background color: f0ecec means lit
	
	if (parent.Navigation.document.body.getAttribute ("bgColor") == "#f0ecec") 
		return false;
	else
		return true;
	}

// =======================
function dimmDaten ()	{
	// dimm right frame
	// most if the dimming work is done in subroutines

	var cURL = "";
	var cBild = "";
	
	if (lDimmed ())	{
		SetAttributesDimmed (parent.Daten.document.body);
		cURL = "images/dimmed";
	}	else	{
		SetAttributesUnDimmed (parent.Daten.document.body);
		cURL = "images/lit";
	}

	//	dimm pics in data area
	for (var i=0; i < parent.Daten.document.getElementsByTagName ("img").length; i++)	{	
		cBild = parent.Daten.document.getElementsByTagName ("img")[i].getAttribute ("src");
		cBild = cBild.slice(cBild.lastIndexOf("/"), cBild.length);
		cBild = parent.Daten.document.getElementsByTagName ("img")[i].setAttribute ("src", cURL + cBild);
	}
}

// =======================
function dimm () {
	// dimm a page. no parameters

	var cURL = "";
		var cBild = "";

	// dimm Navigation area
	if (lDimmed ()) {
		// currently: dimmed
		// undimm pages
		SetAttributesUnDimmed (parent.Navigation.document.body);
		dimmDaten(true);
		cURL = "images/lit";
		//and change the hint in navigation frame's switch (what a pitty, it will only be seen in Micky$oft's internetexploder ...)
		parent.Navigation.document.getElementsByTagName ("img")[0].setAttribute ("alt", "No colors anymore I want them to turn black / I see the switches pass by dressed in their summer clothes / I have to turn my head until my darkness goes");
	}	else	{
		// currently: undimmed
		SetAttributesDimmed (parent.Navigation.document.body);
		dimmDaten(false);
		cURL = "images/dimmed";	
		
		//and change the hint in navigation frame's switch (what a pitty, it will only be seen in Micky$oft's internetexploder ...)
		parent.Navigation.document.getElementsByTagName ("img")[0].setAttribute ("alt", "... let the sunshine in!");
	}

	//	dimm Pics in Navigation area (Table background)
	cBild = parent.Navigation.document.getElementsByTagName ("table")[0].getAttribute ("background");
	cBild= cBild.slice(cBild.lastIndexOf("/"), cBild.length);
	parent.Navigation.document.getElementsByTagName ("table")[0].setAttribute ("background", cURL + cBild);
	
}

// =======================
function SetAttributesDimmed (oSeite)	{
	// dimm a page.
	// oSeite is current page's document.body object
	
	oSeite.bgColor = "#262424";
	oSeite.text = "#232121";
	oSeite.fgColor = "#232121";
	oSeite.link = "#232121";
	oSeite.vLink = "#232121";
	oSeite.aLink = "#232121";
	
	// change these pics
	var cURL = "images/dimmed";
	for (var i=0; i < oSeite.getElementsByTagName ("img").length; i++)	{	
		cBild = oSeite.getElementsByTagName ("img")[i].getAttribute ("src");
		cBild = cBild.slice(cBild.lastIndexOf("/"), cBild.length);
		cBild = oSeite.getElementsByTagName ("img")[i].setAttribute ("src", cURL + cBild);
	}
}

// =======================
function SetAttributesUnDimmed (oSeite)	{
	// undimm a page.
	// oSeite is current page's document.body object
	
	oSeite.bgColor = "#f0ecec";
	oSeite.text = "#000000";
	oSeite.link = "#a00000";
	oSeite.vLink = "#600000";
	oSeite.aLink = "#232121";
	
	// change pics
	for (var i=0; i < oSeite.getElementsByTagName ("img").length; i++)	{	
		cBild = oSeite.getElementsByTagName ("img")[i].getAttribute ("src");
		cBild = cBild.slice(cBild.lastIndexOf("/"), cBild.length);
		cBild = oSeite.getElementsByTagName ("img")[i].setAttribute ("src", "images/lit" + cBild);
	}
}

// =======================
function dimPage ()	{
	// dimm current page (called by register frame on 1st load)
	SetAttributesDimmed (document.body);
	dimmDaten ();
}
