/* Script by: www.jtricks.com
 * Version: 20071017
 * Latest version:
 * www.jtricks.com/javascript/navigation/floating.html
 */
var floatingMenuId = 'floatdiv';
var userNav = 0;
var navSchalter = 1;
var usermode=""
function IEVersion(){
	var _n=navigator,_w=window,_d=document;
	var version="NA";
	var na=_n.userAgent;
	var ieDocMode="NA";
	var ie8BrowserMode="NA";
	// Look for msie and make sure its not opera in disguise
	if(/msie/i.test(na) && (!_w.opera)){
		// also check for spoofers by checking known IE objects
		if(_w.attachEvent && _w.ActiveXObject){		
			// Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7
			version = (na.match( /.+ie\s([\d.]+)/i ) || [])[1];
			// Its IE 8 pretending to be IE 7 or in compat mode		
			if(parseInt(version)==7){				
				// documentMode is only supported in IE 8 so we know if its here its really IE 8
				if(_d.documentMode){
					version = 8; //reset? change if you need to
					// IE in Compat mode will mention Trident in the useragent
					if(/trident\/\d/i.test(na)){
						ie8BrowserMode = "Compat Mode";
					// if it doesn't then its running in IE 7 mode
					}else{
						ie8BrowserMode = "IE 7 Mode";
					}
				}
			}else if(parseInt(version)==8){
				// IE 8 will always have documentMode available
				if(_d.documentMode){ ie8BrowserMode = "IE 8 Mode";}
			}
			// If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions			
			ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode=="CSS1Compat") ? 7 : 5;//default to quirks mode IE5				   			
		}
	}
        usermode = ie8BrowserMode;
				 
	return {
		"UserAgent" : na,
		"Version" : version,
		"BrowserMode" : ie8BrowserMode,
		"DocMode": ieDocMode
	}			
}
IEVersion()


var floatingMenu =
{
    targetX: 'center',
    targetY: 0,

    hasInner: typeof(window.innerWidth) == 'number',
    hasElement: typeof(document.documentElement) == 'object'
        && typeof(document.documentElement.clientWidth) == 'number',

    menu:
        document.getElementById
        ? document.getElementById(floatingMenuId)
        : document.all
          ? document.all[floatingMenuId]
          : document.layers[floatingMenuId]
};

floatingMenu.move = function ()
{
    floatingMenu.menu.style.left = floatingMenu.nextX + 'px';
    floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
}

floatingMenu.computeShifts = function ()
{
    var de = document.documentElement;

    floatingMenu.shiftX =  
        floatingMenu.hasInner  
        ? pageXOffset  
        : floatingMenu.hasElement  
          ? de.scrollLeft  
          : document.body.scrollLeft;  
    if (floatingMenu.targetX < 0)
    {
        floatingMenu.shiftX +=
            floatingMenu.hasElement
            ? de.clientWidth
            : document.body.clientWidth;
    }

    floatingMenu.shiftY = 
        floatingMenu.hasInner
        ? pageYOffset
        : floatingMenu.hasElement
          ? de.scrollTop
          : document.body.scrollTop;
    if (floatingMenu.targetY < 0)
    {
        if (floatingMenu.hasElement && floatingMenu.hasInner)
        {
            // Handle Opera 8 problems
            floatingMenu.shiftY +=
                de.clientHeight > window.innerHeight
                ? window.innerHeight
                : de.clientHeight
        }
        else
        {
            floatingMenu.shiftY +=
                floatingMenu.hasElement
                ? de.clientHeight
                : document.body.clientHeight;
        }
    }
}

floatingMenu.calculateCornerX = function()
{
    if (floatingMenu.targetX != 'center')
        return floatingMenu.shiftX + floatingMenu.targetX;

    var width = parseInt(floatingMenu.menu.offsetWidth);

    var cornerX =
        floatingMenu.hasElement
        ? (floatingMenu.hasInner
           ? pageXOffset
           : document.documentElement.scrollLeft) + 
          (document.documentElement.clientWidth - width)/2
        : document.body.scrollLeft + 
          (document.body.clientWidth - width)/2;

    var hwidth = Math.round(window.innerWidth / 2)
    var diff   = 0

    if (userNav == 0)
      {
         var hilfe = document.getElementById('slidepfeil');
         hilfe.src = 'bilder2010/pfeil_runter.gif';
      }
    else
      {
         var hilfe = document.getElementById('slidepfeil');
         hilfe.src = 'bilder2010/links.gif';
      }

   
    if (hwidth < 600)
      {
         if (navSchalter == 1)
           {
             if (userNav == 0)
               {
                 var hilfe = document.getElementById('slidepfeil');
                 hilfe.src = 'bilder2010/pfeil_runter.gif';
                 Effect.toggle('floatdiv','appear', {duratiom:0.1});
                 navSchalter = 0;
               }
           }
      }
    else
      {
        if (navSchalter == 0)
           {
             if (userNav == 0)
               {
                 var hilfe = document.getElementById('slidepfeil');
                 hilfe.src = 'bilder2010/links.gif';
                 Effect.toggle('floatdiv','appear', {duratiom:0.1});
                 navSchalter = 1;
               }
           }
      }
    // document.write(navigator.appCodeName+' '+navigator.appName+' '+navigator.appVersion);
    
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
  
       hwidth = Math.round(document.body.clientWidth /2)
       if (navigator.appVersion.substring(22,23) == '6')
       {
         if((hwidth-133) < 557)
         { 
           return cornerX + 80
         }     
         return cornerX+(hwidth-557);
       }
       if (navigator.appVersion.substring(22,23) == '7')
       {
         if ( (usermode) == "Compat Mode")
         {           
           if((hwidth-133) < 557)
           { 
             diff = 557 - hwidth
             return cornerX - (480-diff);
           }     
           return cornerX - 557;
         }
         if((hwidth-133) < 557)
         { 
           return cornerX + 80
         }     
         return cornerX+(hwidth-557);
       }
       if (navigator.appVersion.substring(22,23) == '8')
       {
           if((hwidth-133) < 557)
           { 
             diff = 557 - hwidth
             return cornerX - (480-diff);
           }     
           return cornerX - 557;
       }
    }
    else
    {
         if((hwidth-133) < 557)
         { 
           diff = 557 - hwidth
           return cornerX - (480-diff);
         }     
         return cornerX - 557;
    }
};

floatingMenu.calculateCornerY = function()
{
    if (floatingMenu.targetY != 'center')
    {
      if (navigator.appName == 'Microsoft Internet Explorer')
      {
         if (navigator.appVersion.substring(22,23) == '6')
         {
           return floatingMenu.shiftY + floatingMenu.targetY + 100;
         }
         if (navigator.appVersion.substring(22,23) == '7')
         {
           return floatingMenu.shiftY + floatingMenu.targetY + 100;
         }
         if (navigator.appVersion.substring(22,23) == '8')
         {
           return floatingMenu.shiftY + floatingMenu.targetY + 100;
         }
      }
      else
      {
         return floatingMenu.shiftY + floatingMenu.targetY + 100;
      }
      return floatingMenu.shiftY + floatingMenu.targetY;
    }

    var height = parseInt(floatingMenu.menu.offsetHeight);

    // Handle Opera 8 problems
    var clientHeight = 
        floatingMenu.hasElement && floatingMenu.hasInner
        && document.documentElement.clientHeight 
            > window.innerHeight
        ? window.innerHeight
        : document.documentElement.clientHeight

    var cornerY =
        floatingMenu.hasElement
        ? (floatingMenu.hasInner  
           ? pageYOffset
           : document.documentElement.scrollTop) + 
          (clientHeight - height)/2
        : document.body.scrollTop + 
          (document.body.clientHeight - height)/2;

    if (navigator.appName == 'Microsoft Internet Explorer')
    {
       if (navigator.appVersion.substring(22,23) == '6')
       {
         return cornerY+100;
       }
       if (navigator.appVersion.substring(22,23) == '7')
       {
         return cornerY+100;
       }
       if (navigator.appVersion.substring(22,23) == '8')
       {
           return cornerY+100;
       }
    }
    else
    {
         return cornerY+100;
    }
    
    return cornerY
};

floatingMenu.doFloat = function()
{
    // Check if reference to menu was lost due
    // to ajax manipuations
    if (!floatingMenu.menu)
    {
        menu = document.getElementById
            ? document.getElementById(floatingMenuId)
            : document.all
              ? document.all[floatingMenuId]
              : document.layers[floatingMenuId];

        initSecondary();
    }

    var stepX, stepY;

    floatingMenu.computeShifts();

    var cornerX = floatingMenu.calculateCornerX();

    var stepX = (cornerX - floatingMenu.nextX) * .07;
    if (Math.abs(stepX) < .5)
    {
        stepX = cornerX - floatingMenu.nextX;
    }

    var cornerY = floatingMenu.calculateCornerY();

    var stepY = (cornerY - floatingMenu.nextY) * .07;
    if (Math.abs(stepY) < .5)
    {
        stepY = cornerY - floatingMenu.nextY;
    }

    if (Math.abs(stepX) > 0 ||
        Math.abs(stepY) > 0)
    {
        floatingMenu.nextX += stepX;
        var height = window.innerHeight;
        if(height >= 550)
        {
           floatingMenu.nextY += stepY;
        }
        else
        {
           floatingMenu.nextY = 10;
        }
 
        floatingMenu.move();
    }

    setTimeout('floatingMenu.doFloat()', 20);
};

// addEvent designed by Aaron Moore
floatingMenu.addEvent = function(element, listener, handler)
{
    if(typeof element[listener] != 'function' || 
       typeof element[listener + '_num'] == 'undefined')
    {
        element[listener + '_num'] = 0;
        if (typeof element[listener] == 'function')
        {
            element[listener + 0] = element[listener];
            element[listener + '_num']++;
        }
        element[listener] = function(e)
        {
            var r = true;
            e = (e) ? e : window.event;
            for(var i = element[listener + '_num'] -1; i >= 0; i--)
            {
                if(element[listener + i](e) == false)
                    r = false;
            }
            return r;
        }
    }

    //if handler is not already stored, assign it
    for(var i = 0; i < element[listener + '_num']; i++)
        if(element[listener + i] == handler)
            return;
    element[listener + element[listener + '_num']] = handler;
    element[listener + '_num']++;
};

floatingMenu.init = function()
{
    floatingMenu.initSecondary();
    floatingMenu.doFloat();
};

// Some browsers init scrollbars only after
// full document load.
floatingMenu.initSecondary = function()
{
    floatingMenu.computeShifts();
    floatingMenu.nextX = floatingMenu.calculateCornerX();
    floatingMenu.nextY = floatingMenu.calculateCornerY();
    floatingMenu.move();
}

if (document.layers)
    floatingMenu.addEvent(window, 'onload', floatingMenu.init);
else
{
    floatingMenu.init();
    floatingMenu.addEvent(window, 'onload',
        floatingMenu.initSecondary);
}