// (c) 2007 Lars Tewes / l.tewes@view-source.de i.A. erica http://www.ericamedia.de/

var preloadLogo		= (new Image()).src = 'imgs/logo_hl.gif'
var flashVerReq		= 8
var minWidth		= 10000 // 1035 - disabled...
var minHeight		= 10000 // 765 - disabled...
var d				= document
var winModifier		= 'rh'
var timeoutID		= null
var orgWidth		= 0
var orgHeight		= 0
var flashLoaded		= false
var storedBodySrc	= ''

window.onload = function() {
	if (flashVersionGet() < flashVerReq)
		window.location = 'download.html'
	else {
		align()
		start()
	}
}

window.onresize	= function() {
	window.clearTimeout(timeoutID) // IE...
	timeoutID = window.setTimeout('rebuild()', (document.all) ? 500 : 100)
}

function rebuild(force) {
	if (!force && document.all && orgWidth == documentWidth() && orgHeight == documentHeight()) // damn. ie fires resize-event on every small change :(
		return
	orgWidth	= documentWidth()
	orgHeight	= documentHeight()
	align()
}

function align() {
	var viewportWidth	= documentWidth()
	var viewportHeight	= documentHeight()
	if (flashLoaded) {
		if (viewportWidth >= minWidth && viewportHeight >= minHeight) {
			var mainFlashDivElm				= document.getElementById('mainFlashDiv')
			mainFlashDivElm.style.width		= documentWidth() + 'px'
			mainFlashDivElm.style.height	= documentHeight() + 'px'
		} else {
			flashLoaded									= false
			document.getElementById('daBody').className	= ''
			document.getElementById('daBody').innerHTML = storedBodySrc
			start()
		}
	} else {
		if (document.getElementById('floating'))
			document.getElementById('floating').style.top = Math.round(viewportHeight / 2 - 25) + 'px'
	}
}

function documentWidth() {
	return (d.all) ? ((d.documentElement.clientWidth)  ? d.documentElement.clientWidth  : d.body.clientWidth) : window.innerWidth
}

function documentHeight() {
	return (d.all) ? ((d.documentElement.clientHeight) ? d.documentElement.clientHeight : d.body.clientHeight) : window.innerHeight
}

function getQueryStringAsArr(loc) {
	if (loc.charAt(loc.length - 1) == '#')
		loc = loc.substr(0, loc.length - 1)
	var returnArr	= []
	var qs			= (loc.indexOf('?') != -1) ? loc.substr(loc.indexOf('?') + 1) : loc
	var attrArr		= qs.split('&')
	for(var i=0, j=attrArr.length; i<j; i++) {
		var splitArr = attrArr[i].split('=')
		returnArr[splitArr[0]] = splitArr[1]
	}
	return returnArr
}

function getValidQueryString() {
	var qsAdd	= ''
	var qsArr	= getQueryStringAsArr(window.location.href)
	var regEx	= /^[\w\d_]+$/
	if (qsArr['jumper'] != null && regEx.test(qsArr['jumper']))
		qsAdd += '&jumper=' + escape(qsArr['jumper'])
	return qsAdd
}

function start(isClick) {
	var qsArr			= getQueryStringAsArr(window.location.href)
	var isPopUp			= (qsArr['popUp'] != null)
	var viewportWidth	= orgWidth	= documentWidth()
	var viewportHeight	= orgHeight	= documentHeight()

	if (isPopUp || (viewportWidth >= minWidth && viewportHeight >= minHeight)) {
		document.getElementById('daBody').className = 'flash'
		var scale		= isPopUp && (viewportWidth < minWidth || viewportHeight < minHeight)
		viewportWidth	= '100%'
		viewportHeight	= '100%'

		var flashSrc	= 'base.swf?rnd=' + (new Date()).getTime()  + '&test=&' + getValidQueryString()
		var flashStr	= '<object classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000" id="daFlashObj"\
								codebase="http://active.macromedia.com/flash' + flashVerReq + '/cabs/swflash.cab#version=' + flashVerReq + ',0,0,0" width="' + viewportWidth  + '" height="' + viewportHeight  + '">\
								<param name="movie" value="' + flashSrc + '">\
								<param name="quality" value="high">\
								<param name="menu" value="true">\
								<param name="autostart" value="true">\
								' + ((scale) ? '' : '<param name="scale" value="noscale">') + '\
								<param name="salign" value="m">\
								<param name="bgcolor" value="#323232">\
								<embed name="mainFlash" src="' + flashSrc + '"\
									quality="high"\
									id="daFlashObj"\
									autostart="true"\
									pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"\
									type="application/x-shockwave-flash" width="' + viewportWidth  + '" height="' + viewportHeight  + '"\
									' + ((scale) ? '' : 'scale="noscale"') + '\
									salign="m"></embed>\
							</object></div>'
		var containerStr = '<div id="mainFlashDiv"></div>'
		storedBodySrc = document.getElementById('daBody').innerHTML
		document.getElementById('daBody').innerHTML = containerStr
		var mainFlashDivElm = document.getElementById('mainFlashDiv')
		mainFlashDivElm.style.width		= documentWidth() + 'px'
		mainFlashDivElm.style.height	= documentHeight() + 'px'
		document.getElementById('mainFlashDiv').innerHTML = flashStr
		flashLoaded = true
		return false
	} else {
		return (isClick) ? startPopUp() : false
	}
}

function startPopUp() {
	var nUA			= navigator.userAgent
	var buggyIEWin	= (nUA.indexOf('MSIE') != -1 && nUA.indexOf('Windows') != -1)
	var buggyIEMac	= (nUA.indexOf('MSIE') != -1 && nUA.indexOf('Mac') != -1)
	var buggySafari	= (nUA.indexOf('afari') != -1)
	var qsAdd		= getValidQueryString()
	var offX		= 0
	var offY		= -38
	switch (true) {
		case (buggyIEMac):
			offY = -86
			break
		case (buggyIEWin):
			offX = -11
			break
	}
	wWidth		= screen.availWidth  + offX
	wHeight		= screen.availHeight + offY
	paramStr	= "dependent=no,location=no,menubar=no,resizable=yes,scrollbars=no,fullscreen=no,status=no,toolbar=no,left=0,top=0,screenX=0,screenY=0,width=" + wWidth + ",height=" + wHeight + ",outerWidth=" + wWidth
	daWin	= window.open("./?popUp=true&nocache=" + Math.round(Math.random()*100000) + qsAdd, "rhPopUpWin", paramStr)
	if (!buggyIEMac && daWin != null && daWin.focus)
		daWin.focus()
	return false
}

function openWin(daPath, daW, daH, daX, daY) {
	var win = window.open(daPath, 'extWin', 'location=no,toolbar=no,status=no,scrollbars=no,left=' + daX + ',top=' + daY + ',screenX=' + daX + 'screenY=' + daY + ',width=' + daW + ',height=' + daH)
	if (win.focus)
		win.focus()

}

function flashVersionGet() { // part of http://jquery.lukelutman.com/plugins/flash
	try { // ie
		try {
			// avoid fp6 minor version lookup issues, see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always';	}
			catch(e) { return parseInt('6,0,0')}
		} catch(e) {}
		return parseInt(new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]);
	} catch(e) { // other browsers
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return parseInt((navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]);
			}
		} catch(e) {}
	}
	return parseInt('0,0,0');
}

function flashGetHref() {
	return location.href
}

function flashPutHref(href) {
	location.href = href
}

function flashGetTitle() {
	return document.title
}

function flashPutTitle(title) {
	document.title = title
}

