pos=0; //Variable zum positionieren des Scrolltextes
timer=null; //Variable für das Timeout
sprung=1; //scrollweite pro functionsaufruf
zeit=20; //Zeitfolge des Functionsaufrufes in Millisekunden

function scrollitup() // Function zum herunterscrollen des Textes
{
         if (document.getElementById) //NS6 +IE5
             {
                  pos=pos - sprung;
                  document.getElementById("inhalt1").style.top = pos + "px";
             }
         else if (document.layers)//wenn NS4
             {
              max = document.aussenrum.document.innendrin.document.hauptteil.document.inhaltsbereich.document.inhalt1.document.height - 200; //hoehe des Textes ermitteln - größe des Anzeigefensters
                  if (pos < max) //wenn die momentane obere Position des Textes kleiner ist als  Texthöhe-größe Anzeigefenster
                      {
                       pos = pos + sprung;
                       document.aussenrum.document.innendrin.document.hauptteil.document.inhaltsbereich.document.inhalt1.top=pos*-1 //Text neu positionieren
                      }
             }
         else if (document.all) //IE 4+5
                 {
                  max = document.all.inhalt1.offsetHeight - 200; //hoehe des Textes ermitteln - größe des Anzeigefensters
                      if (pos < max) //wenn die momentane obere Position des Textes kleiner ist als  Texthöhe-größe Anzeigefenster
                          {
                           pos=pos+sprung;
                           document.all.inhalt1.style.posTop=pos*-1 //Text neu positionieren
                          }
                 }
timer = window.setTimeout("scrollitup()",zeit); //Function ruft sich selber auf solange die Maus über der Schaltfläche steht

}

function scrollitdown()// Function zum heraufscrollen des Textes
{
         if(document.getElementById)//NS6 +IE5
              {
               pos=pos + sprung;
               document.getElementById("inhalt1").style.top = pos + "px";
              }
         else if (document.layers)//NS4
             {
                      if (pos>0)//wenn die momentane obere Position des Textes größer ist als 0
                          {
                           pos=pos-sprung;
                           document.inhaltsbereich.document.inhalt1.top=pos*-1 //Text neu positionieren
                          }
             }
         else if(document.all)//IE 4+5
              {
                      if(pos>0)//wenn die momentane obere Position des Textes größer ist als 0
                         {
                          pos=pos-sprung;
                          document.all.inhalt1.style.posTop=pos*-1//Text neu positionieren
                         }
              }
timer=setTimeout("scrollitdown()",zeit); //Function ruft sich selber auf solange die Maus über der Schaltfläche steht
}


function dhtml_teasers()
{
    var app = this;
    app.functions = new ly_functions();
    app.classname = null;
    app.teaserHeights = Array();
    app.teaserMinHeight = 29;
    app.motionInterval = 40;
    app.motionDiff = 20;
    /*app.motionInterval = 10;
    app.motionDiff = 40;*/

    app.setEventHandlers = function(classname)
    {
        var teasers;
        var i, k = 0;

        if(typeof classname != 'undefined')
        {
            if(document.getElementsByTagName)
            {
                app.classname = classname;
                teasers = document.getElementsByTagName('DIV');
                if(teasers)
                {
                    for(i = 0; i < teasers.length; i++)
                    {
                        if(app.functions.hasClass(app.classname, teasers[i].className))
                        {
                            var h3s = app.functions.filterChildNodesRecursive(teasers[i], 'H3');
                            if (h3s.length > 0)
                            {
                                app.teaserHeights[k] = teasers[i].offsetHeight;
                                app.teaserHeights[k] = app.getHeight(teasers[i]);

                                app.functions.addEvent(h3s[0], 'click', function()
                                                            {
                                                                var teaserElem = this.parentNode;

                                                                // Öffnen
                                                                if (app.functions.hasClass('closed', this.className))
                                                                {
                                                                    var index = app.getIndexByTeaser(teaserElem);
                                                                    app.toggleTeaser(teaserElem);
                                                                    app.animateTeaser(index, app.teaserHeights[index], true, null);
                                                                }

                                                                // Schließen
                                                                else
                                                                {
                                                                    window.setTimeout(function()
                                                                                                    {
                                                                                                        var index = app.getIndexByTeaser(teaserElem);
                                                                                                        app.animateTeaser(index, app.teaserMinHeight, false, function() { app.toggleTeaser(teaserElem); } );
                                                                                                    }, app.motionInterval);
                                                                }
                                                            } );

                                app.toggleTeaser(teasers[i]);
                            }
                            k++;
                        }
                    }
                }
            }
        }
    }

    app.getTeaserByIndex = function(index)
    {
        var i, k = 0;
        var teasers;

        if (document.getElementsByTagName)
        {
            teasers = document.getElementsByTagName('DIV');
            if(teasers)
            {
                for(i = 0; i < teasers.length; i++)
                {
                    if(app.functions.hasClass(app.classname, teasers[i].className))
                    {
                        if (k == index) return(teasers[i]);
                        k++;
                    }
                }
            }
        }
    }

    app.getIndexByTeaser = function(teaser)
    {
        var i, k = 0;
        var teasers;

        if (document.getElementsByTagName)
        {
            teasers = document.getElementsByTagName('DIV');
            if(teasers)
            {
                for(i = 0; i < teasers.length; i++)
                {
                    if(app.functions.hasClass(app.classname, teasers[i].className))
                    {
                        if (teasers[i] == teaser) return(k);
                        k++;
                    }
                }
            }
        }
    }

    app.animateTeaser = function(index, limit, direction, callback)
    {
        var teaser = app.getTeaserByIndex(index);

        if (teaser)
        {
            if ((direction == true && parseInt(teaser.style['height']) < limit)
                        || (direction == false && parseInt(teaser.style['height']) > limit))
            {
                var newHeight = parseInt(teaser.style['height']);
                newHeight = (direction) ? newHeight + app.motionDiff : newHeight - app.motionDiff;
                if (direction == true && newHeight > limit) newHeight = limit;
                if (direction == false && newHeight < limit) newHeight = limit;

                teaser.style['height'] = String(newHeight) + 'px';
                app.aniTimer = window.setTimeout(function()
                                                            {
                                                                app.animateTeaser(index, limit, direction, callback);
                                                            }, app.motionInterval);
            }
            else
            {
                if (callback != null) callback();
            }
        }
    }

    app.toggleTeaser = function(teaser)
    {
        if(app.functions.hasClass('closed', teaser.className))
        {
            for(i = 0; i < teaser.childNodes.length; i++)
            {
                if(teaser.childNodes[i].nodeType == 1)
                {
                    teaser.childNodes[i].className = app.functions.removeClass(teaser.childNodes[i].className, 'closed');
                }
            }
            teaser.className = app.functions.removeClass(teaser.className, 'closed');
        }
        else
        {
            for(i = 0; i < teaser.childNodes.length; i++)
            {
                if(teaser.childNodes[i].nodeType == 1)
                {
                    teaser.childNodes[i].className = app.functions.addClass(teaser.childNodes[i].className, 'closed');
                }
            }
            teaser.className = app.functions.addClass(teaser.className, 'closed');
            teaser.style['height'] = String(app.teaserMinHeight) + 'px';
        }
    }

    app.getHeight = function(teaser)
    {
        var detectedHeight = teaser.offsetHeight;
        //detectedHeight -= 8;
        return(detectedHeight);
    }
}

var dhtmlTeasers = new dhtml_teasers();
dhtmlTeasers.functions.addEvent(window, 'load', function() { dhtmlTeasers.setEventHandlers('teaser'); } );
//dhtmlTeasers.setEventHandlers('teaser');
