// SCRIPTS FOR MAIN PAGES
// Feel free to use (and optimise :-)) them, please mention http://tomber.de
 
 		// Some global variables
		var longWait = 10000 // wait some time before starting the header dynamics again
		,	startH1 = false	// to synchronise H1 & H2 dynamics
		,	startH2 = false	// to synchronise H1 & H2 dynamics
			
			// Tom's passage to... header text
		,	count = 28 	// color counter, initial setting according to value in CSS
		,	up = true	// direction of count
		,	counterH2 = 0 		// counter to change each character of H2 text (actually land3 id)
			
			// Character highlight (e.g. Header2 text)
		,	spanID = "charHigh"	// needed to generate individual IDs for each character
		, 	spanLength			// length of text for which span & IDs are generated
			
			// Header1 text
		,	size = 3.5			// inital font size
		,	sizeUnit = "pc"		// 
		,	sizeSpeed = 10		// speed of change
		,	sizeStep = 0.01		// increase/decrease font size by
		,	sizeMin = size		// minimal font size
		,	sizeMax = 4			// maximal font size
		,	sizeUp = true	
		;   // end init Global

//		*** FUNCTIONS ***
//
//		***

		function checkJS() {
			document.getElementById("js").innerHTML = "";
			return true;
		} // end checkJS()

//		***
//
// 		scripts for images & image dynamics ***		

		function preloadImages(_img) {
			var imagePreload = new Image(); 
			imagePreload.src = _img; 
			return true;
		} // end preloadImage()

//		***

		function changeImage(_id, _imgSource) {
			document.getElementById(_id).src = _imgSource;
			return true;
		} // end changeImages()

// 		END scripts for image dynamics ***
//		
//		***
//
// 		scripts for header dynamics ***

		function changeColorText() {
			// function changes the gray value in 32 steps
			var tempColor1 = "" // influenced directly by the counter
			,	tempColor2 = "" // D or E
			,	count2 = 0		// needed for counted values above 15
			,	newColor = ""	// as name indicates
			,	speed = 150 	// speed of change			
			;

			if (up) count += 1; 
			if (!up) count -= 1;
			if (count >= 31) up = false; 	// count down
			if (count <= 0) up = true;		// count up

			tempColor2 = "D"; 			// initial setting
			count2 = count;				// initial setting
			if (count >= 16) {
				tempColor2 = "E"; 		// correction of initial setting
				count2 = count - 16; 	// correction of initial setting
			};
			tempColor1 = count2;
										// conversion to hex values
			if (tempColor1 == 10) tempColor1 = "A";
			if (tempColor1 == 11) tempColor1 = "B";
			if (tempColor1 == 12) tempColor1 = "C";
			if (tempColor1 == 13) tempColor1 = "D";
			if (tempColor1 == 14) tempColor1 = "E";
			if (tempColor1 == 15) tempColor1 = "F";

										// stitching the new color hex value
			newColor = "#" + tempColor2 + tempColor1 + tempColor2 + tempColor1 + tempColor2 + tempColor1;

			document.getElementById("land1").style.color = newColor;
			document.getElementById("land1s").style.color = newColor;
			document.getElementById("land1ss").style.color = newColor;
			
										// recall the function
			setTimeout("changeColorText()", speed);

			return true;
		} // end changeColorText()

//		***
		
		function initCharHighlight(_id, _text) { 
		// needed to generate the span & ID for each character
			var effectText = ""
			,	i // counter
			;

			for (i=0; i<_text.length; i++) 
				effectText += "<span id='" + spanID + i + "'>" + _text.charAt(i) + "</span>";
			spanLength = _text.length; 
			document.getElementById(_id).innerHTML = effectText; // browser needs time for innerHTML 
																// (no problem here, first H1 dyna will be executed) 
			return true;
		} // end initCharHighlight()

//		***
		
		function changeH2()	{ 
		// accesses the generated span & ID to change style attributes
			var getIdNew
			, 	getIdOld
			, 	getIdOne
			, 	speed = 75 // speed of effect
			; // end var decl

			getIdOne = spanID + 0;
			getIdNew = spanID + counterH2;
			getIdOld = spanID + (counterH2 - 1);
			
			
			if (counterH2 > 0 && counterH2 <= spanLength) // set attribute back
				document.getElementById(getIdOld).style.fontWeight = "normal"; 
			
			if (counterH2 < spanLength) // set new attribute
			{
				document.getElementById(getIdNew).style.fontWeight = "bold"; 
				counterH2 += 1; // next character
				setTimeout("changeH2()", speed);
			}
			else if (counterH2 >= spanLength) // last character
			{
				counterH2 = 0; 		// reset char counter
				startH1 = true; 	// after H2 dynamics, H1 dynamics again
				setTimeout("synchronise()", longWait);  // start H1 dynamics after some time
			};

			return true;
		} // end changeH2()

//		***

		function changeH1()	{ 
		// H1 text size change
			var newSize = ""
			,	turn = false
			;
			
			if (sizeUp)  size += sizeStep;
			if (!sizeUp) size -= sizeStep;

					// change of direction, one turn consists of increase & decrease size			
			if (size >= sizeMax) { sizeUp = false; };
			if (size <= sizeMin) { sizeUp = true; turn = true; }; // new turn

					// setting the new size			
			newSize = size + sizeUnit;
			document.getElementById("land2").style.fontSize = newSize; 

					// recall the function
			if (turn) {
				startH2 = true;
				synchronise();	// H1 turn finished, hence start H2 dynamics 
			}
			else setTimeout("changeH1()", sizeSpeed); // H1 turn not finished
						
			return true;
		} // end changeH1()

//		***

		function synchronise() {
		// to synchronise the H1 & H2 dynamics
			if (startH1) { startH1 = false; changeH1(); };
			if (startH2) { startH2 = false; changeH2(); };
			return true;
		} // end synchronise()

// 		END scripts for header dynamics ***
//
//		***
//
// *** END SCRIPTS FOR  MAIN PAGES ***
