/*
	Javascript File für Eurener Hof, http://www.eurener-hof.de/
	27 März 2006
	Daan Meskers, Bob-design.de
*/

var msie, moz, safari
if ( document.all && !window.opera ) {
	msie = true
	writeCSS( "ie.eurener-hof.css" );
	if ( navigator.userAgent.indexOf( "MSIE 6" )> 0 ){
		msie = 6; writeCSS( "ie6.eurener-hof.css" );
	}
} else if ( navigator.userAgent.toLowerCase().indexOf( "khtml" )> 0 ) {
	safari = true; writeCSS( "khtml.eurener-hof.css" );
}
if ( getCookie("marginLeftLi") > 0 ) {
	document.write('<style type="text/css">');
	if (msie) document.write('UL#header { padding-left: '+(parseInt(getCookie("marginLeftLi"),10)+15)+'px;}');
	else {
		document.write('UL#header LI:first-child {margin-left:'+(parseInt(getCookie("marginLeftLi"),10)+10)+'px !important;}');
	}
	document.write('</style>');
}

function writeCSS( myurl ) {
	document.write('<link href="fileadmin/templates/lib/css/'+myurl+'" rel="stylesheet" title="CSS Stylesheet">');
}

function hi( elm ) {
	elm.onmouseout = low
	elm = elm.childNodes[0]
	elm.src = elm.src.substring( 0, elm.src.length - 7 )+"on.gif"
} 
function low() {
	elm = this.childNodes[0]
	elm.src = elm.src.substring( 0, elm.src.length - 6 )+"off.gif"
}

/* ================ init ======================== */
function goFirstPage() {
	if ( window.location.href.indexOf(".de/en")>0 ) {
		window.location = "/en/history.html"
		return false;
	}
}

/* ================ init ======================== */
window.onload = function() {
	buildWindow()
}
window.onresize = function() {
	buildWindow()
}
function buildWindow() {
	var myUL = document.getElementById('header')
	var myULs = ( myUL.childNodes ) ? myUL.childNodes : myUL.children
	var LeftLi, marginLeftLi = 0
	for ( var i=0; myULs.length > i; i++ ) {
		myLi = myULs[i]
		if ( !LeftLi && myLi.style ) { myLi.style.marginLeft = "2px" ; LeftLi = myLi }
		if ( myLi.offsetWidth > 0 ) { // && myLi.className.indexOf("Birdy")<0 
			marginLeftLi += myLi.offsetWidth +  10 
		}
		if ( myLi.className.indexOf("Birdy") > -1 && Math.random() > 0.5 ) {
			img = (myLi.childNodes[1] && myLi.childNodes[1].src ) ? myLi.childNodes[1] : myLi.childNodes[0]
			img.src = "/fileadmin/templates/img/layout/birdy2.gif"
		}
	}
	var cookieInt = parseInt( getCookie("marginLeftLi"), 10 )
	if ( LeftLi && marginLeftLi > 0 && ( isNaN(cookieInt) || marginLeftLi+5 < cookieInt || marginLeftLi-5 > cookieInt )) {
		if ( msie == 6 ) marginLeftLi = marginLeftLi / 0.9
		if ( safari ) marginLeftLi = 965 // || msie
		else 
			marginLeftLi = 945
		newLI = Math.max( -15, Math.ceil((getWidth()-marginLeftLi)/2)+5)
		LeftLi.style.marginLeft = newLI+"px"
		setCookie("marginLeftLi",newLI,365)
		if ( msie )	myUL.style.paddingLeft = "15px"
			
	}
}
/* ============= lib ================== */
function getHeight() {
	if ( window.innerHeight ) return window.innerHeight 
	if ( document.documentElement ) return document.documentElement.clientHeight
	if ( document.body ) return document.body.clientHeight
	else return 700;
}
function getWidth() {
	if ( window.innerWidth ) return window.innerWidth 
	if ( document.documentElement ) return document.documentElement.offsetWidth 
	if ( document.body ) return document.body.offsetWidth
	else return 800;
}

// ============ Cookie LIB  ============ 
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) return null;
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
