//define universal reference to "staticcontent"
var crossobj= "";
var menuobj= "";
//define reference to the body object in IE
var iebody= "";

function init_ontop(){
	//define universal reference to "staticMenu" and "ontopmarker"
	crossobj=document.all? document.all.staticMenu : document.getElementById("staticMenu");
	menuobj=document.all? document.all.ontopmarker : document.getElementById("ontopmarker");
	menuobjfooter=document.all? document.all.ontopmarkerfooter : document.getElementById("ontopmarkerfooter");


	//define reference to the body object in IE
	iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	setInterval("positionit()",300);
	menuobj.style.height = "auto";
}

// returns offsetLeft and offsetRight of an object (absolut to the upper left corner of the side)
// var pos=findPos(posObj);
// alert(posObj.left + "   " + posObj.top); 
// because IE calculates offsetLeft of an object only to his parent
// we have to get all parents of the object and her offsetLefts
function findPos(obj) {
	var curleft = obj.offsetLeft || 0;
	var curtop = obj.offsetTop || 0;
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
	return {left:curleft,top:curtop};
}

function positionit(){
	//define universal dsoc left point
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
	//define universal dsoc top point
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;

	//if the user is using IE 4+ or Firefox/ NS6+
	if (document.all||document.getElementById){
		var pos=findPos(menuobj);
		var posfooter=findPos(menuobjfooter);
		var aleft = pos.left + 0 +"px";
		// jquery.positions.js to get height of static menu
		var staticMenuHeight = $('#staticMenu').outerHeight();
		// top + höhe ontopmarker + abstand zu menu
		var atop = pos.top + 30 + "px";
		// ontopmarker ist außerhalb des sichtbaren Bereiches: staticMenu am oberen Fensterrand positionieren
		// top + höhe ontopmarker + dsoc top point
		// dsoctop ppint + abstand menu
		if ((pos.top + 27 - dsoctop ) < 0 ) atop = dsoctop  + 10 + "px";
		// staticMenu(height) überragt Fußzeile der Seite: staticMenu oberhalb der Fußzeile positonieren
		if ((dsoctop + staticMenuHeight) > posfooter.top) atop = posfooter.top - staticMenuHeight - 10 + "px"
		crossobj.style.left=aleft;
		crossobj.style.top=atop;
	}
}
