/*
	IMAGION AG Website: 
	BOB Design http://www.bob-design.de/
	Imagion AG http://www.imagion.de/
	Javascript Datei
	29.11.2006 Daan Meskers
	$last_change: 29.11.2006 Daan Meskers
*/


function hi( elm )
{
	elm = findParent( elm )
	if( elm = findChild( elm, "UL" ) ) 
	{
		hideSubmenu( findParent( elm ) )
		elm.style.display = "block"
		elm.onmouseover = function(){ clearTimeout( timer ) }
		elm.parentNode.onmouseout = function(){ low( this ) }
		findChild ( findParent( elm ), "A" ).className = "myhover"
		createShadow( findParent( elm ) )
		if ( mozilla ) {
			var myA = findChild ( findParent( elm ), "A" )
			var splash = document.getElementById( 'splash' )
			var myNav = document.getElementById( 'Navigator' )
			var myPort = document.getElementById( 'Portfolio' )
			if ( !splash && myA.href.indexOf( "format" ) > 0 && myNav && myNav.className.indexOf( "rightbox" )>-1 ) {
				findChild ( myNav, "EMBED" ).setAttribute( "wmode", "opaque")
				myNav.setAttribute( "class", "rightbox navigatorswf hideMe" )
			} else if ( !khtml && !splash && myA.href.indexOf("portfolio")>0 && myNav && myNav.className.indexOf("rightbox")>-1) {
				findChild ( myNav, "EMBED" ).SetVariable( "overlay", "ja" )
			} else if ( myPort && myA.href.indexOf("service")>0 ) {
				findChild ( myPort, "EMBED" ).setAttribute( "wmode", "transparent")
				myPort.setAttribute( "class", "hideMe" )
			} else if ( !khtml && myPort && ( myA.href.indexOf("unternehmen")>0 || myA.href.indexOf("company")>0 ) && myPort.offsetWidth > 365 ) {
				findChild ( myPort, "EMBED" ).setAttribute( "wmode", "transparent")
				myPort.setAttribute( "class", "hideMe" )
			}
		}
	}
}
var timer = null
var hideElm = null
function low( elm ) 
{
	hideSubmenu( elm )
	hideElm = elm
	timer = setTimeout( "hideSubmenu( null )", 300 )
}
function hideSubmenu ( elm ) {
	if ( !elm || ( hideElm && hideElm.innerHTML != elm.innerHTML ) )
	{
		hideUL = findChild ( hideElm, "UL" )
		hideUL.style.display = 'none'
		hideA = findChild ( hideElm, "A" )
		hideA.className = ''
		clearShadow( elm )
		if ( mozilla ) {
			var myNav = document.getElementById( 'Navigator' )
			var myPort = document.getElementById( 'Portfolio' )
			if ( myNav && myNav.className.indexOf( "hideMe" ) > -1 && hideA.href.indexOf( "format" ) > 0 ) {
				findChild ( myNav, "EMBED" ).setAttribute( "wmode", "")
				myNav.setAttribute( "class", "rightbox navigatorswf" )
			} else if ( !khtml && myNav && hideA.href.indexOf( "portfolio" ) > 0  ) {
				findChild ( myNav, "EMBED" ).SetVariable( "overlay", "nein" )
			} else if ( myPort && myPort.className.indexOf("hideMe")>-1  && hideA.href.indexOf("service")>0 ) {
				findChild ( myPort, "EMBED" ).setAttribute( "wmode", "")
				myPort.setAttribute( "class", "" )
			} else if ( !khtml && myPort && myPort.className.indexOf("hideMe")>-1   
						&& ( hideA.href.indexOf("unternehmen")>0 || hideA.href.indexOf("company")>0 )
						&& myPort.offsetWidth > 365 ) {
				findChild ( myPort, "EMBED" ).setAttribute( "wmode", "")
				myPort.setAttribute( "class", "" )
			}
		}
	}
	clearTimeout( timer )
}


function createShadow( elm ) {
	clearShadow()
	newelm = document.createElement( "DIV" )
	newelm.setAttribute( "id", "shadow" )
	h = findChild ( elm, "UL" ).offsetHeight+2
	newelm.style.height = h+"px"
	elm.appendChild( newelm )
}
function clearShadow( elm ) {
	var tmp
	if ( elm && hideElm.innerHTML == elm.innerHTML || !elm )
		tmp =  document.getElementById('shadow')
	if ( tmp ) tmp.parentNode.removeChild( tmp )
}

// ============ Menu LIB ============ 
function findChild ( elm, tagName ) {
	//for ( a in elm.childNodes ) 
	for ( var a=0; a < elm.childNodes.length; a++ ) {
		if( elm.childNodes.item(a).tagName == tagName ) {
			return elm.childNodes.item(a)
		}
	}
	return false
}
function findParent( elm ) {
	if ( elm.parentElement ) {
		return elm.parentElement
	} else
		return elm.parentNode
}


// ============ getPortfolio ============
function getPortfolio ( url, meinkeks ) {
	if ( meinkeks ) {
		setCookie( "keks", meinkeks, 5 )
	}
	window.location = url;
} 
// ============ onload ============ 
window.onload = init
window.onresize = setup

function init() {
	setup()
	if ( msie ) {
		doPNGs()
		//setTimeout("setOverflowMSIE()", 100)
	}
	spamSchutz()
}
function setup() {
	resetHeights()
	setheightContentarea()
	setMainHeight()
	//setContentSmallboxes()
}

function getHeight() {
	if ( window.innerHeight )
		return window.innerHeight
	if ( document.documentElement && document.documentElement.clientHeight )
		return document.documentElement.clientHeight
	if ( document.body ) 
		return document.body.clientHeight
	else 
		return 600;
}

function getBoxes( myClassName ) {
	elm = document.getElementById( 'contentArea' )
	//for ( a in elm.childNodes ) {
	for ( a=0; elm.childNodes.length > a; a++ ) {
		myelm = elm.childNodes[a]
		if ( myelm.tagName && myelm.tagName == "DIV" && myelm.className.indexOf( myClassName ) > 0  ) {
			return myelm
		}
	}
}
var heightContentarea
function setheightContentarea() {
	// sets height of DIV#Contentarea to windowheight
	var elm = document.getElementById( 'contentArea' )
	var bigbox = getBoxes( "bigbox" )
	var smallboxes = document.getElementById( 'smallboxes' )
	var splash = document.getElementById( "splash" )
	if ( elm && !( msie_version == 6 && splash ) ) {
		elm.style.height = "auto"
		var newH = Math.max( getHeight() - 160, 380 )
		elm.style.height =  newH + "px"
	}
	// BigBox
	if ( bigbox && bigbox.className.indexOf( "full" ) > 0 ) { // smallbox
		if ( bigbox.offsetHeight > elm.offsetHeight )
		 	elm.style.height =  bigbox.offsetHeight + "px"
		bigbox.style.minHeight = (bigbox.parentNode.offsetHeight - 1 ) + "px"
		bigbox.style.height = bigbox.offsetHeight + "px"
	}
	else if ( bigbox && smallboxes || splash  ) { // && !splash
		
		if ( bigbox )
			newH = bigbox.offsetHeight + smallboxes.offsetHeight
		if ( splash ) {
			newH = splash.offsetHeight + smallboxes.offsetHeight + 55
			//elm.style.border = "1px solid red"
		}
		if ( newH > elm.offsetHeight )
		 	elm.style.height = (newH+10)+"px"
		newH = elm.offsetHeight - smallboxes.offsetHeight + 2
		if ( msie && msie_version > 6 && newH > getHeight()-150 ) newH = false;
		if ( newH && bigbox ) bigbox.style.height = newH + "px"
		else if ( document.getElementById( 'Navigator' ) && !splash  )
			document.getElementById( 'Navigator' ).style.height =  (elm.offsetHeight-10) + "px" 
	}
	// teamListing
	if ( getBoxes( "TeamListingSmall" ) ) {
		var team = getBoxes( "TeamListingSmall" )
		team.style.minHeight = (team.parentNode.offsetHeight + 2 ) + "px"
		for ( a in team.childNodes ) {
			myelm = team.childNodes[a]
			if ( myelm.tagName && myelm.tagName == "UL" )
				myelm.style.minHeight = ( myelm.parentNode.offsetHeight - 24 )+"px"
			if ( myelm.tagName && myelm.tagName == "DIV" && myelm.className == "tx-feusersview-pi1" ) {
				for ( a in myelm.childNodes ) {
					tmp = myelm.childNodes[a]
					if ( tmp.tagName && tmp.tagName == "UL" )
						tmp.style.minHeight = ( tmp.parentNode.parentNode.offsetHeight - 24 )+"px"
				}
			}
		}
	} 
	// splash
	else if ( splash && ( msie_version > 6 ) ) {
		minHelms = splash.offsetHeight
		minHelms += document.getElementById("smallboxes").offsetHeight
		minHelms += 55
		if ( elm.offsetHeight < minHelms ) 
			elm.style.height = minHelms + "px"
		else 
			elm.style.height = "auto"
	} 
	// msie6 && smallboxes && bigbox
	if ( msie_version == 6 && bigbox && smallboxes && !splash ) {
		bigbox.style.height = ( Math.max( getHeight() - 160, 380 ) - 172 ) + "px"
		for ( var i=0; bigbox.children.length > i ; i++ ) {
			var myC = bigbox.children[i]
			if ( myC.className && myC.className.indexOf("leftbg") > -1) {
				myC.style.height = bigbox.offsetHeight + "px"
			}
		}
	}
	if ( msie_version == 6 &&  getBoxes( "TeamListingSmall" ) ) {
		var team = getBoxes( "TeamListingSmall" )
		team.style.height = Math.max( ( Math.max( getHeight() - 160, 380 ) ), 456 ) + "px"
		for ( a in team.children ) {
			myelm = team.children[a]
			if ( myelm.tagName && myelm.tagName == "UL" )
				myelm.style.height = ( myelm.parentElement.offsetHeight - 23 )+"px"
			if ( myelm.tagName && myelm.tagName == "DIV" && myelm.className == "tx-feusersview-pi1" ) {
				for ( a in myelm.children ) {
					tmp = myelm.children[a]
					if ( tmp.tagName && tmp.tagName == "UL" ) 
						tmp.style.height = ( tmp.parentElement.parentElement.offsetHeight - 23 )+"px"
				}
			}
		}
	}
	if ( msie_version == 6 && document.getElementById( 'Navigator' ) && !splash ) {
		newH = elm.offsetHeight - 52
		if ( smallboxes ) {
			newH = smallboxes.offsetHeight + bigbox.offsetHeight - 1
		}
		document.getElementById( 'Navigator' ).style.height = ( newH )+ "px"
	}
	
}
function setMainHeight() {
	if ( !document.getElementById( "splash" ) ) {
		var con = document.getElementById( 'contentArea' )
		var Main = document.getElementById( 'Main' )
		Main.style.minHeight = (con.offsetHeight + 140 ) + "px"
	}
}

function resetHeights() {
	if ( !document.getElementById( "splash" ) ) {
		resetMyHeight ( document.getElementById('contentArea') )
		resetMyHeight ( getBoxes( "bigbox" ) )
		resetMyHeight ( document.getElementById('Main') )
	}
}
function resetMyHeight ( elm  ) {
	if (elm && elm.style ) {
		elm.style.minHeight = "0"
		elm.style.height = "auto"
	}
}
// ================== FLASH NAVIGATION ===================================
function writeNav( navigator, L ) {
	if ( navigator == "navigator" ) {
		var src = "/fileadmin/templates/swf/navigator.swf"
	} else {
		var src = "/fileadmin/templates/swf/aktuelles.swf"
	}
	var so = new SWFObject(src,"mynavigator","100%","100%","6","");
	if ( !mozilla ) //|| mozilla_version >= 2 )
		so.addParam("wmode", "transparent");
	so.addVariable("pfad", "/fileadmin/templates/");
	so.addVariable("L", L );
	if ( wert = getCookie( "keks" ) )
		so.addVariable("keks", wert);
	so.useExpressInstall('/fileadmin/templates/swf/expressinstall.swf');
	so.setAttribute('xiRedirectUrl', 'http:\/\/www.imagion.de/');
	so.write("Navigator");
}
function writeNav90() {
	var L = (window.location.href.indexOf("imagion.de/en")>0) ? 1: 0
	var so = new SWFObject("/fileadmin/templates/swf/slideshow_90.swf", "navigator", "100%", "100%", "6", "");
	so.addVariable("pfad", "/fileadmin/templates/");
	so.addVariable("L", L );
	so.useExpressInstall('/fileadmin/templates/swf/expressinstall.swf');
	so.setAttribute('xiRedirectUrl', 'http:\/\/www.imagion.de/');
	so.write("Navigator");
}
function Impressum() {
	if ( window.location.href.indexOf("imagion.de/en")>0 ) {
		window.location = "/en/extra/impressum.html"
		return false;
	}
}


// ============ onload CSS Loader ============ 
var msie, msie_version
var dom, opera, mozilla, mozilla_version, khtml
if ( !window.opera && navigator.userAgent.indexOf( "MSIE" ) > 0 ) {
	msie = true
	msie_version = 4
	document.write( '<link href="/fileadmin/templates/lib/css/bc.msie.styles.css" 	rel="Stylesheet"  type="text/css" />' )
	if ( navigator.userAgent.indexOf( "MSIE 7" ) > 0 ) {
		// alert( "msie 7" )
		msie = true
		msie_version = 7
		document.write( '<link href="/fileadmin/templates/lib/css/bc.msie7.styles.css" 	rel="Stylesheet"  type="text/css" />' )
	} else if ( navigator.userAgent.indexOf( "MSIE 8" ) > 0 ) {
		msie = true
		msie_version = 7
		document.write( '<link href="/fileadmin/templates/lib/css/bc.msie7.styles.css" 	rel="Stylesheet"  type="text/css" />' )
	} else if ( navigator.userAgent.indexOf( "MSIE 6" ) > 0 ) {
		// alert( "msie 6" )
		msie = true
		msie_version = 6
		document.write( '<link href="/fileadmin/templates/lib/css/bc.msie6.styles.css" 	rel="Stylesheet"  type="text/css" />' )
	} else if ( navigator.userAgent.indexOf( "MSIE 5" ) > 0 ) {
		//alert( "msie 5" )
		msie = true
		msie_version = 5
		document.write( '<link href="/fileadmin/templates/lib/css/bc.msie5.styles.css" 	rel="Stylesheet"  type="text/css" />' )
	}
} else if ( window.opera ) {
	opera = true
	document.write( '<link href="/fileadmin/templates/lib/css/bc.opera.styles.css" 	rel="Stylesheet"  type="text/css" />' )
} else if ( navigator.userAgent.indexOf( "Gecko" ) > 0 ) {
	mozilla = true
	if ( navigator.userAgent.indexOf( "KHTML" ) > 0 ) {
		khtml = true // SAFARI
		writeCSS( "bc.safari.styles" )
	} else if ( navigator.userAgent.indexOf( "Firefox\/1.5" ) > 0 )
		mozilla_version = 1.5
	else if ( navigator.userAgent.indexOf( "Firefox\/1" ) > 0 )
		mozilla_version = 1
	else if ( navigator.userAgent.indexOf( "Firefox\/0" ) > 0 )
		mozilla_version = 0
	else 
		mozilla_version = 2 // Fallback, everything higher than Firefox  2.0
}

function writeCSS( cssname ) {
	document.write('<link href="/fileadmin/templates/lib/css/'+cssname+'.css" rel="Stylesheet" type="text/css" />')
}
// ============ PNG ============ 
function doPNGs() {
	if ( msie_version < 7 ) {
		for (a in document.images) {
			var myimg = document.images[a]
			if ( myimg.src && myimg.src.indexOf(".png")>0 && myimg.src.indexOf("\/uploads\/")>0 ) {
				myfilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+myimg.src+"',sizingMethod='scale')"
				myimg.src = "/clear.gif"
				myimg.runtimeStyle.filter = myfilter
			}
		}
	}
}

function setOverflowMSIE() {
	var docElm 
	docElm =  ( document.documentElement ) ? document.documentElement : document.body
	docElm.style.overflow = "auto"
	docElm.style.overflowX = "hidden"
	if (  msie_version > 6 && ( document.getElementById( 'contentArea' ).offsetHeight + 125 ) > getHeight() ) {
		document.getElementById( 'Main' ).style.left = "8px"
	}
}


// ============ onload LIB  ============ 
function countMe( elm, tagname ) {
	var i=0
	for ( a in elm.childNodes ) {
		if ( elm.childNodes[a].tagName && elm.childNodes[a].tagName == tagname ) {
			i++
		}
	}
	return i;
} 

function spamSchutz() {
	myLinks = document.getElementsByTagName( "SPAN" )
	for ( i=0; i < myLinks.length ; i++ ) {
		var myLinkItem = myLinks.item( i )
		if ( myLinkItem && myLinkItem.className && myLinkItem.className == "spamschutz" ) {
			myLinkItem.className == ""
			myLinkA = Rot13.convert( myLinkItem.innerHTML )
			myLinkItem.innerHTML = "<a href='mailto:"+myLinkA+"'>"+myLinkA+"</a>"
		}
	}

}

/* ROT13 encode */
Rot13 = {
    map: null,
    convert: function(a) {
        Rot13.init(); var s = "";
        for (i=0; i < a.length; i++) {
            var b = a.charAt(i); s += ((b>='A' && b<='Z') || (b>='a' && b<='z') ? Rot13.map[b] : b);
        }
        return s;
    },
    init: function() {
        if (Rot13.map != null) return;
        var map = new Array(); var s = "abcdefghijklmnopqrstuvwxyz";
        for (i=0; i<s.length; i++) map[s.charAt(i)] = s.charAt((i+13)%26);
        for (i=0; i<s.length; i++) map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
        Rot13.map = map;
    },
    write: function(a) {
        document.write(Rot13.convert(a));
    }
}

// ============ 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 ) );
}

function SendCookieToFlash( name ) {
	var flash = findFlash( "navigator" )
	wert = getCookie( name )
	if ( flash && wert ) {
		// alert( name+" = "+wert )
		flash.SetVariable( name, wert )
	}
}

function findFlash (flash) {
	if (document.all) 
	{
		if (document.all[flash]) return document.all[flash];
		if (window.opera) 
		{
			var movie = eval(window.document + flash);
			if (movie.SetVariable) return movie;
		}
	} else if(document.embeds) 
	{
		if(document.embeds) 
		{
        	var movie = document.embeds[flash];
			if (movie.SetVariable)  return movie;
		}
    } else if (document.getElementById) 
	{
		var movie = document.getElementById(flash);
    	if (movie.SetVariable) 
			return movie;
    	var movies = movie.getElementsByTagName('embed');
    	if ( !movies || !movies.length ) return;
    	if ( movies[0].SetVariable ) return movies[0];
	}
}
function setAktuelles() {
	var so = new SWFObject("/fileadmin/templates/swf/aktuelles.swf","mynavigator","100%","100%","6","");
	if ( !mozilla ) so.addParam("wmode", "transparent");
	so.addVariable("pfad", "/fileadmin/templates/");
	var L = (window.location.href.indexOf("/en/")>0) ? 1 : 0
	so.addVariable("L", L);
	so.useExpressInstall('/fileadmin/templates/swf/expressinstall.swf');
	so.setAttribute('xiRedirectUrl', 'http:\/\/www.imagion.de/');
	so.write("Navigator");
}

function setMax( ) {
	alert( "Max IST gross" )
}