/***************************************************************
*
*  JavaScript DHTML layer menu
*
* $Id: jsfunc.layermenu.js,v 1.3.2.1 2005/08/22 14:14:30 masi Exp $
*
*
*
*  Copyright notice
*
*  (c) 1998-2003 Kasper Skårhøj
*  All rights reserved
*
*  This script is part of the TYPO3 tslib/ library provided by
*  Kasper Skårhøj <kasper@typo3.com> together with TYPO3
*
*  Released under GNU/GPL (see license file in tslib/)
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*  This copyright notice MUST APPEAR in all copies of this script
***************************************************************/

var RRV_x = 0; var RRV_y = 0; var RRV_w = 0;
var RRV_curItem = new Array();
var RRV_oldItem = new Array();
var RRV_oleItem = new Array();
var RRV_curItemX = new Array();
var RRV_curItemY = new Array();
var RRV_curItemWidth = new Array();
var RRV_curItemHeight = new Array();
var RRV_curLayer = new Array();
var RRV_curLayerX = new Array();
var RRV_curLayerY = new Array();
var RRV_curLayerWidth = new Array();
var RRV_curLayerHeight = new Array();
var RRV_menuOn = new Array();
var RRV_gap = new Array();

var RRV_hasBeenOver = new Array();
var RRV_doReset = new Array();
var RRV_lastKey = new Array();
var RRV_date = new Array();
var RRV_timeout = new Array();
var RRV_timeoutRef = new Array();
var RRV_date = new Date();
var RRV_timeout_count=0;
var RRV_timeout_pointers = new Array();

//Browser ermitteln
function RR_checkBrowser() {
  this.dom = (document.getElementById);
  // Ermittelt Version (selbst wenn Opera sich als Mozilla oder IE tarnt)
  if (op = (navigator.userAgent.indexOf("Opera") > -1))	{
    switch (parseInt(navigator.userAgent.substr(navigator.userAgent.indexOf("Opera") + 6)))	{
      case 5: case 6:
        this.op5 = true;	break;
      case 7: case 8:
        this.op7 = true;	break;
      default:
        this.op4 = true;	}	}
  this.konq = (navigator.userAgent.indexOf("Konq") > -1);
  this.ie4 = (document.all && !this.dom && !op && !this.konq);
  this.ie5 = (document.all && this.dom && !op && !this.konq);
  this.ie6 = (this.ie5);
  this.ns4 = (document.layers && !this.dom && !this.konq);
  this.ns5 = (!document.all && this.dom && !op && !this.konq);
  this.ns6 = (this.ns5);
  this.bw = (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.konq || op);

  return this;
}

bw = new RR_checkBrowser();

//NS4 resize fix.
if (document.layers) {
  scrX = innerWidth; scrY = innerHeight;
  onresize = function()	{ if (scrX != innerWidth || scrY != innerHeight)	{ history.go(0); } };
}

//Liefert Element zurück
function RR_getObjCss(obj) {
  return bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? document.layers[obj] : 0;
}

function RR_isObjCss(obj) {
  flag = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? document.layers[obj] : 0;
  if (flag)	{ return true; }
}

function RR_getObj(obj) {
  nest = "";
  this.el = bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest + "document." + obj) : document.getElementById(obj);
  this.css = bw.ns4 ? this.el : this.el.style;
  this.ref = bw.ns4 ? this.el.document : document;
  this.x = (bw.ns4||bw.op5) ? this.css.left : this.el.offsetLeft;
  this.y = (bw.ns4||bw.op5) ? this.css.top : this.el.offsetTop;
  this.absx = (bw.ns4||bw.op5) ? RR_absPos(this.css, "Left") : RR_absPos(this.el, "Left");
  this.absy = (bw.ns4||bw.op5) ? RR_absPos(this.css, "Top") : RR_absPos(this.el, "Top");
  this.height = (bw.ie4||bw.ie5||bw.ns6||bw.op7) ? this.el.offsetHeight : bw.ns4 ? this.ref.height : bw.op4 ? this.css.pixelHeight : 0;
  this.width = (bw.ie4||bw.ie5||bw.ns6||bw.op7) ? this.el.offsetWidth : bw.ns4 ? this.ref.width : bw.op4 ? this.css.pixelWidth : 0;

  return this;
}

function RR_absPos(el, which) {
  iPos = 0;
  while (el != null) {
    iPos += el["offset" + which];
    el = el.offsetParent; }
  return iPos;
} 

function RR_initLayers() {
  if (bw.ns4) { document.captureEvents(Event.MOUSEMOVE); }
  RR_timeout_func();
}

function RR_updateTime(WMid)	{
  RRV_date = new Date();
  RRV_timeout[WMid] = RRV_date.getTime();
}

function RR_doResetAll(WMid) {
  if (RRV_doReset[WMid]) {
    RRV_doReset[WMid] = false;
    RR_hideAll(WMid);	}
}

function RR_timeout_func()	{
  RRV_date = new Date();
  var stuff = "";
  for (var a = 0; a < RRV_timeout_count; a++)	{
    WMid = RRV_timeout_pointers[a];
    if (RRV_date.getTime() - RRV_timeout[WMid] > RRV_timeoutRef[WMid])	{	RR_doResetAll(WMid);	}	}

  window.setTimeout("RR_timeout_func();", 200);
}

function RR_resetAll(WMid) {
  if (!RRV_doReset[WMid]) {
    RR_updateTime(WMid);
    RRV_doReset[WMid] = true;	}
}

function RR_stopMove(WMid) {
  RRV_menuOn[WMid] = null;
}

function RR_doLev0(WMid, id) {
  RR_hideAll(WMid);
  if (RR_isObjCss("lev1" + id))	{
    RRV_menuOn[WMid] = RR_getObjCss("lev1" + id);
    RRV_menuOn[WMid].visibility = "visible";

    eval('RR' + WMid + '_doLev0(WMid, id)');
    eval('RR_doLev1(WMid, id)');

    var layerObj = RR_getObj("lev1" + id);
    RRV_curLayerHeight[WMid] = layerObj.height; RRV_curLayerWidth[WMid] = layerObj.width;
    RRV_curLayerX[WMid] = layerObj.x; RRV_curLayerY[WMid] = layerObj.y;
    RRV_curLayer[WMid] = "lev1" + id;
    var itemObj = RR_getObj("lev0" + id);
    RRV_curItemHeight[WMid] = itemObj.height; RRV_curItemWidth[WMid] = itemObj.width;
    RRV_curItemX[WMid] = itemObj.absx; RRV_curItemY[WMid] = itemObj.absy;
    RRV_hasBeenOver[WMid] = 0;
	}
}

function RR_doLev1(WMid, id) {
  //RR_hideAll(WMid);
  if (RR_isObjCss("lev2" + id))	{
    RRV_menuOn[WMid] = RR_getObjCss("lev2" + id);
    RRV_menuOn[WMid].visibility = "visible";

    eval('RR' + WMid + '_doLev1(WMid, id)');

    var layerObj = RR_getObj("lev2" + id);
    RRV_curLayerHeight[WMid] = layerObj.height; RRV_curLayerWidth[WMid] = layerObj.width;
    RRV_curLayerX[WMid] = layerObj.x; RRV_curLayerY[WMid] = layerObj.y;
    RRV_curLayer[WMid] = "lev2" + id; }
}

//Mausbewegung festhalten
function RR_getMouse(e) {
  RRV_x = (bw.ns4||bw.ns5) ? e.pageX : (bw.ie4||bw.op4) ? event.x : (event.x - 2) + document.body.scrollLeft;
  RRV_y = (bw.ns4||bw.ns5) ? e.pageY : (bw.ie4||bw.op4) ? event.y : (event.y - 2) + document.body.scrollTop;
}

function RR_mouseMoveEvaluate(WMid)	{
  if (RRV_gap[WMid] && RRV_curLayer[WMid] != null)	{
    if ((RRV_x + RRV_gap[WMid] - RRV_curLayerX[WMid] < 0 || 
        RRV_y + RRV_gap[WMid] - RRV_curLayerY[WMid] < 0 || 
        RRV_curLayerX[WMid] + RRV_curLayerWidth[WMid] + RRV_gap[WMid] - RRV_x < 0 || 
        RRV_curLayerY[WMid] + RRV_curLayerHeight[WMid] + RRV_gap[WMid] - RRV_y < 0) &&
        (RRV_x + RRV_gap[WMid] - RRV_curItemX[WMid] < 0 || 
        RRV_y + RRV_gap[WMid] - RRV_curItemY[WMid] < 0 || 
        RRV_curLayerX[WMid] + RRV_curItemWidth[WMid] + RRV_gap[WMid] - RRV_x < 0 || 
        RRV_curLayerY[WMid] + RRV_curItemHeight[WMid] + RRV_gap[WMid] - RRV_y < 0))	{
      if (RRV_hasBeenOver[WMid])	{	RRV_doReset[WMid] = true;	}	}
    else {
      RR_updateTime(WMid);
      RRV_hasBeenOver[WMid] = 1;
      RRV_doReset[WMid] = false;	}	}
}

//Alles ausblenden
function RR_hideAll(WMid)	{
  RRV_doReset[WMid] = false;
  RRV_curLayer[WMid] = null;
  if (RR_isObjCss(RRV_lastKey[WMid]) && RR_getObjCss(RRV_lastKey[WMid]))	{	eval('RR' + WMid + '_hideCode()');	}
  RRV_hasBeenOver[WMid] = 0;
}

