// *** Initialisierung ********************************************************************************************

var aktSbl = null;
var aktSbr = null;


// *** DOM-Initialisierung ****************************************************************************************

// DHTML-Initialisierung
var DHTML = false;
var DOM = false;
var IE = false;
var NC = false;
var OP = false;
var SAFARI = false;
function initDHTML()
{
   if (window.opera) {OP = true;}
   if (document.getElementById) {DHTML = true; DOM = true;}
   if (document.all && !OP) {DHTML = true; IE = true;}
   if (window.netscape && window.screen && !DOM && !OP) {DHTML = true; NC = true;}
   if (navigator.appVersion.search(/Safari/) != - 1) {SAFARI = true;}
}

// Element ansprechen
function getE(p1,p2,p3)
{
   if (DOM)
   {
      switch (p1.toLowerCase())
      {
         case "id":
            if (typeof document.getElementById(p2) == "object") {return document.getElementById(p2);}
            else {return void(0);}
            break;
         case "name":
            if (typeof document.getElementsByName(p2) == "object") {return document.getElementsByName(p2)[p3];}
            else {return void(0);}
            break;
         case "tag":
            if (typeof document.getElementsByTagName(p2) == "object" || ((OP || SAFARI) && typeof document.getElementsByTagName(p2) == "function"))
               {return document.getElementsByTagName(p2)[p3];}
            else {return void(0);}
            break;
         default: return void(0);
      }
   }
   else if (IE)
   {
      switch (p1.toLowerCase())
      {
         case "id":
            if (typeof document.all[p2] == "object") {return document.all[p2];}
            else {return void(0);}
            break;
         case "name":
            if (typeof document[p2] == "object") {return document[p2];}
            else {return void(0);}
            break;
         case "tag":
            if (typeof document.all.tags(p2) == "object") {return document.all.tags(p2)[p3];}
            else {return void(0);}
            break;
         default: return void(0);
      }
   }
   else if (NC)
   {
      switch (p1.toLowerCase())
      {
         case "id":
            if (typeof document[p2] == "object") {return document[p2];}
            else {return void(0);}
            break;
         case "name":
            if (typeof document[p2] == "object") {return document[p2];}
            else {return void(0);}
            break;
         case "index":
            if (typeof document.layers[p2] == "object") {return document.layers[p2];}
            else {return void(0);}
            break;
         default: return void(0);
      }
   }
   else return void(0);
}

// Event zu Objekt hinzufügen
function addEvent(obj,event,func)
{
   if (IE || OP)  // ältere Operaversionen kennen addEventListener noch nicht!
   {
      if (obj == window) {eval("obj.on" + event + " = document.on" + event + " = func;");}
      else {eval("obj.on" + event + " = func;");}
   }
   else if (DOM)
   {
      if (event == 'mousewheel')
      {
         obj.addEventListener('DOMMouseScroll', func, true);
         window.onmousewheel = document.onmousewheel = func;
      }
      else {obj.addEventListener(event, func, true);}
   }
   if (NC)
   {
      eval("obj.captureEvents(Event." + event.toUpperCase() + ");");
      eval("obj.on" + event + " = func;");
   }
}


// *** AJAX: XMLHttpRequest ***************************************************************************************

function hrGet(fnc,f,n)
{
   hr = null;
   try {hr = new ActiveXObject("MSXML2.XMLHTTP");}
   catch (err_MSXML2)
   {
      try {hr = new ActiveXObject("Microsoft.XMLHTTP");}
      catch (err_Microsoft)
      {
         if (typeof XMLHttpRequest != 'undefined') {hr = new XMLHttpRequest;}
      }
   }
   if (hr)
   {
      eval('hr.onreadystatechange = function() {'+fnc+'();};');
      hr.open('GET',f+'?sub='+n,true);
      hr.send(null);
   }
   return hr;
}

function hrCnt()
{
   if (hr.readyState == 4 && hr.status == 200)
   {
      eval(hr.responseText);
      hr.abort();
      hr = null;

      // Inhalt durch AJAX-Reload ersetzen
      var cnt = document.createElement('div');
      if (v[0])
      {
         cnt.setAttribute('class','sml');
         cnt.setAttribute('className','sml');
      }
      cnt.innerHTML = v[1];
      ifma.idc.replaceChild(cnt,ifma.idc.firstChild);
      ifma.setH();
      ifma.shw();
   }
}


// *** iFrame-Objekt **********************************************************************************************

var ifma = null;

// Eventhandler für Scrollrad (global, nicht auf bestimmtes Objekt bezogen!)
function eMouseWheel(e)
{
   // Mouse-Event für alle Browser vereinheitlichen
   if (!e) {e = window.event;}
   if (e.wheelDelta)
   {
      d = e.wheelDelta/120;
   }
   else if (e.detail)
   {
      d = -e.detail/3;
   }

   // Abhängig von Scroll Event ausführen
   if (d) {ifma.scr(d/Math.abs(d),5*14);}
}

function eMouseUp(e)
{
   if (ifma && ifma.bar) {ifma.bar.scrEnd();}
}

function eMouseMove(e)
{
   if (ifma && ifma.bar && ifma.bar.getDrag())
   {
      if (!e) {e = window.event;}
      if (IE) {d = e.y;} else {d = e.screenY;}
      ifma.bar.scrMove(d);
   }
}

// Objekt für up-/down-Buttons
function btn(idS,idP,idB,t)
{
   // Initialisierung
   var div = document.createElement('div');
   div.idS = idS		// ID des Scrollelements
   div.idP = idP		// ID des Elternelements
   div.idB = idB		// ID des Buttons
   div.t = t;        	// Typ des Buttons: 1=up, -1=down
   div.ids = null;	// Scrollelement
   div.idp = null;	// Elternelement
   div.tim = null;	// Timer
   div.s = 2;		// Schrittweite für Scroll (in Pixel)

   // Button erzeugen
   div.crt = function()
   {
      this.setAttribute('id',this.idB);
      this.setAttribute('class','btn '+((t==1) ? 'up' : 'down'));
      this.setAttribute('className','btn '+((t==1) ? 'up' : 'down'));
      this.ids = getE('id',this.idS,null);
      this.idp = getE('id',this.idP,null);
      this.idp.appendChild(this);
      addEvent(this,"mouseover",this.eMouseover);
      addEvent(this,"dblclick",this.eDblclick);
      addEvent(this,"mouseout",this.eMouseout);
   }

   // Button einblenden
   div.shw = function()
   {
      if (DOM || IE) {this.style.visibility = 'visible';} else if (NC) {this.visibility = 'show';}
   }

   // Button ausblenden
   div.hid = function()
   {
      if (DOM || IE) {this.style.visibility = 'hidden';} else if (NC) {this.visibility = 'hide';}
   }

   // Event onMouseover
   div.eMouseover = function(e)
   {
      this.scr();
   }

   // Event onDblclick (IE-Fehler: bei zwei schnellen Klicks wird nur ein einfacher Klick ausgelöst)
   div.eDblclick = function(e)
   {
      if (IE) {this.ids.scr(this.t,this.s);}
   }

   // Event onMouseout
   div.eMouseout = function(e)
   {
      if (this.tim)
      {
         window.clearTimeout(this.tim);
         this.tim = false;
      }
   }

   // Scroll ausführen
   div.scr = function()
   {
      if (this.ids.scr(this.t,this.s))
      {
         obj = this;
         if (!this.tim) {this.tim = window.setTimeout(function(){obj.scr();},50,obj);}
         else {this.tim = window.setTimeout(function(){obj.scr();},10,obj);}
      }
   }

   return (div);
}

// Objekt für iFrame-Fenster
function ifm(idB,idP,idF,idC,h,sub,rgt)
{
   // Initialisierung
   var div = document.createElement('div');
   div.h = h;
   div.wScr = 16;		// Breite des Scrollbalkens
   div.hBtn = Math.round(h/8);
   div.hCnt = 0;		// Inhalts-Höhe
   div.hScr = 0;		// Höhe, um die maximal gescrollt werden kann
   div.hBar = 0;		// Scrollbalken-Höhe
   div.hRst = 0;		// leer Scrollbalken-Höhe
   div.idB = idB		// ID des Elternelements (für Buttons)
   div.idP = idP		// ID des Elternelements; falls leer: body
   div.idF = idF		// ID des iFrames
   div.idC = idC		// ID des Inhalts
   div.bup = null;
   div.bdn = null;
   div.ibg = null;	// Hintergrund (transparent)
   div.idc = null;	// Inhalt
   div.sy = 0;		// Vertikaler Scroll-Versatz;
   div.d = false;		// Drag-Status
   div.dy = 0;		// y-Position für jeweiligen Drag-Start

   // iFrame erzeugen
   div.crt = function()
   {
      var idp = getE('id',this.idP,null);

      // Inhaltselement analysieren
      this.idc = getE('id',this.idC,null);
      this.w = this.idc.offsetWidth;

      // transparenten Hintergrund an Eltern-Element anhängen
      this.ibg = document.createElement('div');
      this.ibg.setAttribute('class','ibg');
      this.ibg.setAttribute('className','ibg');
      if (rgt) {this.ibg.style.right = '0px';} else {this.style.left = '0px';this.ibg.style.backgroundColor = 'transparent';}
      this.ibg.style.width = this.w+'px';
      this.ibg.style.height = this.h+'px';
      idp.appendChild(this.ibg);

      // iFrame erstellen und an Eltern-Element anhängen
      this.setAttribute('id',this.idF);
      this.setAttribute('class','ifm');
      this.setAttribute('className','ifm');
      if (rgt)
      {
         this.style.right = '8px';
         this.style.top = '5px';
         this.style.width = (this.w-16)+'px';
         this.style.height = (this.h-10)+'px';
      }
      else 
      {
         this.style.left = '0px';
         this.style.top = '0px';
         this.style.width = this.w+'px';
         this.style.height = this.h+'px';
      }
      idp.appendChild(this);

      // Inhaltselement in iFrame einbinden
      this.idc.style.position = 'absolute';
      this.idc.style.backgroundColor = 'transparent';
/*
      this.idc.style.filter = 'alpha(opacity:100)';
      this.idc.style.KHTMLOpacity = 1.00;
      this.idc.style.MozOpacity = 1.00;
      this.idc.style.opacity = 1.00;
*/
      this.idc.style.padding = '0px';
      this.idc.style.left = '0px';
      this.appendChild(this.idc);
      this.setH();

      // Button Up in iFrame einbinden
      this.bup = btn(this.idF,this.idB,'bup',1);
      this.bup.crt();

      // Button Down in iFrame einbinden
      this.bdn = btn(this.idF,this.idB,'bdn',-1);
      this.bdn.crt();

      // iFrame ein- oder ausblenden
      if (sub) {this.shw();} else {this.hid();}
   }

   // iFrame einblenden
   div.shw = function()
   {
      if (DOM || IE)
      {
         this.style.visibility = 'visible';
         this.ibg.style.visibility = 'visible';
      }
      else if (NC)
      {
         this.visibility = 'show';
         this.ibg.visibility = 'show';
      }
      if (this.hBar) {this.bup.shw(); this.bdn.shw();} else {this.bup.hid(); this.bdn.hid();}

      // an Anfang scrollen
      this.idc.style.top = '0px';
   }

   // iFrame ausblenden
   div.hid = function()
   {
      if (DOM || IE)
      {
         this.style.visibility = 'hidden';
         this.ibg.style.visibility = 'hidden';
      }
      else if (NC)
      {
         this.visibility = 'hide';
         this.ibg.visibility = 'hide';
      }
      this.bup.hid();
      this.bdn.hid();
   }

   // Höhen für Scrolling berechnen
   div.setH = function()
   {
      this.hCnt = this.idc.offsetHeight;
      this.hScr = this.hCnt - (this.h-((rgt) ? 10 : 0));
      if (this.hCnt > this.h)
      {
         this.hBar = Math.max(10,Math.round((this.h-2*this.wScr-2)*this.h/this.hCnt));
         this.hRst = -this.h+2*this.wScr+2+this.hBar;
      }
      else {this.hBar = 0; this.hRst = 0;}
      this.sy = 0;
   }

   // iFrame schrittweise scrollen (falls in gewünschte Richtung gescrollt werden kann)
   div.scr = function(t,s)
   {
      if (this.hBar)
      {
         if (this.d) {stp = this.dy-this.sy+Math.round(t/this.hRst*this.hScr);} else {stp = s*t;}
         if (this.sy+stp <= -this.hScr) {this.sy = -this.hScr; go = false;}
         else if (this.sy+stp >= 0) {this.sy = 0; go = false}
         else {this.sy = this.sy+stp; go = true;}
         this.idc.style.top = this.sy+'px';
      }
      else {go = false;}
      return (go);
   }

   div.drg = function(d)
   {
      this.d = d;
      this.dy = this.sy;
   }

   return (div);
}

function AC_FL_RunContent2()
{
   return AC_GetArgs (arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
}

// Bild auswechseln
function chgImg(idSbr,idOld,idNew,img)
{
   // Bild wechseln
   getE('id','img',null).src = img;

   // iFrame ausblenden
   ifma.hid();

   // Sub-Navi rechts normal darstellen
   var sbr = (aktSbr==null) ? getE('id','sbr'+idSbr,null) : aktSbr;
   if (sbr != null)
   {
      var h3 = sbr.firstChild;
      var txt = h3.removeChild(h3.firstChild);
      sbr.replaceChild(txt,h3);
      aktSbr = null;
   }

   // alten Link normal darstellen
   var sbl = (aktSbl==null) ? getE('id','sbl'+idOld,null) : aktSbl;
   var h3 = sbl.firstChild;
   var txt = h3.removeChild(h3.firstChild);
   sbl.replaceChild(txt,h3);

   // neuen Link hervorheben
   var sbl = getE('id','sbl'+idNew,null);
   var h3 = document.createElement('h3');
   h3.appendChild(sbl.firstChild);
   sbl.appendChild(h3);

   aktSbl = sbl;
}

// Inhalt auswechseln
function chgCnt(idOld,idNew)
{
   // Inhalt wechseln
   hrGet('hrCnt','cnt.php',idNew);

   // alten Link normal darstellen
   var sbr = (aktSbr==null) ? getE('id', 'sbr'+idOld,null) : aktSbr;
   if (sbr != null)
   {
      var h3 = sbr.firstChild;
      var txt = h3.removeChild(h3.firstChild);
      sbr.replaceChild(txt,h3);
   }

   // neuen Link hervorheben
   var sbr = getE('id','sbr'+idNew,null);
   var h3 = document.createElement('h3');
   h3.appendChild(sbr.firstChild);
   sbr.appendChild(h3);

   aktSbr = sbr;
}

// Initialisierung
function init(flash,sub,typ)
{
   // DHTML starten
   initDHTML();

   // Flash-Version prüfen
   var hasRightVersion = flash && DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

   // Inhalt mit Flash überschreiben
   if(hasRightVersion)
   {
      ret = AC_FL_RunContent2 (
         'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,2,0',
         'width', '780',
         'height', '400',
         'src', 'elfelf_moebeldesign',
         'quality', 'high',
         'pluginspage', 'http://www.adobe.com/go/getflashplayer',
         'align', 'middle',
         'play', 'true',
         'loop', 'true',
         'scale', 'showall',
         'wmode', 'transparent',
         'devicefont', 'false',
         'id', 'elfelf_moebeldesign',
         'bgcolor', '#ffffff',
         'name', 'elfelf_moebeldesign',
         'menu', 'true',
         'allowFullScreen', 'false',
         'allowScriptAccess','sameDomain',
         'movie', 'elfelf_moebeldesign',
         'salign', ''
      );
      var box = getE('id','box',null);
      if (isIE && isWin && !isOpera)
      {
         var fo = document.createElement('object');
         for (var i in ret.objAttrs) {if (i != 'classid') {fo.setAttribute(i,ret.objAttrs[i]);}}
         for (var i in ret.params)
         {
            var prm = document.createElement('param');
            prm.setAttribute('name',i);
            prm.setAttribute('value',ret.params[i]);
            fo.appendChild(prm);
         }
      }
      else
      {
         var fo = document.createElement('embed');
         for (var i in ret.embedAttrs) {fo.setAttribute(i,ret.embedAttrs[i]);}
      }
      box.replaceChild(fo,box.firstChild);

      // classid darf bei IE erst nach Einbinden in Struktur gesetzt werden (da sonst Fehler auftritt)
      if (isIE && isWin && !isOpera)
      {
         getE('id',ret.objAttrs['id'],null).setAttribute('classid',ret.objAttrs['classid']);
      }
   }

   // Website ohne Flash anzeigen
   else
   {
      // iFrame erstellen
      if (getE('id','cnt',null) != null)
      {
         ifma = ifm('box','cnt','ifm','ict',270,sub,typ);
         ifma.crt();

         // globale EventHandler hinzufügen
         addEvent(window,'mouseup',eMouseUp);
         addEvent(window,'mousemove',eMouseMove);
         addEvent(window,'mousewheel',eMouseWheel);
      }
   }
}
