var mouseX
var mouseY

/*  id ( ID des Info-Layers )
 *  overID ( ID des Objekts, auf das reagiert wird )
 */ 


function Point(x,y){this.x=x;this.y=y}
function Polygon(a,b){
	this.x=a
	this.y=b
	this.addPoint=addPoint
	this.inside=inside
	this.move=move
	this.points=new Array()
	function move(a,b){	this.x=a;this.y=b;}
	function addPoint(x,y){	this.points[this.points.length]=new Point(x,y)	}
	function inside(a,b) {
		point=new Point(a-this.x,b-this.y)
		var length=this.points.length
		var counter=0
		var x_inter=0
		var p1 = this.points[0]
		for (var i=1;i<=length;i++) {
			var p2 = this.points[i%length]
			if (point.y>Math.min(p1.y,p2.y)) {
				if (point.y<=Math.max(p1.y, p2.y)) {
					if (point.x<=Math.max(p1.x,p2.x)) {
						if (p1.y!=p2.y){
							x_inter=(point.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x
							if (p1.x==p2.x||point.x<=x_inter)counter++
						}
					}
				}
			}
			p1=p2
		}
		return ( counter % 2 == 1 )
	}
}


function infobox(id, overID, offsetx, offsety,ExitPoly) {

	this.id=id
	this.overID=overID
	
	
	this.ns4=document.layers
	this.ie4=document.all
	this.ns6=document.getElementById&&!document.all
	
	this.left=""
	this.top=""
	this.infoBoxWidth=""
	this.infoBoxHeight=""

	this.crossobj=null
	this.eventobj=null

	this.offsetx = offsetx
	this.offsety = offsety
	this.ExitPoly=ExitPoly
	
	
	this.mousePosX=0
	this.mousePosY=0

	this.init=init
	this.hidebox=hidebox
	this.showbox=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(){
		//alert(document.all[ this.id ])
		this.crossobj=this.ns6? document.getElementById(this.id) : document.all[ this.id ]
		this.eventobj=this.ns6? document.getElementById(this.overID) : document.all[ this.overID ]
		
	}
	
	function reposition() {
		this.init()
		this.setLeft()
		this.setTop()
		//if (this.ExitPoly!=null)this.ExitPoly.move(this.left,this.top)
	}

	function hidebox(){
		if (this.ie4||this.ns6)
			this.crossobj.style.visibility="hidden"
		else if (this.ns4)
			document.showimage.visibility="hide"
		if(document.telsuche) document.telsuche.kategorie.style.visibility="visible";
		activeObject=null
	}
	
	
	
	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 showbox() {
		closeAllBoxes()
		this.reposition()
		
		this.crossobj.style.left=this.left+offsetx
		this.crossobj.style.top=this.top+offsety
		
		//--- falls Bildschirmgrösse zu klein für Infobox -> Positionierung der Infobox an rechten Rand
		var screenWidth= getScreenWidth()
		
		if( (parseInt(this.crossobj.style.left)+this.infoBoxWidth) > screenWidth)
			this.crossobj.style.left=screenWidth-this.infoBoxWidth-15
		//---
		
		if(document.telsuche) document.telsuche.kategorie.style.visibility="hidden";
		if (this.ie4||this.ns6) {
			this.crossobj.style.visibility="visible"
		}
		else if (this.ns4)
			document.showimage.visibility="show"
		activeObject=this
	}
	
	
	
	function setLeft() {
		parentObj=this.eventobj.offsetParent
		leftPos=this.eventobj.offsetLeft
		
		while(parentObj != null) {
			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) ) {
				/*nix*/
		}
		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()
	}
	activeObject=null
	return true 
}

var activeObject=null
function getMouse(){
	mouseX=browser.mouseX
	mouseY=browser.mouseY
	if (activeObject!=null){
		if (activeObject.ExitPoly!=null) {
			
					if (activeObject.ExitPoly.inside(mouseX-activeObject.left-activeObject.offsetx,mouseY-activeObject.top-activeObject.offsety)){
						activeObject.hidebox()
						closeAllBoxes()
						
					}
				
			}
	}
}

browser.addMouseMoveEvent("getMouse")