var first_load = 1;

var current_style = 0;

var divsloaded = 0;



function byId(name)

{

	if(document.getElementById(name) !== null)

		return document.getElementById(name);

	else

		return null;

}



function init()

{

	//alert(navigator.appVersion);

	var browser = navigator.appVersion;

	var safaritest = browser.search(/Safari/);

	if (safaritest != -1)

	{

		alert("This website is not optimized for the 'Safari' browser. Please choose a different browser like 'Firefox'!");

		top.location.href = 'http://www.mozilla-europe.org/de/products/firefox/';

	}

	

	byId("main").style.visibility = "hidden";

	divsloaded = 1;

	styles = new Array("comic", "classic", "modern");

	

	random = getRandomInt(3);

	

	document.getElementsByTagName('body')[0].scroll = "no";

	

	if(navigator.appName == "Opera")

		setStyle("classic");

	else

		setStyle(styles[random]);

		 

	setDivSize();

	

	byId("cstyle").style.textDecoration = "blink";		

	byId("addinfo").style.visibility = "visible";

	byId("styleguide").style.visibility = "visible";

	byId("main").style.visibility = "visible";

				

	setTimeout("stopBlink()", 5000);

}



function changeColor(target, color)

{

	if(typeof(target) == "string")

		target = document.getElementById(target);

	

	target.style.color = color;

}



function getWindowWidth()

{

	var width = "0";

	

	if (self.innerWidth) 

		width = self.innerWidth;

	else if (document.documentElement && document.documentElement.clientWidth)

		width = document.documentElement.clientWidth;

	else if (document.body)

		width = document.body.clientWidth;

	  

	return width;

}



function getWindowHeight()

{

	var height = "0";

	

	if (self.innerHeight) 

		height = self.innerHeight; 

	else if (document.documentElement && document.documentElement.clientHeight)

		height = document.documentElement.clientHeight; 

	else if (document.body)

		height = document.body.clientHeight;

	  

	return height;

}



function setWindowWidth(width)

{

	if (self.innerWidth) 

		self.innerWidth = width;

	else if (document.documentElement && document.documentElement.clientWidth)

		document.documentElement.clientWidth = width;

	else if (document.body)

		document.body.clientWidth = width;				

}



function setDivSize()

{

	if(divsloaded == 1)

	{

		var width = getWindowWidth();

		var height = getWindowHeight();

		

		if(width < 777 || height < 333)

		{

			window.moveTo(0, 0);
			
			alert("Minimum size reached! Switching back.");

			window.resizeTo(800, 600);

		}

		

		width = ( width - 702 ) / 2;

	

		if(current_style == "classic")

			height = height - 173;

		else

			height = height - 223;

		

		byId("left").style.width = width + "px";

		byId("shadow-navi").style.width = width + "px";

		byId("shadow-bottom").style.height = height + "px";

		byId("contentbox").style.height = height + "px";	

		byId("styleguide").style.left = (getWindowWidth()/2) - 75 + "px";

	

		byId("addinfo").style.left = getWindowWidth()/2-379 + "px";

		byId("addinfo").style.top = getWindowHeight()-91 + "px";

	}	

}



function openStyleGuid(top)

{

	if(typeof(top) == "string")

	{

		if(top.indexOf("px") != -1)

		{

			top = top.split("px");

			top = top[0];

		}

	}

	

	if(top <= -10)

	{

		byId("styleguide").style.top = top +"px";

		top++;

		setTimeout("openStyleGuid("+top+")", 10);

	}

}



function closeStyleGuid(top)

{

	if(typeof(top) == "string")

	{

		if(top.indexOf("px") != -1)

		{

			top = top.split("px");

			top = top[0];

		}

	}	

	

	if(top >= -50)

	{

		byId("styleguide").style.top = top +"px";

		top--;

		setTimeout("closeStyleGuid("+top+")", 10);

	}

}





function setStyle(style)

{

	var styles = document.getElementsByTagName('style');

	current_style = style;

	

	for(var i = 1; i < (styles.length); i++) 

	{

  		if(styles[i].getAttribute("title") == style) 

   			styles[i].disabled = false;

  		else

      		styles[i].disabled = true;

	}

	

	ajaxRequest(style, "navi");	

	byId("cstyle").innerHTML = style;

	setDivSize();

	

}



function stopBlink()

{

	byId("cstyle").style.textDecoration = "none";

}



function getRandomInt(limit)

{

	var a = 0;

	a = Math.random();

	a *= limit;

	a = Math.floor(a);



	return a * 1;

}





function showTip()

{

	var tips = "When all else fails, read the instructions. ;-)Any attempt to print Murphy's laws will jam the printer. ;-)New systems generate new problems. ;-)A failure will not appear till a unit has passed final inspection. ;-)Any given program, when running, is obsolete. ;-)The faster a computer is, the faster it will reach a crashed state. ;-)Any sufficiently advanced technology is indistinguishable from magic. ;-)All great discoveries are made by mistake. ;-)Always draw your curves, then plot your reading. ;-)Any instrument when dropped will roll into the least accessible corner. ;-)Nothing is as easy as it looks. ;-)Everything takes longer than you think. ;-)It is impossible to make anything foolproof because fools are so ingenious. ;-)Left to themselves, things tend to go from bad to worse. ;-)If everything seems to be going well, you have obviously overlooked something. ;-)If it's not in the computer, it doesn't exist. ;-)Every solution breeds new problems. ;-)You never run out of things that can go wrong. ;-)If a program is useless, it will have to be documented. ;-)Any program will expand to fill available memory. ;-)The value of a program is proportional to the weight of its output. ;-)Any non-trivial program contains at least one bug. ;-)Undetectable errors are infinite in variety, in contrast to detectable errors, which by definition are limited. ;-)Paper is always strongest at the perforations. ;-)Experiments should be reproducible. They should all fail in the same way. ;-)Do not believe in miracles. Rely on them. ;-)Machines should work. People should think. ;-)";

	tips = tips.split(";-)");

	

	random = getRandomInt(27);

	

	var object = document.getElementById("tip");

	object.innerHTML = tips[random] + " ;-)";

	object.style.visibility = "visible";

	object.style.left = getWindowWidth()/2 + "px";

	

	if(current_style == "comic")

		object.style.top = "475px";

	else if((current_style == "classic"))

		object.style.top = "400px";

	else

		object.style.top = "450px";

}



function hideTip()

{

	var object = document.getElementById("tip");

	object.style.visibility = "hidden";	

}



function showInfo()

{

	byId('info').style.visibility = 'visible';

	byId('info').style.left =  getWindowWidth()/2-150 + "px";

	byId('info').style.top =  "50px";

}



function hideInfo()

{

	byId('info').style.visibility = 'hidden';

	byId('info').style.left = "0px";

	byId('info').style.top =  "10000px";

}



/*

function setShadow(style)

{

	black = new Array('#686868', '#757575', '#858585', '#969696', '#a9a9a9', '#bababa', '#cacaca', '#d7d7d7', '#e3e3e3', '#ececec', '#f4f4f4', '#f4f4f4', '#FFFFFF');

	orange = new Array('#68300e', '#753610', '#853e12', '#964515', '#a94e17', '#ba561a;', '#ca5d1c', '#d7631e', '#e3691f', '#ec6d20', '#f47121', '#f47121', '#ff7623');

	none = new Array('FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF', '#FFFFFF');

	

	//top = new Array();

	//middle = new Array();

	//bottom = new Array();

	

	if(style == "comic")

	{

		var top = black;

		var middle = orange;

		var bottom = black;

	}

	else if(style == "modern")

	{

		var top = black;

		var middle = black;

		var bottom = black;		

	}

	else

	{

		var top = none;

		var middle = none;

		var bottom = none;			

	}

	

	var html = "";



	html += "<div style='height: 100px; clear: both; background-color: "+ top[12] +"'>";	

	for(i = 0; i < 12; i++)

	{

		html += "	<div style='height: 100px; width: 1px; background-color: "+ top[i] +"; float: left;'></div>";	

	}

	html += "	<div style='clear: both'></div>	";			

	html += "</div>";

	

	html += "<div style='height: 150px; clear: both; background-color: "+ middle[12] +"'>";	

	for(i = 0; i < 12; i++)

	{

		html += "	<div style='height: 150px; width: 1px; background-color: "+ middle[i] +"; float: left;'></div>";	

	}

	html += "	<div id='rightshadow' style='height: 150px; background-color: "+ middle[i+1] +"; float: left;'>";

	html += "	<div style='clear: both'></div>	";			

	html += "</div>";

	

	html += "<div id='shadow' style='clear: both; background-color: "+ bottom[12] +"'>";	

	for(i = 0; i < 12; i++)

	{

		html += "	<div style='height: 100%; width: 1px; background-color: "+ bottom[i] +"; float: left;'></div>";	

	}

	html += "	<div style='clear: both'></div>	";			

	html += "</div>";

	

	

	document.getElementById("right").innerHTML = html;

	

	setTimeout("setDivSize()", 1);



}

*/

