// # Fading-Animation-System # //

// This script is part of Zetaneon.

// Allows you to put fading effects on HTML structures

// Examples
//# fadeElement("example", true, 0, 0.125, 50, alert(true));
//# fadeElement("example", false, 1, 0.5, 120, nextFunction());

// Parameters

	// str_id:         Target ID
	// bol_direction:  true for fade in, false for fade out
	// int_value:      Value of opacity at the beginning and during the process
	// int_by:         Value to increase or descrease opacity
	// int_speed:      Value of Animation Speed between single fading actions in ms
	// str_exit:       A function to be called after the fading


	function fadeElement(str_id, bol_direction, int_value, int_by, int_speed, str_exit) {

		if (bol_direction) { // Fade in
		
			if (int_value < (1 + int_by)) {
			
				// Set opacity (with IE debug)
				if (checkBrowserName("MSIE")) { 
					document.getElementById(str_id).style.filter = "Alpha(opacity=" + int_value * 100 + ")";
				}
				else {
					document.getElementById(str_id).style.opacity = int_value;
				}
				
				// Increase opacity value for next step
				int_value += int_by;
				
				// Round to the exactly number (debug)
				int_value *= 100;
				int_value = Math.round(int_value);
				int_value /= 100;
				
				// Next step of Animation
				window.setTimeout('fadeElement("' + str_id + '", true, ' + int_value + ', ' + int_by + ', ' + int_speed + ', "' + str_exit + '")', int_speed);
			
			}
			
			else {
				// Execute the exit function
				eval(str_exit);
			}
		
		}
		
		else { // Fade out

			if (int_value > (0 - int_by)) {
			
				// Set opacity (with IE debug)
				if (checkBrowserName("MSIE")) { 
					document.getElementById(str_id).style.filter = "Alpha(opacity=" + int_value * 100 + ")";
				}
				else {
					document.getElementById(str_id).style.opacity = int_value;
				}
				
				// Decrease opacity value for next step
				int_value -= int_by;
				
				// Round to the exactly number (debug)
				int_value *= 100;
				int_value = Math.round(int_value);
				int_value /= 100;
				
				// Next step of Animation
				window.setTimeout('fadeElement("' + str_id + '", false, ' + int_value + ', ' + int_by + ', ' + int_speed + ', "' + str_exit + '")', int_speed);
			
			}
			
			else {
				// Execute the exit function
				eval(str_exit);
			}
		
		}
	
	}
	
	
// Macht ein Element sofort sichtbar oder unsichtbar über opacity Werte
	function fadeNow(sID, iTo) {
		if (sID != "") {
			switch(iTo) {
				case 1:
					fadeElement(sID, 1, 0, 1, 1, "");
					break;
				case 0:
					fadeElement(sID, 0, 1, 1, 1, "");
					break;
				default:
					if (checkBrowserName("MSIE")) document.getElementById(sID).style.filter = "Alpha(opacity=" + iTo * 100 + ")";
					else document.getElementById(sID).style.opacity = iTo;
					break;
			}
			/*
			// Einblenden
			if (bState) {
				fadeElement(sID, 1, 0, 1, 1, "");
			}
			// Ausblenden
			else {
				fadeElement(sID, 0, 1, 1, 1, "");
			}*/
		}
		else return false;
	}
