/**
*	FADE 4 real-dot-ch 2007
*
*	uffizi-dot-ch
*/

var hexChars	= "0123456789ABCDEF";
var vonColor	= 0;
var bisColor	= 0;
var bg			= 'Start';

var time		= 2;
var faktor		= 2;
var neg			= -1;

/**
*	FUNC
*
*/

function Dec2Hex (Dec)
{
	if ( Dec > 255 )
	{
		hex = "ff";
	}
	else
	{
		var a = Dec % 16;
		var b = (Dec - a)/16;
		hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
	}
	return hex;
}

function setBGColor(bis)
{
	bisColor = bis;
	if (bg=='Start')
	{
		bg = "OK";
		von = 255;
		vonColor = von;
	}
	
	if (vonColor < bisColor) {
		faktor = Math.round((bisColor - vonColor)/32);
		aufZaehlen();
	} else {
		faktor = Math.round((vonColor - bisColor)/32);
		abZaehlen();
	}
}

function aufZaehlen()
{
	var diff = vonColor - bisColor;
	if (diff < 0) diff = diff*neg;
	
	if (vonColor == bisColor)
	{
		vonColor = bisColor;
	}
	else if (diff < faktor)
	{
		aendereFarbe(bisColor);
		vonColor = bisColor;
	}
	else if (vonColor < bisColor)
	{
		aendereFarbe(vonColor);
		vonColor = vonColor+faktor;
		window.setTimeout("aufZaehlen()", time);
	}
	else
	{
		aendereFarbe(vonColor);
		vonColor = vonColor-faktor;
		window.setTimeout("abZaehlen()", time);
	}
}

function abZaehlen()
{
	var diff = vonColor - bisColor;
	if (diff < 0) diff = diff*neg;

	if (vonColor == bisColor)
	{
		vonColor = bisColor;
	}
	else if (diff < faktor)
	{
		aendereFarbe(bisColor);
		vonColor = bisColor;
	}
	else if (vonColor > bisColor)
	{
		aendereFarbe(vonColor);
		vonColor = vonColor-faktor;
		window.setTimeout("abZaehlen()", time);
	}
	else
	{
		aendereFarbe(vonColor);
		vonColor = vonColor+faktor;
		window.setTimeout("aufZaehlen()", time);
	}
}

function aendereFarbe(vonColor)
{
	var bgcolor = "#" + Dec2Hex(vonColor) + Dec2Hex(vonColor) + Dec2Hex(vonColor);
	$$('.fade').each(function(el) {
		el.style.backgroundColor = bgcolor;
	});
}

/*

// var layer		= new Array("big", "user", "password", "playground", "top", "left", "news_content", "corporate_film_content", "corporate_film_content_home", "corporate_film_content_module", "methodik_content", "methodik_content_1ststep", "methodik_content_2ndstep", "methodik_content_3rdstep", "methodik_content_referenzen", "tool_content", "tool_content_beschrieb", "tool_content_lightbox", "tool_content_editbox", "kontakt_content");
// var layer		= new Array("real", "login", "menu", "bx", "cx", "cx1x", "cx1x1x", "cx1x2x", "cx1x3x", "cx1x3x1x", "cx1x3x2x", "cx1x3x3x", "cx1x3x4x", "cx1x4x", "cx2x", "cx2x1x", "cx2x2x", "cx2x3x", "cx2x4x", "dx");
// var layer		= new Array("real", "login", "menu", "bx", "cx", "cx1x", "cx1x1x", "cx1x2x", "cx1x3x", "cx1x3x1x", "cx1x3x2x", "cx1x3x3x", "cx1x4x", "cx1x4x1x", "cx1x4x2x", "cx1x4x3x", "cx2x", "cx2x1x", "cx2x2x", "cx2x3x", "cx2x4x", "dx");

function aendereFarbe(vonColor)
{
	var thecolor = "#" + Dec2Hex(vonColor) + Dec2Hex(vonColor) + Dec2Hex(vonColor);
	if (document.getElementById)
	{
		for(i=0; i < layer.length; i++)
		{
			var the_div = layer[i];
			document.getElementById(the_div).style.backgroundColor = thecolor;
		}
	}
	else if (document.all)
	{
		for(i=0; i < layer.length; i++)
		{
			var the_div = layer[i];
			document.all[the_div].style.backgroundColor = thecolor;
		}
	}
}
*/
