var mouseX
var mouseY

/*  id ( ID des Info-Layers )
 *  overID ( ID des Objekts, auf das reagiert wird )
 */ 
function infobox(id, overID, offsetx, offsety) {

	this.id=id
	this.overID=overID
	
	this.ns4=document.layers
	this.ie4=document.all
	this.ns6=document.getElementById&&!document.all
	this.os=""
	this.left=""
	this.top=""
	this.infoBoxWidth=""
	this.infoBoxHeight=""

	this.crossobj=null
	this.eventobj=null

	this.offsetx = offsetx
	this.offsety = offsety
	
	this.mousePosX=0
	this.mousePosY=0

	this.init=init
	this.hidebox=hidebox
	this.showbox=showbox
	this.taxi_showbox=taxi_showbox
	this.setLeft=setLeft
	this.setTop=setTop
	this.reposition=reposition
	
	this.getScreenWidth=getScreenWidth
	
	this.getInfoBoxWidth=getInfoBoxWidth
	this.getInfoBoxHeight=getInfoBoxHeight
	
	//this.getMousePosX=getMousePos
	//this.getMousePosY=getMousePosY
	
	this.checkMousePos=checkMousePos

	this.init()
	this.setLeft()
	this.setTop()
	this.getInfoBoxWidth()
	this.getInfoBoxHeight()
	
	InfoBoxList[InfoBoxList.length] = this
	
	
	function init(){
		this.crossobj=this.ns6? document.getElementById(this.id) : document.all[ this.id ]
		this.eventobj=this.ns6? document.getElementById(this.overID) : document.all[ this.overID ]
		if (navigator.appVersion.indexOf("Win")!=-1) this.os="Windows";
		if (navigator.appVersion.indexOf("Mac")!=-1) this.os="MacOS";

	}
	
	function reposition() {
		this.init()
		this.setLeft()
		this.setTop()
	}

	function hidebox(){
		if (this.ie4||this.ns6)
			this.crossobj.style.visibility="hidden"
		else if (this.ns4)
			document.showimage.visibility="hide"
	}
	
	
	
	function getScreenWidth() {
		if( this.ns6 ) 
			return parseInt(window.innerWidth )
		else
			return parseInt(document.body.clientWidth)
	}
	
	
	
	function getInfoBoxWidth() {
		this.infoBoxWidth = parseInt(this.crossobj.style.width)
	}
	
	
	
	function getInfoBoxHeight() {
		this.infoBoxHeight = parseInt(this.crossobj.style.height)
	}
	
	
	
	function taxi_showbox(xx,yy) {
			closeAllBoxes()
			
			if(this.os=="MacOS")
				this.crossobj.style.left=xx+top.main.document.getElementById("maphelper").offsetLeft-65
			else
				this.crossobj.style.left=xx+top.main.document.getElementById("mapgif").offsetLeft-65
			this.crossobj.style.top=yy+35
			var screenWidth= getScreenWidth()
			if( (parseInt(this.crossobj.style.left)+this.infoBoxWidth) > screenWidth)
				this.crossobj.style.left=screenWidth-this.infoBoxWidth-15
			if (this.ie4||this.ns6) {
				this.crossobj.style.visibility="visible"
			}
			else if (this.ns4)
				document.showimage.visibility="show"
	}
	
	function showbox() {
		closeAllBoxes()
		this.reposition()
		this.crossobj.style.left=this.left+offsetx	
		this.crossobj.style.top=this.top+offsety
		var screenWidth= getScreenWidth()
		if( (parseInt(this.crossobj.style.left)+this.infoBoxWidth) > screenWidth)
			this.crossobj.style.left=screenWidth-this.infoBoxWidth-15
		
		if (this.ie4||this.ns6) {
			this.crossobj.style.visibility="visible"
		}
		else if (this.ns4)
			document.showimage.visibility="show"
	}
	
	
	
	function setLeft() {
		parentObj=this.eventobj.offsetParent
		leftPos=this.eventobj.offsetLeft
		while(parentObj != null) {
			if (parentObj.id.indexOf("map")!=-1) {
				leftPos+=document.getElementById("mapgif").offsetLeft
			} else {
				leftPos+=parentObj.offsetLeft
			}
			parentObj=parentObj.offsetParent
		}
		this.left=leftPos
	}
	
	
	
	function setTop() {
		parentObj=this.eventobj.offsetParent
		topPos=this.eventobj.offsetTop
			
		while(parentObj != null) {
			topPos+=parentObj.offsetTop
			parentObj=parentObj.offsetParent
		}
		this.top=topPos
	}
	
	
	//---------------------------------------------------------------------------------------------------
	
	
	function checkMousePos() {
		infoleft = parseInt(this.crossobj.style.left)
		infotop = parseInt(this.crossobj.style.top)
		
		if( (mouseX >= infoleft+5) && 
			(mouseX < infoleft+this.infoBoxWidth-5) &&
			(mouseY > infotop) &&
			(mouseY <= infotop+this.infoBoxHeight) ) {
		}
		else{
			this.hidebox()
			closeAllBoxes()
		}
		return false
	}
	
	
	
}
// Ende Infobox
//-----------------------------------------------------------------------------------------------



function getMousePos(e, boxID) {
	mouseX=(window.event)? window.event.clientX+document.body.scrollLeft : e.pageX;
	mouseY=(window.event)? window.event.clientY+document.body.scrollTop : e.pageY;
	boxID.checkMousePos()
	return false
}


function closeAllBoxes() {
	for(var i=0; i<InfoBoxList.length; i++) {
		InfoBoxList[i].hidebox()
	}
	return true 
}