
function getAbsPos(o, p)
{
	var i = 0;
	while (o != null)
	{
		i += o["offset" + p];
		o = o.offsetParent;
	}
	return i;
}
function getAbsPosWithLevels(o, p, l)
{
	var i = 0;
	while ((o != null) && (l --))
	{
		i += o["offset" + p];
		o = o.offsetParent;
	}
	return i;
}
//simple class for point
function Point(x, y)
{
	this.x		= x;
	this.y		= y;
}
function rectangle()
{
  this.top	= 0;
  this.bottom	= 0;
  this.left	= 0;
  this.right	= 0;
  
  //class member - checks whether given point is in current rectangle
  this.IsPointIn = function (point)
  {
	var is_in_rectangle = true;
	if ((point.x > this.right + 5) || (point.x < this.left - 5) || (point.y > this.bottom + 5) || (point.y < this.top - 5))
	{
		is_in_rectangle = false;
	}
	
	return is_in_rectangle;
  }
}


var m_rectDropDown = new rectangle();
var m_rectTab = new rectangle();
var point;
var m_do_mouse_track = false;

function hideAll()
{
    $("#prinav_dropdown").hide();
    $("#prinav_dropdown_service").hide();
    $(".prinav_dropdown_content").hide();
    $("#prinav_on").hide();
    $("#prinav_on_serv").hide();
    jQuery("#prinav_dropdown td#pn_middle").html('');
    jQuery("#prinav_dropdown_service td#ser_middle").html('');
}

$(document).ready(function(){
		/*checkMerkzettel();
		if(jQuery('div#block_subtabs a.lh30').size() > 0) {
			jQuery('div#block_subtabs a.lh30').click(checkMerkzettel);
		}*/
    //if(querySt('test') == undefined) {
        jQuery("#prinav_dropdown_service td#ser_middle").html('');
        $("body").mousemove(function(e){
            if (m_do_mouse_track)
            {
    		    if (!e) var e = window.event;
                point = new Point(e.pageX, e.pageY);
                if ((!m_rectDropDown.IsPointIn(point)) && (!m_rectTab.IsPointIn(point)))
    		    {
    			    hideAll();
    			    m_do_mouse_track = false;
    		    }
            }
        });
    
        $("div#nav_main a").mouseover(function(){
            hideAll();
            
            //get the Id of current PriNav DropDown to display
            var show_id = $(this).parent().attr("show_id");
            
            var container_id = $(this).parent().attr("container_id");
            if ((container_id == "") || (container_id ==null))
            {
                container_id = "prinav_dropdown";
            }
            var tab_stubb_id = $(this).parent().attr("tab_stubb_id");
            if ((tab_stubb_id == "") || (tab_stubb_id ==null))
            {
                tab_stubb_id = "prinav_on";
            }
            var container = $("#" + container_id);
            var content = $("#" + show_id);
            var tab_stubb = $("#" + tab_stubb_id);
        
            //get coordinates of left top corner of current Tab
            var nLeft = getAbsPos($(this).parent().get(0), "Left");
            var nTop = getAbsPos($(this).parent().get(0), "Top");
        
            //get offset to move left PriNav DropDown
            var nOffset = $(this).parent().attr("offset");
            if ((nOffset == "") || (nOffset == null))
            {//default offset is -20
                nOffset = -20;
            }
            else
            {
                nOffset = parseInt(nOffset);
            }
            //position current PriNav DropDown
        
            var nWidth = $(this).parent().get(0)["offsetWidth"];
            var nHeight = $(this).parent().get(0)["offsetHeight"];
            
            container.css("left", (nLeft + nOffset) + "px");
            container.css("top", (nTop + nHeight) + "px");
            
            tab_stubb.hide();
            tab_stubb.show();
            tab_stubb.css("left", nLeft + "px");
            tab_stubb.css("top", (nTop - 7) + "px");
            tab_stubb.css("width", nWidth + "px");
            tab_stubb.css("height", "42px");
            tab_stubb.find(".prinav_on_inner").css("width", nWidth + "px");
            tab_stubb.find(".prinav_on_inner").css("height", "42px");
            tab_stubb.find(".img_prinav_on_left").css("width", (nWidth - 8) + "px");
        
            tab_stubb.find(".prinav_on_inner span").html(jQuery(this).clone());
            
            m_do_mouse_track = true;
            
            m_rectDropDown.left = nLeft + nOffset;
            m_rectDropDown.top = 128;
            m_rectDropDown.right = m_rectDropDown.left + container.get(0)["offsetWidth"];
            m_rectDropDown.bottom = m_rectDropDown.top + container.get(0)["offsetHeight"];
        
            m_rectTab.left = nLeft;
            m_rectTab.top = nTop - 7;
            m_rectTab.right = m_rectTab.left + tab_stubb.get(0)["offsetWidth"];
            m_rectTab.bottom = m_rectTab.top + tab_stubb.get(0)["offsetHeight"];
        
            //Display current PriNav DropDown
            var show_html = $(this).next().html();
            if((show_html == '') || (show_html == undefined) || (show_html == null)) return;
            //Display current PriNav DropDown
            if($(this).next().attr('id') != 'tblService') {
       		container.find("td#pn_middle").html(show_html);
            } else {
       	    	container.find("td#ser_middle").html(show_html);
            }
            container.show();
            content.show();
        
            m_rectDropDown.left = nLeft + nOffset;
            m_rectDropDown.top = 128;
            m_rectDropDown.right = m_rectDropDown.left + container.get(0)["offsetWidth"];
            m_rectDropDown.bottom = m_rectDropDown.top + container.get(0)["offsetHeight"];
        
            m_rectTab.left = nLeft;
            m_rectTab.top = nTop - 7;
            m_rectTab.right = m_rectTab.left + tab_stubb.get(0)["offsetWidth"];
            m_rectTab.bottom = m_rectTab.top + tab_stubb.get(0)["offsetHeight"];
        
            return false;
        });/*
    } else {
        alert("Attension: Testmode for menu is on");
        jQuery("#prinav_dropdown_service td#ser_middle").html('');
        $("body").mousemove(function(e){
            if (m_do_mouse_track)
            {
    		    if (!e) var e = window.event;
            	  point = new Point(e.pageX, e.pageY);
                if ((!m_rectDropDown.IsPointIn(point)) && (!m_rectTab.IsPointIn(point)))
    		    {
    			    hideAll();
    			    m_do_mouse_track = false;
    		    }
            }
        });
    
        $("div#nav_main a").mouseover(function(){
            hideAll();
            
            //get the Id of current PriNav DropDown to display
            var show_id = $(this).parent().attr("show_id");
            
            var container_id = $(this).parent().attr("container_id");
            if ((container_id == "") || (container_id ==null))
            {
                container_id = "prinav_dropdown";
            }
            var tab_stubb_id = $(this).parent().attr("tab_stubb_id");
            if ((tab_stubb_id == "") || (tab_stubb_id ==null))
            {
                tab_stubb_id = "prinav_on";
            }
            var container = $("#" + container_id);
            var content = $("#" + show_id);
            var tab_stubb = $("#" + tab_stubb_id);
        
            //get coordinates of left top corner of current Tab
            var nLeft = getAbsPos($(this).parent().get(0), "Left");
            var nTop = getAbsPos($(this).parent().get(0), "Top");
        
            //get offset to move left PriNav DropDown
            var nOffset = $(this).parent().attr("offset");
            if ((nOffset == "") || (nOffset == null))
            {//default offset is -20
                nOffset = -20;
            }
            else
            {
                nOffset = parseInt(nOffset);
            }
            //position current PriNav DropDown
        
            var nWidth = $(this).parent().get(0)["offsetWidth"];
            var nHeight = $(this).parent().get(0)["offsetHeight"];
            
            container.css("left", (nLeft + nOffset) + "px");
            container.css("top", (nTop + nHeight) + "px");
            
            tab_stubb.hide();
            tab_stubb.show();
            tab_stubb.css("left", nLeft + "px");
            tab_stubb.css("top", (nTop - 7) + "px");
            tab_stubb.css("width", nWidth + "px");
            tab_stubb.css("height", "42px");
            tab_stubb.find(".prinav_on_inner").css("width", nWidth + "px");
            tab_stubb.find(".prinav_on_inner").css("height", "42px");
            tab_stubb.find(".img_prinav_on_left").css("width", (nWidth - 8) + "px");
        
            tab_stubb.find(".prinav_on_inner span").html('<a href="' + $(this).parent().find("A").attr('href') + '">' + $(this).parent().find("A").html() + '</a>');
            
            m_do_mouse_track = true;
            
            m_rectDropDown.left = nLeft + nOffset;
            m_rectDropDown.top = 128;
            m_rectDropDown.right = m_rectDropDown.left + container.get(0)["offsetWidth"];
            m_rectDropDown.bottom = m_rectDropDown.top + container.get(0)["offsetHeight"];
        
            m_rectTab.left = nLeft;
            m_rectTab.top = nTop - 7;
            m_rectTab.right = m_rectTab.left + tab_stubb.get(0)["offsetWidth"];
            m_rectTab.bottom = m_rectTab.top + tab_stubb.get(0)["offsetHeight"];
        
            //Display current PriNav DropDown
            var show_html = $(this).next().html();
            if((show_html == '') || (show_html == undefined) || (show_html == null)) return;
            //Display current PriNav DropDown
            if($(this).next().attr('id') != 'tblService') {
        	container.find("td#pn_middle").html(show_html);
            } else {
            	container.find("td#ser_middle").html(show_html);
            }
            container.show();
            content.show();
        
            m_rectDropDown.left = nLeft + nOffset;
            m_rectDropDown.top = 128;
            m_rectDropDown.right = m_rectDropDown.left + container.get(0)["offsetWidth"];
            m_rectDropDown.bottom = m_rectDropDown.top + container.get(0)["offsetHeight"];
        
            m_rectTab.left = nLeft;
            m_rectTab.top = nTop - 7;
            m_rectTab.right = m_rectTab.left + tab_stubb.get(0)["offsetWidth"];
            m_rectTab.bottom = m_rectTab.top + tab_stubb.get(0)["offsetHeight"];
        
            return false;
        });
     }*/
});

function modifyUrl(obj)
{
	if((obj.size) && (obj.size() > 0)) {
		var href = obj.attr('href');
		if(href.indexOf('https:') > -1) {
			href = "http:" + href.substring(6);
			obj.attr('href', href);
		}
	}
	return true;
}/*

function checkMerkzettel() {
	if(jQuery('div.nomerkzettel a').size() > 0) {
		if(jQuery('div.nomerkzettel').attr('id') != 'itemMerkzettel') {
			jQuery('div.nomerkzettel a').attr('id', 'mzlink');
			var arrCookies = document.cookie.split(';');
			var cookieMissing = true;
			for(var i = 0; i < arrCookies.length; i++) {
				var arrCookie = arrCookies[i].split('=');
				if((arrCookie[0] == ' merkzettel') && (arrCookie[1] != '')) {
					jQuery('div.nomerkzettel a').html(jQuery('div.nomerkzettel a').html().replace(/\(.*\)/g, '')+' <span id="spMZCnt">(' + unescape(arrCookie[1]).split(',').length + ')</span>');
					jQuery('div.nomerkzettel').addClass('merkzettel');
					jQuery('div.nomerkzettel').removeClass('nomerkzettel');
					cookieMissing = false;
					break;
				} else if(arrCookie[0] == ' merkzettel') {
					jQuery('div.nomerkzettel a').html(jQuery('div.nomerkzettel a').html()+' <span id="spMZCnt">(0)</span>');
					cookieMissing = false;
				}
			}
			if(cookieMissing) {
				jQuery('div.nomerkzettel a').html(jQuery('div.nomerkzettel a').html()+' <span id="spMZCnt">(0)</span>');
			}
		}
	} else if(jQuery('div.merkzettel a').size() > 0) {
		if(jQuery('div.merkzettel').attr('id') != 'itemMerkzettel') {
			jQuery('div.merkzettel a').attr('id', 'mzlink');
			var arrCookies = document.cookie.split(';');
			var cookieMissing = true;
			for(var i = 0; i < arrCookies.length; i++) {
				var arrCookie = arrCookies[i].split('=');
				if((arrCookie[0] == ' merkzettel') && (arrCookie[1] != '')) {
					jQuery('div.merkzettel a').html(jQuery('div.merkzettel a').html().replace(/\(.*\)/g, '')+' <span id="spMZCnt">(' + unescape(arrCookie[1]).split(',').length + ')</span>');
					cookieMissing = false;
					break;
				} else if(arrCookie[0] == ' merkzettel') {
					jQuery('div.merkzettel a').html(jQuery('div.merkzettel a').html()+' <span id="spMZCnt">(0)</span>');
					cookieMissing = false;
				}
			}
			if(cookieMissing) {
				jQuery('div.nomerkzettel a').html(jQuery('div.nomerkzettel a').html()+' <span id="spMZCnt">(0)</span>');
			}
		}
	}
}*/