/* -- */function fixPosition(el,delay,offset){
  if(document.getElementById){
    el.delay=delay;
    el.initTop=0;
    el.offset=offset;
    el.refreshPosition=function(){
      if(document.getElementById){
        st = parseInt((document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop);
        st-=this.offset;
        if(st<0){
        	st=0;
        }
	    this.style.marginTop=this.initTop+st+"px";
      }
    }
    setInterval('document.getElementById("'+el.id+'").refreshPosition()',delay);
  }
}

var dom= new Object();
dom.removeAllChildNodes=function(e){
	for(var i=e.childNodes.length-1;i>=0;i--){
		e.removeChild(e.childNodes[i]);
	}
};

dom.remove=function(node){
	node.parentNode.removeChild(node);
};

function CreateImageCaptions(){
	var images=document.getElementsByTagName('img');
	for(var i=0;i<images.length;i++){
		if(images[i].className!='static'){
		 	if(document.body.className!='Index'){
				var imageWithCaption=document.createElement('DIV');
				imageWithCaption.className='imageWithCaption';
				var image=document.createElement('IMG');
				imageWithCaption.style.width=images[i].width+'px';
				image.alt=images[i].alt;
				image.src=images[i].src;	
				imageWithCaption.appendChild(image);
				imageWithCaption.appendChild(document.createElement('BR'));			
				caption=document.createElement('SPAN');
				caption.appendChild(document.createTextNode(image.alt));			
				imageWithCaption.appendChild(caption);
				images[i].parentNode.replaceChild(imageWithCaption,images[i]);
			}
		}
	}
}

window.onload=function(){
	CreateImageCaptions();
	if(window.name=='print'){
		document.body.className='Print';
	}	
};


function ToggleDisplay(id){
	var htmlElement=document.getElementById(id);
	htmlElement.style.display=(htmlElement.style.display=='block')?'none':'block';
}

function OpenPrintViewWindow(){	
	var printView=window.open(window.location.href,'print','');
}

function OpenNewWindow(url,winName,width,height,posX,posY) {
	var location="no";
	var resizable="yes";
	var toolbar="no";
	var status="no";
	if (!posX) posX=40;
	if (!posY) posY=40;
	window.open(url,winName,"width="+width+",height="+height+",top="+posY+",screenY="+posY+",left="+posX+"screenX="+posX+",location="+location+",resizable="+resizable+",toolbar="+toolbar+",status="+status);
}

function OpenCalendar(url){
	OpenNewWindow(url,'calendar',800,600);
}

Menu=new Object();

Menu.hideTimeoutTime=1000;
Menu.hideTimeoutID=null;
Menu.currentItem=null;
Menu.selectedItem=null;

Menu.init=function(){
	this.root.htmlContainer.onmouseout=function(){
		Menu.hideTimeoutID=setTimeout('Menu.collapse()',Menu.hideTimeoutTime);
	};
	this.root.htmlContainer.onmouseover=function(){
		clearTimeout(Menu.hideTimeoutID);
	};
	this.root.display=true;
	this.root.init();
	this.update();
};

Menu.writePath=function(){
	if(this.selectedItem){
		var path=new Array();
		var item=this.selectedItem;
		while(item!=this.root){
			path[path.length]=item;
			item=item.parent;
		}
		for(var i=path.length-1;i>=0;i--){
			var link=path[i].htmlElement.getElementsByTagName('A')[0];
			document.write(' / <a href="'+link.href+'">'+((document.all)?link.innerHTML:link.firstChild.nodeValue)+'</a>');
		}
	}
};

Menu.find=function(element){
	return this.root.find();
};

Menu.setSelected=function(element){
	var selectedItem=this.root.find(element);
	Menu.selectedItem=selectedItem;
	while(selectedItem!=null){
		selectedItem.selected=true;
		selectedItem=selectedItem.parent;		
	}
};

Menu.collapse=function(){
	this.root.hide();
	this.update();
};

Menu.update=function(){
	this.root.update();
};


Menu.parse=function(rootElement,itemTagName,menuTagName){
	this.root=this.parseItem(rootElement,itemTagName,menuTagName);	
}

Menu.parseItem=function(element,itemTagName,menuTagName){
	var item=new MenuItem(element);
	for(var i=0;i<element.childNodes.length;i++){
		var e=element.childNodes[i];
		if(e.tagName==menuTagName){
			item.htmlContainer=e;
			break;
		}
	}
	for(var i=0;i<item.htmlContainer.childNodes.length;i++){
		var e=item.htmlContainer.childNodes[i];
		if(e.tagName==itemTagName){
			item.add(this.parseItem(e,itemTagName,menuTagName));
		}
	}
	return item;
};

function MenuItem(htmlElement){
	this.htmlElement=htmlElement;
	this.htmlContainer=htmlElement;
	this.children=new Array();
	this.parent=null;
	this.display=false;
	this.selected=false;
	htmlElement.item=this;
}

MenuItem.prototype.init=function(){	
	this.baseClassName=this.htmlElement.className;
	//this.baseClassName+=((this.baseClassName!='')?' ':'')+'item';
	this.baseClassName+=((this.baseClassName!='')?' ':'')+((this.selected)?'selected':'');
	this.baseClassName+=((this.baseClassName!='')?' ':'')+((this.htmlElement!=this.htmlContainer)?'parent':'');	
	if(this.parent!=null){
		this.htmlElement.onmouseover=this.onMouseOver;
	}
	for(var i=0;i<this.children.length;i++){
		this.children[i].init();
	}
};

MenuItem.prototype.find=function(htmlElement){
	if(this.htmlElement==htmlElement){
		return this;
	}
	for(var i=0;i<this.children.length;i++){
		var f=this.children[i].find(htmlElement);
		if(f){
			return f;
		}
	}
	return null;
};

MenuItem.prototype.add=function(child){
	this.children[this.children.length]=child;
	child.parent=this;
};

MenuItem.prototype.hide=function(){
	if(this.parent!=null){
		this.display=false;
	}
	for(var i=0;i<this.children.length;i++){
		this.children[i].hide();
	}
};

MenuItem.prototype.show=function(){	
	if(this.parent!=null){
		this.display=true;
		this.parent.show();
	}
};

MenuItem.prototype.update=function(){
	this.htmlElement.className=this.baseClassName+((this.display)?((this.baseClassName!='')?((this.htmlElement!=this.htmlContainer)?' parent_hover ':' '):'')+'hover':'');
	if(this.htmlContainer!=this.htmlElement){		
		this.htmlContainer.style.display=(this.display)?'block':'none';
	}
	if(this.display){
		for(var i=0;i<this.children.length;i++){
			this.children[i].update();
		}
	}
	// ie daran erinnern, dass wir diese elemente sehen wollen ..
	this.htmlContainer.style.visibility='visible';	
	this.htmlElement.style.visibility='visible';	
};

MenuItem.prototype.onMouseOver=function(){
	var p=Menu.currentItem;
	while(p!=null){
		if(p==this.item){
			break;
		}
		p=p.parent;
	}
	if(p==null){
		Menu.root.hide();
		Menu.currentItem=this.item;
	}
	Menu.currentItem.show();
	Menu.update();
};
