/*##################################################################
Mouseover v 2.1
Mouseover mit einfachem text

//	<script language="JavaScript" type="text/javascript" src='./amtool/script/mouseover.js'>
//	<!--
//
//	//-->
//	</script>

* onmouseover=\"showTextMouseOver('mytext');\"  onmouseout=\"hideTextMouseOver();\" onmousemove=\"setTextPosition();\"
* formatierbar ueber class container oder mouseover

oder beliebigem inhalt

* onmouseover="showMouseOver('span_xy');" onmouseout="hideMouseOver('span_xy')" onmousemove="setPosition('span_xy')"
* <span class='overtextspan' id="span_xy" style="position:absolute;top:-400px;left:-700px;z-index:99;min-width:50px;max-width:200px;"></span>

/*##################################################################
## CHANGELOG
##################################################################*/
/*
2008_06_11 [ 11:00:38 ]
leere id´s ohne element führten im IE zu einer Fehlermeldung
*/

/*##################################################################
## globals
##################################################################*/
var poppos="ro";
var dim=0;
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE){document.captureEvents(Event.MOUSEMOVE)};
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
//	alternative
//	document.onmousemove = getCoordinate;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;
var lasttempX = 0;
var lasttempY = 0;

var mousexdir="";
var mouseydir="";

// jeweils die aktuellen ecken des elements
var positions=new Array();
positions["x1"]=0;
positions["x2"]=0;
positions["y1"]=0;
positions["y2"]=0;

var dim=new Array();
dim["wwidth"]=0;
dim["wheight"]=0;
// fuer mousecapture
var mosX = 0;
var mosY = 0;

/*##################################################################
## 
##################################################################*/
function getWindowDim()
{
	if (IE)
	{
		// ie nicht standartconform
		dim["wwidth"]=document.body.clientWidth;
		dim["wheight"]=document.body.clientHeight;
		// ie standartconform
		if(dim["wwidth"]<1&&dim["wheight"])
		{
			dim["wwidth"]=document.documentElement.clientWidth;
			dim["wheight"]=document.documentElement.clientHeight;
		}
	}
	else
	{
		// andere browser
		dim["wwidth"]=window.innerWidth;
		dim["wheight"]=window.innerHeight;
	}
	return dim;
}

/*##################################################################
##	Main function to retrieve mouse x-y pos.s
##	funktionierte nicht wenn scrollbarer innenbereich
##################################################################*/
function getMouseXY(e)
{
	if(lasttempX!=tempX){lasttempX=tempX;}
	if(lasttempY!=tempY){lasttempY=tempY;}
	if (IE)
	{
		// grab the x-y pos.s if browser is IE
		tempX = event.clientX + window.document.body.scrollLeft;
		tempY = event.clientY + window.document.body.scrollTop;
	}
	else
	{
		// grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	// catch possible negative values in NS4
	if (tempX < 0)
	{
		tempX = 0;
	}
	if (tempY < 0)
	{
		tempY = 0;
	}
	return true
}

/*##################################################################
## mouseposition anhand von mouseevents
##################################################################*/
// diese funktion geht auch
//<!-- start testausgabe -->
//<div id="dx">xxx</div>
//<div id="jumper" style="width:30;height:40;background-color:#DE3030;z-index:10;position:absolute"></div>
//<!-- end testausgabe -->
function getCoordinate(event)
{
	if (!event)
	event = window.event;
	mosX = event.clientX + document.body.scrollLeft ;
	mosY = event.clientY + document.body.scrollTop;
	// http://www.xploredotnet.blogspot.com/2007/07/get-mouse-position-using-javascript.html
	//clientX Property Sets or retrieves the x-coordinate of the mouse
	//pointer's position relative to the client area of the window,
	//excluding window decorations and scroll bars
	//scrollLeft Property Sets or retrieves the distance between the
	//left edge of the object and the leftmost portion of the content
	//currently visible in the window.
	document.title = "(X Co-Ordinate » "+ mosX +") ( "+"Y Co-ordinate » " +mosY+")";
	document.getElementById('dx').innerHTML = "Mouse X  » "+mosX+"<br>"+"Mouse Y  » "+mosY;
	setJumper();
	return true;
}

/*##################################################################
## testausgabe
##################################################################*/
function setJumper()
{
	if (document.getElementById)
	{
		document.getElementById("jumper").style.left  = mosX + "px";
		document.getElementById("jumper").style.top = mosY + "px";
	}
	else if (document.all)
	{
		document.all.jumper.style.left = mosX;
		document.all.jumper.style.top = mosY;
	}
}


/*##################################################################
## 
##################################################################*/
function toggle(list,pos)
{
	if(!pos)
	{
		poppos="lo";
	}
	else
	{
		poppos=pos;
	}
	var listElementStyle=document.getElementById(list).style;
	setPosition(list);
	if (listElementStyle.visibility=="visible")
	{
		listElementStyle.visibility="hidden";
	}
	else
	{
		listElementStyle.visibility="visible";
		aktiv = window.setTimeout("hideMouseOver(\""+list+"\")", 8000);
	}
}

/*##################################################################
## 
##################################################################*/
function showMouseOver(list,pos)
{
	if(!document.getElementById(list))
	{
		return null;
	}	
	if(!pos)
	{
		poppos="ro";
	}
	else
	{
		poppos=pos;
	}
		var listElementStyle=document.getElementById(list).style;
		setPosition(list);
		listElementStyle.visibility="visible";
		aktiv = window.setTimeout("hideMouseOver(\""+list+"\")", 8000);
}

/*##################################################################
## 
##################################################################*/
function hideMouseOver(list)
{
	if(!document.getElementById(list))
	{
		return null;
	}	
	var listElementStyle=document.getElementById(list).style;
	document.getElementById(list).style.top="-900px";
	document.getElementById(list).style.left="-900px";
	listElementStyle.visibility="hidden";
	window.clearTimeout(aktiv);
}

/*##################################################################
## 
##################################################################*/
function setPosition(list)
{
	if(!document.getElementById(list))
	{
		return null;
	}	
	var testtop=0;
	var listElementHight=document.getElementById(list).offsetHeight;
	var listElementWidth=document.getElementById(list).offsetWidth;
	var mousex=tempX;
	var mousey=tempY;
//	grundpositionen der box auf mouse 0 0
//	positions["x1"]=mousex; positions["y1"]=mousey;
//	grundpositionen der box lo
	positions["x1"]=mousex-listElementWidth;
	positions["y1"]=mousey-listElementHight;
	positions["x2"]=mousex;
	positions["y2"]=mousey;
	poppos=elementInsideCheck(positions);

	switch (poppos) 
	{
		case "lo":
		// default
		positions["x1"]=mousex-5-listElementWidth;
		positions["y1"]=mousey-listElementHight;
		break;

		case "ru":
		positions["x1"]=mousex+5;
		positions["y1"]=mousey;
		break;

		case "lu":
		positions["x1"]=mousex-5-listElementWidth;
		positions["y1"]=mousey;
		break;

		case "ro":
		positions["x1"]=mousex+5;
		positions["y1"]=mousey-listElementHight;
		break;

		/*
		default:

		break;
		*/
	}
//	setze rechte untere ecke
	positions["x2"]=positions["x1"]+listElementWidth;
	positions["y2"]=positions["y1"]+listElementHight;
	document.getElementById(list).style.left=positions["x1"]+"px";
	document.getElementById(list).style.top=positions["y1"]+"px";
}

/*##################################################################
## 
##################################################################*/
function showTextMouseOver(mytext,pos)
{
	if(mytext!='')
	{
		//alert(document.getElementsById(this));
		//referenzierungDeinesObjekts.title='neuer Titel-Text';
		// alt bzw title => unset
		// <a href="javascript:alert(document.Anna.border)">
		// document.getElementById("container").setAttribute("alt", "TEXT");
		//document.getElementsByTagName("h1")[0].setAttributeNode(Ausrichtung);
		mytext = nl2br_12(mytext);
		mytext = mytext.replace(/<br \/>/g, '\n\r');
		document.getElementById("container").firstChild.nodeValue=mytext;
		showMouseOver('mouseover',pos);
	}
}

/*##################################################################
## 
##################################################################*/
function setTextPosition()
{
	setPosition('mouseover');
}

/*##################################################################
## 
##################################################################*/
function hideTextMouseOver()
{
	hideMouseOver('mouseover');
}

/*##################################################################
## 
##################################################################*/
function getScrollPos()
{
	var spx,spy;
	scrollpos=new Array();
	if (self.pageYOffset) // all except Explorer
	{
		scrollpos["x"] = self.pageXOffset;
		scrollpos["y"] = self.pageYOffset;

	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		// Explorer 6 Strict
		scrollpos["x"] = document.documentElement.scrollLeft;
		scrollpos["y"] = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		// all other Explorers
		scrollpos["x"] = document.body.scrollLeft;
		scrollpos["y"] = document.body.scrollTop;
	}
	return scrollpos;
}

/*##################################################################
## 
##################################################################*/
function writeBox()
{
	document.writeln("<style type='text/css'>");
	document.writeln("<!--");
	document.writeln("#mouseover {");
//	die css datei eignet sich besser fuer diese formatierungen
//	document.writeln("/* Gestaltung */");
//	document.writeln("font-family: Arial, Helvetica, sans-serif;");
//	document.writeln("width:150px;");
	document.writeln("position:absolute;");
	document.writeln("top:-400px;");
	document.writeln("left:-700px;");
	document.writeln("visibility:hidden;");
	document.writeln("z-index:100;");
	document.writeln("}");
// 	die css datei eignet sich eigentlich besser fuer diese formatierungen
	document.writeln("#container {");
	document.writeln("font-family: Arial, Helvetica, sans-serif;");
	document.writeln("font-size: 11px;");
	document.writeln("color: #252525;");
	document.writeln("font-weight: bold;");
	/*
	document.writeln("min-width:50px;");
	document.writeln("max-width:200px;");
	document.writeln("[if IE]");
	document.writeln("	width:150px;");
	document.writeln("[endif]");
	*/
	document.writeln("padding:4px;");
	document.writeln("border : 1px solid #666666;");
	document.writeln("background-color:#FFFF80;");
	document.writeln("}");
	document.writeln("-->");
	document.writeln("</style>");
	document.writeln("	");
	document.writeln("<div id='mouseover' class='mouseover'>");
	document.writeln("	<pre id='container' class='container' style='white-space:pre;'>Mouseovertext</pre>");
//	document.writeln("	<span id='container' class='container' >Mouseovertext</span>");
	document.writeln("</div>");
//	document.writeln("<table width='50' height='100'><tr><td>");
//	document.writeln("</td></tr></table>");

}	

writeBox();

/*##################################################################
## hilfsfunktionen
##################################################################*/
function elementInsideCheck(boxinfo)
{
	// position wird neu bestimmt falls links oder oben nicht genug platz
	var xdir="l";
	var ydir="o";
	if(boxinfo["x1"]<1)
	{
		xdir="r";
	}
	if(boxinfo["y1"]<1)
	{
		ydir="u";
	}
	var newdir = xdir+ydir;
	return newdir;
}

// javascript 1_2
function nl2br_12(str)
{
	if(typeof(str)=="string")
	{
		return str.replace(/(\r\n)|(\n\r)|\r|\n|<br>/g,"<br />");
	}
	else
	{
		return str;
	}
}

// javascript 1_0
function nl2br_10(s)
{
	s+="";
	r="";
	c="";
	while(s.length)
	{
		if(s.substr(0,1)=="\n")
		{
			if(c!="\r") r+="<BR>";
		}
		else if(s.substr(0,1)=="\r")
		{
			if(c!="\n")
			{
				r+="&ltBR>";
			}
		}
		else
		{
			r+=s.substr(0,1);
		}
	c=s.substr(0,1);
	s=s.substr(1,s.length-1);
	}
return r;
}

/*##################################################################
## misc stuff
##################################################################*/



// Link
// dirs are
//	<a href="http://www.annen-media.de" target="_blank" onmouseover="showMouseOver('mouseover','ro');" onmouseout="hideMouseOver('mouseover')" onmousemove="setPosition('mouseover')">
//		<img src="Bilder/am.gif" width="168" height="59" vspace="10" border="0">
//	</a>

/**
* Ab hier folgt ein einfaches Text mouseover
* onmouseover=\"showTextMouseOver('mytext');\"  onmouseout=\"hideTextMouseOver();\" onmousemove=\"setTextPosition();\"
* formatierbar ueber class container oder mouseover
*/

// css part
//	<style type="text/css">
//		<!--
//		#mouseover {
//		/* Gestaltung */
//		font-family: Arial, Helvetica, sans-serif;
//		font-size: 13px;
//		color: #2D7215;
//		font-weight: bold;
//		border : 1px solid #666666;
//		/*background-color:#202d7d;*/
//		/* Startposition */
//		position:absolute;
//		top:-400px;
//		left:-700px;
//		visibility:hidden;
//		padding:2px;
//		z-index:100;
//		}
//		-->
//	</style>

// HTML Mouseover Part
//	<table border='0' cellspacing='0' cellpadding='0' id="mouseover" >
//		<tr>
//			<td align='center'>
//				noch keine Vereinswebseite<br />
//				schnell zu Annen.Media
//			</td>
//		</tr>
//	</table>

// geht auch
/*
	<a href="http://www.annen-media.de" target="_blank" onmouseover="showMouseOver('mouseover','ro');" onmouseout="hideMouseOver('mouseover')" onmousemove="setPosition('mouseover')">
	<img src="..{STYLEIMGPATH}am.gif" vspace="10" border="0" />
	</a>
*/

//var breit = screen.width;
//var hoch = screen.height;

//function fenster() {
//	if(document.all) {
//		breit=document.body.clientWidth;
//		hoch=document.body.clientHeight;
//	}
//	if (document.layers) {
//		breit = window.innerWidth;
//		hoch = window.innerHeight;
//	}
//	alert("Der verfuegbare Anzeigenbereich\nBreite: "+breit+"  Hoehe: "+hoch);
//}
//
//function aufloesung() {
//	var breit = screen.width;
//	var hoch = screen.height;
//	alert("Die Aufloesung\nBreite: "+breit+"  Hoehe: "+hoch);
//}

//<a href="javascript:Position()">Y-Position</a>
//function Position ()
//{
////  alert("pageYOffset: " + window.pageYOffset + " Pixel");// geht nicht bei scrollbarem content
//  alert("y-Wert: " + self.screen.height);
//}

// nicht benutzt
//function getMouseDir()
//{
//	if(parseInt(lasttempX)<parseInt(tempX))
//	{
//		mousexdir="right";
//	}
//	else
//	{
//		mousxedir="left";
//	}
//	if(parseInt(lasttempY)<parseInt(tempY))
//	{
//		mouseydir="down";
//	}
//	else
//	{
//		mouseydir="up";
//	}
//	//alert(mousexdir + " " + mouseydir);
//}