document.write("<style type='text/css'>.klapp_box *{display: none;}</style>")

window.onload=init

function init(){
	setLocationHighlight()
	document.onclick=doc_onclick
	header_bgimage_moveright()
}

function setLocationHighlight(){
	var loc=window.CURR_FILEPATH? CURR_FILEPATH : (window.location_path ? location_path : window.location.pathname)
	var pn=_id("primnav")
	var pnlinks=pn.getElementsByTagName("A")
	for(var i=0; i< pnlinks.length; i++){
		if(pnlinks[i].hostname != window.location.hostname) continue
		var stem=pnlinks[i].pathname
		stem=stem.replace(/^(\/[\w_-]+)[\/\.].*/, "$1")
		if(pnlinks[i].parentNode.className=="subMenuDiv2"){
			if(loc.indexOf(pnlinks[i].pathname)>=0) pnlinks[i].className+=" current"
		}
		else if(loc.indexOf(stem)==0) {
			if(pnlinks[i].parentNode.tagName=="TD") pnlinks[i].parentNode.className += " current"
			else pnlinks[i].parentNode.parentNode.className += " current"
		}
	}
}


function doc_onclick(e){
	e=e || window.event
	if(!e) return false
	if(e.button==2)return true
	var trgt=getEventTarget(e)
	var par=trgt.parentNode
	if(trgt.className=="klapp_header" || (trgt.tagName.match(/em|h(2|3|4|5)/i)) && par.className && par.className.match(/klapp_box/)){
		if(DOSLIDE)toggle2_klapp_block(par,trgt)
		else toggle_klapp_block(par)
	}
	
}





/*-------------------------------------
header Image background show
-------------------------------------*/

header_bg_imgdir="/images/"
wipe_step=1
wipe_delay=30
wipe_pause=2000
var imgLeft=-600
header_show_window_width=430;

function header_bgimage_moveright(){
	var bg=_id("header_bg_image")
	var mw=bg.offsetWidth-header_show_window_width
	bg.style.left=imgLeft + "px"
	imgLeft-=wipe_step
	if(imgLeft>-mw)setTimeout("header_bgimage_moveright()",wipe_delay)
	else {
		switch_image()
		imgLeft=-( panoramaImages[imgRotate].w -header_show_window_width )
		bg.style.left=imgLeft+"px"
		setTimeout("header_bgimage_moveleft()",wipe_pause)
	}
}
function header_bgimage_moveleft(){
	var bg=_id("header_bg_image")
	bg.style.left=imgLeft + "px"
	imgLeft+=wipe_step
	if(imgLeft<0) setTimeout("header_bgimage_moveleft()",wipe_delay)
	else {
		switch_image()
		setTimeout("header_bgimage_moveright()",wipe_pause)
		imgLeft=0
	}
}

imgRotate=0
panoramaImages=[
	{src:"Allgaeuer_Alpen_Panorama_slide.jpg",w:1269},
	{src:"hafen_panorama.jpg",w:912}
]

function switch_image(){
	imgRotate=++imgRotate % panoramaImages.length
	var bg=_id("header_bg_image")
	bg.src=header_bg_imgdir + panoramaImages[imgRotate].src
}





/*-------------------------------------
Klapp block 
-------------------------------------*/


function toggle_klapp_block(elm){
	if(elm.className.match(/klapp_box_open/)){
		elm.className=elm.className.replace(/klapp_box_open/, "klapp_box")
	}
	else elm.className=elm.className.replace(/klapp_box/, "klapp_box_open")
}





DOSLIDE=true
SLIDESTEPS=7
SLIDEDELAY=20
SLIDEOPEN=1
SLIDESHUT=2
PAGE_H_MARGINS=80 // add page margins height to body height to stop the flickers when resizing on close slider


function toggle2_klapp_block(elm,header){
	if(elm.className.match(/klapp_box_open/))start_slide(elm,header,SLIDESHUT)
	else start_slide(elm,header,SLIDEOPEN)
}

function start_slide(elm,header,d){
	if(!elm.className.match(/_open/))elm.className=elm.className.replace(/klapp_box/, "klapp_box_open")
	if(window.slide_timer)finish_slide()
	elm.direction=d
	elm.style.overflow="hidden"
	hh=getElmHeight(header)
	elm.headerHeight=hh
	var h=getElmHeight(elm)
	elm.bottom=(d==SLIDESHUT) ? h : hh
	elm.jump= Math.ceil((h-hh) / SLIDESTEPS)
	elm.loops=0
	current_slider=elm
	slide_elm()
	var t=elm.getElementsByTagName("TABLE")[0]
	if(t) {
		if(t.outerHTML) t.outerHTML=t.outerHTML
	}
	
}

function slide_elm(){
	var cs = current_slider
	cs.bottom = cs.direction==SLIDESHUT ? cs.bottom - cs.jump: cs.bottom + cs.jump
	cs.style.height=cs.bottom + "px"	
	if(++cs.loops>=SLIDESTEPS ) return finish_slide()
	slide_timer=setTimeout("slide_elm()", SLIDEDELAY)
}

function finish_slide(){
	window.slide_timer=null
	var cs=current_slider
	if(cs.direction==SLIDESHUT) cs.className=cs.className.replace(/_open/, "")
	cs.style.height="auto"
	var pg=_id("page")
	if(cs.direction==SLIDEOPEN)document.body.style.height=(getElmHeight(pg) + PAGE_H_MARGINS) + "px"
}


/*--------------------------------
basic dom/event things
--------------------------------------*/

function _id(s){return document.getElementById(s)}
function getWinHeight(){return window.innerHeight || document.body.clientHeight}
function getElmTop(elm){return elm ? elm.offsetTop + getElmTop(elm.offsetParent) : 0}
function getElmLeft(elm){return elm ? elm.offsetLeft + getElmLeft(elm.offsetParent) : 0}

function getElmHeight(elm){return elm.offsetHeight }
function getElmWidth(elm){return elm.offsetWidth}

function getScrollY() {
  return typeof( window.pageYOffset ) == 'number' ? window.pageYOffset
    	: document.body && document.body.scrollTop ? document.body.scrollTop
    	: document.documentElement.scrollTop
}



function getEventTarget(e){window.defaultStatus=e.type;return e.srcElement ? e.srcElement : e.target}

function killBubble(e){
	if(!e)e=window.event
	if(!e)return false
	if(e.stopPropagation)e.stopPropagation()
	else e.cancelBubble=true
}

kgpopwin=null
function openpop(l, w, h){
	if(!w) w=680; if(!h)h=500;
	if(kgpopwin && !kgpopwin.closed)kgpopwin.close()
	var dims= "width=" + w + ",height=" + h + ",scrollbars=1"
	kgpopwin=window.open(l.href, "popup", dims)
	self.name="kg_main"
	return false
}




