  /*Globale Variablen */
         var i = 0;   /* Zählervariable */
         var maxwidth = 500;
         var maxheight = 500;

         var FadeDurationMS=400;  /* in ms */

         var n=1;



/* Funktions*/

       function loadImage(Bilder, Beschreibung){

       document.getElementById("fadeContainer").style.width = "auto";   //clear size of image container
       document.getElementById("fadeContainer").style.height = "auto";

       i = 0;
       var w = Bilder[i].width;
       var h = Bilder[i].height;

         if(Bilder.length > 1) {
         document.getElementsByName("back")[0].firstChild.nodeValue="<<";
         document.getElementsByName("forw")[0].firstChild.nodeValue=">>";
         }

         else {
         document.getElementsByName("back")[0].firstChild.nodeValue=" ";
         document.getElementsByName("forw")[0].firstChild.nodeValue=" ";
         }



       if (w ==h)  // Quadratisches Bild
         {
         document.images["bild"].height = maxheight;
         document.images["bild"].width = maxwidth;
         }


       if(w < h)  // Hochformat
         {
         document.images["bild"].height = maxheight;
         document.images["bild"].width = maxheight*w/h;
         }

       else       // Querformat
         {
         document.images["bild"].width = maxwidth;
         document.images["bild"].height = maxwidth*h/w;
         }

       document.images["bild"].src = Bilder[i].src;
       document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i];
       }



      function loadImageWithPrice(Bilder, Beschreibung, Preis){

      if(Bilder.length > 1) {
      document.getElementsByName("back")[0].firstChild.nodeValue="<<";
      document.getElementsByName("forw")[0].firstChild.nodeValue=">>";
      }


      i = 0;
      var w = Bilder[i].width;
       var h = Bilder[i].height;

       if (w ==h)  // Quadratisches Bild
         {
         document.images["bild"].height = maxheight;
         document.images["bild"].width = maxwidth;
         }


       if(w < h)  // Hochformat
         {
         document.images["bild"].height = maxheight;
         document.images["bild"].width = maxheight*w/h;
         }

       else       // Querformat
         {
         document.images["bild"].width = maxwidth;
         document.images["bild"].height = maxwidth*h/w;
         }

      document.images["bild"].src = Bilder[i].src;
      document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i]+", "+Preis[i];
         }


    // Bildwechselcode
    function bildwechsel(Bilder, booleanNotFade){

      var w = Bilder[i].width;
      var h = Bilder[i].height;

      if (w == 0 || h == 0)
         booleanNotFade = true;



      if (w ==h)  // Quadratisches Bild
         {
         document.images["bild"].height = maxheight;
         document.images["bild"].width = maxwidth;
         document.getElementById("fadeContainer").style.width = maxwidth+"px";   // wichtig für das Faden
         document.getElementById("fadeContainer").style.height = maxheight+"px"; // wichtig für das Faden
         }


      if(w < h)  // Hochformat
         {
         document.getElementById("fadeContainer").style.width = maxheight*w/h+"px";   // wichtig für das Faden
         document.getElementById("fadeContainer").style.height = maxheight+"px";     // wichtig für das Faden
         document.images["bild"].height = maxheight;
         document.images["bild"].width = maxheight*w/h;

         }

      else       // Querformat
         {
         document.getElementById("fadeContainer").style.width = maxwidth+"px";     // wichtig für das Faden
         document.getElementById("fadeContainer").style.height = maxwidth*h/w+"px"; // wichtig für das Faden
         document.images["bild"].width = maxwidth;
         document.images["bild"].height = maxwidth*h/w;

         }


      if(booleanNotFade)                                       // wenn das NotFade-Flag gesetzt
         FadeInImage(Bilder[i].src);                        // nicht faden
      else                                                  // sonst im Normalfall immer faden
         FadeInImage(Bilder[i].src,"fadeContainer");        // Bildwechsel beim Faden
      //document.images["bild"].src = Bilder[i].src;     // Bildwechsel ohne Faden
      }




      // Vorwärts Bildewechselfunktion mit Bildunterschrift
      function forward(Bilder, Beschreibung) {
         i++                     // forwärts
         if (i>=Bilder.length) i = 0;
         bildwechsel(Bilder);
         document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i];
      }

      function forwardNotFade(Bilder, Beschreibung) {
         i++                     // forwärts
         if (i>=Bilder.length) i = 0;
         bildwechsel(Bilder,true);         // do not fade
         document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i];
      }



      function forwardWithPrice(Bilder, Beschreibung, Preis) {
         i++;
         if (i>=Bilder.length) i = 0;
         bildwechsel(Bilder);
         document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i]+", "+Preis[i];
      }




           function backward(Bilder, Beschreibung) {
             i--;
             if (i<0) i = Bilder.length-1;
             bildwechsel(Bilder);
             document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i];
           }

           function backwardNotFade(Bilder, Beschreibung) {
             i--;
             if (i<0) i = Bilder.length-1;
             bildwechsel(Bilder,true);           // do not fade
             document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i];
           }




    function backwardWithPrice(Bilder, Beschreibung, Preis) {
      i--;
      if (i<0) i = Bilder.length-1;
      bildwechsel(Bilder);
      document.getElementById("imgcaption").firstChild.nodeValue = Beschreibung[i]+", "+Preis[i];
    }




    // Fade Test from www.cryer.co.uk
     function SetOpacity(object,opacityPct)
         {
        // IE.
        object.style.filter = 'alpha(opacity=' + opacityPct + ')';
        // Old mozilla and firefox
        object.style.MozOpacity = opacityPct/100;
        // Everything else.
        object.style.opacity = opacityPct/100;
         }


         function ChangeOpacity(msDuration,msStart,fromO,toO)
         {
         var element=document.getElementsByName("bild")[0];
         var msNow = (new Date()).getTime();
         var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
         if (opacity>=100)
                 {
                 SetOpacity(element,100);
                 element.timer = undefined;
                 }
         else if (opacity<=0)
                 {
                 SetOpacity(element,0);
                 element.timer = undefined;
                 }
         else
                 {
                 SetOpacity(element,opacity);
                 element.timer = window.setTimeout("ChangeOpacity(" + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
                 }
         }


          function FadeInImage(newImage,backgroundID)
          {
                 var foreground=document.getElementsByName("bild")[0];
                 if (foreground.timer) window.clearTimeout(foreground.timer);

                 if (backgroundID)
                 {
                        var background=document.getElementById(backgroundID);
                        if (background)
                        {
                                if (background.src)
                                {
                                        foreground.src = background.src;
                                        SetOpacity(foreground,100);
                                }
                                background.src = newImage;
                                background.style.backgroundImage = 'url(' + newImage + ')';
                                background.style.backgroundRepeat = 'no-repeat';
                                var startMS = (new Date()).getTime();
                                foreground.timer = window.setTimeout("ChangeOpacity(" + FadeDurationMS + "," + startMS + ",100,0)",10);
                        }
                 }
                 else {
                   foreground.src = newImage;
                 }
          }
