

 // **************************************************************************************************************
 // *** Slideshow 1.1-avonlea.hu verzió 
 // **************************************************************************************************************

 // ------------------------------
 // --- Beállítható paraméterek
 // ------------------------------

 // --- Oldal nyelvének a beállítása: LANG_EN = angol (alapértelmezett), LANG_HU = magyar
 var pageLang = LANG_EN;
 // --- Betöltődés után milyen módban induljon: false = manuális (alapértelmezett), true = automata
 var startAutoMode = false;
 // --- Automata indulás esetén megjelenjenek-e a kézi léptető linkek: false = nem (alapértelmezett), true = igen
 var showAllControl = false;
 // --- Automatikusan visszatér a menübe az utolsó kép után
 var autoBackToMenu = false;
 // --- Egy kep megjelenesi ideje masodpercben
 var slideTime = 5;
 // --- Időtúllépés ideje masodpercben
 var slideTimeout = 10;

 // --- Régi arány, ha nincs explicite beállítva
 if (!ratio) {
     var ratio  = 4/3;
 }

 // --- A megjelenített képek mérete
 var imgHeight = 360;
 var imgWidth  = imgHeight*ratio;
 // --- A megjelenített állóképek átméretezése
 var resizePortrait = true;
 // --- Nagyméretű kép megjelenése
 var imgBigfullscreen = false;
 // --- A nagyméretű kép mérete
 var imgBigHeight = 768;
 var imgBigWidth  = imgBigHeight*ratio;
 // --- Az ugrás távolsága
 var jumpLength = 5;
 // --- Képváltás effektusa
 var slideEffect = "fade";

 var fadingSpeed = 5;

 // --- Színek
 var bodyBgColor   = "#f4f4f4";   // Háttér
 var descTextColor = "green";   // Képleírás
 
 // -- a kepek egyszerubb kezelesehez, defaultkent a kiskepeket hasznlajuk previewnak
 var imgName1  = "preview/img_";
 var imgName2  = "_s.jpg";
 
 // -- védett projectek
 var project = 0;
 var simple  = 0;
 var page    = 0;

 // --- Oldal hivatkozások
 var validReferrer = new Array ("avonlea", "avonlea.hu");
 
 // ------------------------------
 // --- Global variables
 // ------------------------------

 // --- Állóképek átméretezése
 var imgWidthP  = imgHeight;
 var imgHeightP = imgWidth;

 var curpos = 0;

 var Clock;
 var runid, waitid, fadeid = 0;
 var autoMode;

 var slideNext  =  0; // Első kép
 var slideIndex = -1;

 var slideCounter = slideTime-1;
 var cntTimeout   = 0;         // időtúllépés másodpercben

 var frstSlide  = new Image(); // az első kép előtöltéséhez
 var prevSlide  = new Image(); // az előző kép előtöltéséhez
 var nextSlide  = new Image(); // a következő kép előtöltéséhez
 var lastSlide  = new Image(); // az utolsó kép előtöltéséhez

 var codeInit   = true;
 var processDL  = false;

 var thumbVisible = false;
 var popupOpen  = false;
 var bigPicDesc = "";

 var useURLparams = false;

 // --- Néhány konstans
 var HIDE_E   = true;          // setElementVisibility()
 var SHOW_E   = false;         // setElementVisibility()

 // -------------------------------------------------------------------
 // --- "Hotkey function" code start
 // -------------------------------------------------------------------

 var HK_FRSTSL = 102; // f
 var HK_PREVSL = 112; // p
 var HK_AUTOSL =  97; // a
 var HK_NEXTSL = 110; // n
 var HK_LASTSL = 108; // l

 var HK_OPTION = 115; // s
 var HK_HELP   = 109; // m
 var HK_BACK   =  98; // b
 var HK_THUMBS = 116; // t


 if (document.layers)
  document.captureEvents(Event.KEYPRESS);

 function getKeyFunction(e)
 {
  if (document.layers) {
   if (e.which == HK_FRSTSL)
    manualStep (0);
   else
    if (e.which == HK_PREVSL)
     manualStep (-1);
    else
     if (e.which == HK_AUTOSL)
      selectMode ();
     else
      if (e.which == HK_NEXTSL)
       manualStep (1);
      else
       if (e.which == HK_LASTSL)
        manualStep (slideMax);
       else
        if (e.which == HK_OPTION)
         openBox (0);
        else
         if (e.which == HK_HELP)
          openBox (1);
         else
          if (e.which == HK_BACK)
           history.back ();
          else
           if (e.which == HK_THUMBS)
            setThumbsVisibility ();
  }
  else
   if (document.all) {
    if (event.keyCode == HK_FRSTSL)
     manualStep (0);
    else
     if (event.keyCode == HK_PREVSL)
      manualStep (-1);
     else
      if (event.keyCode == HK_AUTOSL)
       selectMode ();
      else
       if (event.keyCode == HK_NEXTSL)
        manualStep (1);
       else
        if (event.keyCode == HK_LASTSL)
         manualStep (slideMax);
        else
        if (event.keyCode == HK_OPTION)
          openBox (0);
         else
          if (event.keyCode == HK_HELP)
           openBox (1);
          else
           if (event.keyCode == HK_BACK)
            history.back ();
           else
            if (event.keyCode == HK_THUMBS)
             setThumbsVisibility ();
   }
 }

 document.onkeypress = getKeyFunction;

//----------------------------------------------------------------------------
function setSlideshowSettings() {
//----------------------------------------------------------------------------
    var settings    = document.getElementById('ssSettings');
    var stParam     = settings.slidetime;
    var resParam    = settings.resolution;
    var prParam     = settings.isPreview;
    var fdParam     = settings.isFading;
    var fsParam     = settings.fadingSpeed;

    slideTime = stParam.value;
    //korrekcio, ha vki 0-at adna meg
    if (slideTime == 0) {
        slideTime = 1;
    }
    imgHeight = resParam.value;
    var ratio = getParameter("ratio");
    imgWidth  = imgHeight*ratio;

    isPreview   = prParam.checked;
    isFading    = fdParam.checked;
    fadingSpeed = fsParam.value;

    var opener = window.opener;
    opener.slideTime    = slideTime;
    opener.imgWidth     = imgWidth;
    opener.imgHeight    = imgHeight;
    if (opener.isPreview!=isPreview){
        opener.setThumbsVisibility();
    }
    opener.isPreview    = isPreview;
    opener.isFading     = isFading;
    opener.fadingSpeed  = parseInt(fadingSpeed);

    opener.pageReInit();

    // -- vajon a kicsi vagy a nagy kepet hasznaljuk previewnak?
    if (imgHeight>360) {
	    opener.imgName1  = "img_";
	    opener.imgName2  = ".jpg";
    }else{
	    opener.imgName1  = "preview/img_";
	    opener.imgName2  = "_s.jpg";
    }
	
    expDate = new Date();
    expDate.setTime(expDate.getTime() + (1000*60*60*24*90));
    var ssSettings = slideTime+":"+imgHeight+":"+isPreview+":"+isFading+":"+fadingSpeed;
    setCookie("ssSettings",ssSettings,expDate);
    window.close();
}
    
//----------------------------------------------------------------------------
function getSlideshowParams() {
//----------------------------------------------------------------------------
    var ssSettings = getCookie("ssSettings");
    if (ssSettings == null) {
        slideTime   = 5;
        imgHeight   = 360;
        isPreview   = false;
        isFading    = true;
        fadingSpeed = 5;
    } else {
        var ssArray = ssSettings.split(":");
        slideTime   = ssArray[0];
        imgHeight   = ssArray[1];
        if (ssArray[2] == "true") {
            isPreview = true;
        } else {
            isPreview = false;
        }
        if (ssArray[3] == "true") {
            isFading = true;
        } else {
            isFading = false;
        }
        fadingSpeed = parseInt(ssArray[4]);
    }
    imgWidth = imgHeight*ratio;
}

//----------------------------------------------------------------------------
function getSlideshowSettings() {
//----------------------------------------------------------------------------
    var settings    = document.getElementById('ssSettings');
    var stParam     = settings.slidetime;
    var resParam    = settings.resolution;
    var prParam     = settings.isPreview;
    var fdParam     = settings.isFading;
    var fsParam     = settings.fadingSpeed;
    getSlideshowParams();

    stParam.value = slideTime;
    for (i=0;i<resParam.length;i++) {
        if (resParam.options[i].value == imgHeight) {
    	    resParam.options[i].selected = true;
	    }
    }
    if (isPreview) {
        prParam.checked = true;
    }
    if (isFading) {
        fdParam.checked = true;
    }
    for (i=0;i<fsParam.length;i++) {
        if (fsParam.options[i].value == fadingSpeed) {
    	    fsParam.options[i].selected = true;
	    }
    }
}

 // -------------------------------------------------------------------
 // --- "Hotkey function" code end
 // -------------------------------------------------------------------

 // ----------------------------------------
 // --- Get string
 // ----------------------------------------
 function getLangStr2(strID)
 {
  var resString = "<unknown>";

  for (var i = 0; i < arLang.length; i++)
   if ( strID == arLang[i].lsID ) {
    if ( pageLang == LANG_EN )
     resString = arLang[i].lsStrEN;
    else
     if ( pageLang == LANG_HU )
      resString = arLang[i].lsStrHU;

    break;
   }

  return (resString);
 }
 // Pictures descriptions text
 function getDescStr(sIndex)
 {
  var resString = "<unknown>";

  if (pageLang == LANG_HU) // Hungarian
   resString = arPic[sIndex].slDescHU;
  else
   if (pageLang == LANG_EN) // English
    resString = arPic[sIndex].slDescEN;

  return resString;
 }

 // ----------------------------------------
 // --- Hide/show text on page
 // ----------------------------------------
 function setElementVisibility(cellOrId, hideE)
 {
  var text = typeof cellOrId == 'string' ? (document.all ? document.all[cellOrId] : document.getElementById(cellOrId)) : cellOrId;

  if (hideE == HIDE_E)
   text.style.display = 'none';
  else
   text.style.display = '';
 }

 // ----------------------------------------
 // --- Hide/show thumbs view
 // ----------------------------------------
 function setThumbsVisibility()
 {
  var elem  = document.all ? document.all["thumbView"] : document.getElementById ? document.getElementById("thumbView") : null;

  if (thumbVisible)
   elem.style.display = 'none';
  else
   elem.style.display = '';

  thumbVisible = !thumbVisible;
 }

 // ----------------------------------------
 // --- Read a text value
 // ----------------------------------------
 function getTextValue(cellOrId)
 {
  var cell = typeof cellOrId == 'string' ? (document.all ? document.all[cellOrId] : document.getElementById(cellOrId)) : cellOrId;

  if (document.all)
   return cell.innerText;
  else {
   cell.normalize();
   if (cell.firstChild.nodeType == 3)
    return cell.firstChild.nodeValue;
   else
    return '';
  }
 }

 // ----------------------------------------
 // --- Write a text value
 // ----------------------------------------
 function setTextValue (cellOrId, newValue)
 {
  var cell = typeof cellOrId == 'string' ? (document.all ? document.all[cellOrId] : document.getElementById(cellOrId)) : cellOrId;

  if (msie | operaBrowser | !document.all) {
   cell.innerHTML = newValue;
  }
  else {
   cell.normalize();
   if (cell.firstChild.nodeType == 3)
    cell.firstChild.nodeValue = newValue;
  }
 }

 // ----------------------------------------
 // --- Build time string (->manual mode)
 // ----------------------------------------
 function getManualTime()
 {
  var     localClk = new Date();
  var     hour = localClk.getHours()
  var     min  = localClk.getMinutes()
  var     sec  = localClk.getSeconds()

  clkStr  = "" + hour + ":"
  clkStr += ((min < 10) ? "0" : "") + min + ":"
  clkStr += ((sec < 10) ? "0" : "") + sec

  return clkStr;
 }

 // ----------------------------------------
 // --- Build time string (->auto mode)
 // ----------------------------------------
 function getSlideTime()
 {
  var     localClk = new Date();

  actTime = Math.round( (localClk.getTime() - Clock.getTime()) / 1000 ); // eltelt ido masodpercben
  if ( actTime > 59 )
  {
   var     hour = 0, min = 0, sec = 0;

   sec = Math.round(actTime % 60);
   min = Math.floor(actTime / 60);
   if ( min > 59 )
   {
    hour = Math.floor(min / 60);
    min  = Math.round(min % 60);
   }
   clkStr  = " " + ((hour < 10) ? "0" : "") + hour + ":";
   clkStr += ((min < 10) ? "0" : "") + min + ":";
   clkStr += ((sec < 10) ? "0" : "") + sec;
  }
  else
   clkStr = " 00:00:" + ((actTime < 10) ? "0" : "") + actTime;

  return clkStr;
 }

 // ----------------------------------------
 // --- Change the statusbar text
 // ----------------------------------------
 function setStatusText(strID)
 {
  if ( strID != "" )
   self.status = getLangStr2(strID);
  else {
   if ( slideIndex != -1 )
    self.status = getLangStr2("T_SLIDE") + "   " + (slideIndex+1) + " / " + (slideMax+1) + "   [" + arPic[slideIndex].slFile + "]";
   else self.status = "";
  }
 }

 // ----------------------------------------
 // --- open slide in a popup window
 // ----------------------------------------
 function openSlide ()
 {
  var     parts   = document.URL.split("/");
  var     loadURL = parts[0] + "//";

  if ( !popupOpen ) {
//   for (var i = 1; i < parts.length-1; i++) by KoZso
   for (var i = 1; i < 3; i++)
    if ( parts[i].length )
     loadURL += (parts[i] + "/");

   loadURL += "showpic.html";

   if ( useURLparams ) {
    loadURL += "?pic=" + mediaPath2 + "img_" + arPic[slideIndex].slFile + ".jpg" + "&mozilla=";

/*
    if ( !imgBigfullscreen )
     if (arPic[slideIndex].slWidth) {
        loadURL += "&w="+arPic[slideIndex].slWidth+"&h="+arPic[slideIndex].slHeight;
     } else {
        loadURL += "&w="+imgBigWidth+"&h="+imgBigHeight;
     }
*/     
   }

   if ( pageLang == LANG_HU )
    bigPicDesc = (slideIndex+1)+". kép: ";
   else bigPicDesc = "Slide "+(slideIndex+1)+": ";
   bigPicDesc += getDescStr(slideIndex);

   var wHeight= 0;
   var wWidth = 0;
   
   if (document.images.actSlide.width<document.images.actSlide.height) {
    //álló
    wHeight = imgBigWidth;
    wWidth  = imgBigHeight;
   } else {
    wHeight = imgBigHeight;
    wWidth  = imgBigWidth;
   }

   picWindow = window.open(loadURL,'popup','width='+wWidth+',height='+wHeight+',status=no');
   popupOpen = true;
  }
  else {
  }
 }

 // ----------------------------------------
 // --- preload prev and next slide
 // ----------------------------------------
 function preLoadSlides()
 {
  var     prevIndex = slideIndex-1, nextIndex = slideIndex+1, swap;

   var localOrientation = false;     // fekvő kép
   var direction = slideNext;
   var thumbFrstWidth, thumbPrevWidth, thumbNextWidth;

   if (direction == 1)
    localOrientation = (nextSlide.width < nextSlide.height);
   else if (direction == -1)
         localOrientation = (prevSlide.width < prevSlide.height);
        else if (direction == 0)
              localOrientation = (frstSlide.width < frstSlide.height); // első kép
             else if (direction == slideMax)
                   localOrientation = (lastSlide.width < lastSlide.height); // utolsó kép

  if(localOrientation) {
    thumbFrstWidth = imgWidthP / 10;
    thumbLastWidth = imgWidthP / 10;
    thumbPrevWidth = imgWidthP / 10;
    thumbNextWidth = imgWidthP / 10;
  } else {
    thumbFrstWidth = imgWidth / 10;
    thumbLastWidth = imgWidth / 10;
    thumbPrevWidth = imgWidth / 10;
    thumbNextWidth = imgWidth / 10;
  }
  thumbWidth  = imgWidth / 10;
  thumbHeight = imgHeight / 10;
  
  if ( slideIndex == 0 ) {
   document.images.thumbAct.width  = thumbFrstWidth;
   document.images.thumbAct.height = thumbHeight;
   document.images.thumbAct.src  = frstSlide.src;
  }
  else {
   if ( slideNext == -1 ) {
    document.images.thumbAct.width  = thumbPrevWidth;
    document.images.thumbAct.height = thumbHeight;
    document.images.thumbAct.src  = document.images.thumbPrev.src;
   }
   else
    if ( slideNext == 1 ) {
     document.images.thumbAct.width  = thumbNextWidth;
     document.images.thumbAct.height = thumbHeight;
     document.images.thumbAct.src  = document.images.thumbNext.src;
    }
    else {
     document.images.thumbAct.width  = thumbLastWidth;
     document.images.thumbAct.height = thumbHeight;
     document.images.thumbAct.src  = lastSlide.src;
    }
  }

  if ( prevIndex < 0 )
   prevIndex = slideMax;

  prevSlide = new Image();
  prevSlide.src = mediaPath + imgName1 + arPic[prevIndex].slFile + imgName2;

  if (nextIndex > slideMax)
   nextIndex = 0;

  nextSlide = new Image();
  nextSlide.src = mediaPath + imgName1 + arPic[nextIndex].slFile + imgName2;

  lastSlide = new Image();
  if (prevIndex == slideMax)
   lastSlide.src = mediaPath + imgName1 + arPic[slideMax].slFile + imgName2;

  // Kis képek
  document.images.thumbPrev.width  = thumbWidth;
  document.images.thumbPrev.height = thumbHeight;
  document.images.thumbPrev.src = prevSlide.src;

  document.images.thumbNext.width  = thumbWidth;
  document.images.thumbNext.height = thumbHeight;
  document.images.thumbNext.src = nextSlide.src;
 }

 // -------------------------------------------------------------------
 // --- Image fade-in/-out code start
 // -------------------------------------------------------------------
 function fadeIn(asA)
 {
  if ( curpos < 100 && slideEffect == "fade" ) {
   curpos += fadingSpeed;

   if (asA.filters) {
    asA.filters.alpha.opacity = curpos;
   }

   if (asA.style.MozOpacity) {
    if ( curpos < 100 ) {
     asA.style.MozOpacity = curpos/100;
    }
    else {
     asA.style.MozOpacity = 0.99;
    }
   }

   if (asA.style.KhtmlOpacity) {
    asA.style.KhtmlOpacity = curpos/100;
   }

   if ( !fadeid )
    fadeid = setInterval("fadeIn(document.images.actSlide)", 10);
  }
  else {
   window.clearInterval(fadeid);
   fadeid = 0;
  }
 }
 // ----------------------------------------------------------------
 // ----
 function fadeOut(asA)
 {
  if ( curpos > 0 && slideEffect == "fade" ) {
   curpos -= fadingSpeed;

   if (asA.filters) {
    asA.filters.alpha.opacity = curpos;
   }

   if (asA.style.MozOpacity) {
    asA.style.MozOpacity = curpos/100;
   }

   if (asA.style.KhtmlOpacity) {
    asA.style.KhtmlOpacity = curpos/100;
   }

   if ( !fadeid )
    fadeid = setInterval("fadeOut(document.images.actSlide)", 10);
  }
  else {
   window.clearInterval(fadeid);
   fadeid = 0;

   changeSlide();
  }
 }
 // -------------------------------------------------------------------
 // --- Image fade-in/-out code end
 // -------------------------------------------------------------------

 // ----------------------------------------
 // --- Change slide image /resize image and table cell/
 // ----------------------------------------
 function changeSlide()
 {
   var cell  = document.all ? document.all["slideCell"] : document.getElementById ? document.getElementById("slideCell") : null;
   var cellT = document.all ? document.all["textCell"] : document.getElementById ? document.getElementById("textCell") : null;
   var descStr = getDescStr(slideIndex);
   var localOrientation = false;     // fekvő kép
   var direction = slideNext;

   if (direction == 1)
    localOrientation = (nextSlide.width < nextSlide.height);
   else if (direction == -1)
         localOrientation = (prevSlide.width < prevSlide.height);
        else if (direction == 0)
              localOrientation = (frstSlide.width < frstSlide.height); // első kép
             else if (direction == slideMax)
                   localOrientation = (lastSlide.width < lastSlide.height); // utolsó kép

   if ( localOrientation ) { // Portrait
    document.images.actSlide.width  = imgWidthP;
    document.images.actSlide.height = imgHeightP;

    cell.width  = imgWidthP;
    cellT.width = imgWidthP;
    cell.height = imgHeightP;
   }
   else { // Landscape
    document.images.actSlide.width  = imgWidth;
    document.images.actSlide.height = imgHeight;

    cell.width  = imgWidth;
    cellT.width = imgWidth;
    cell.height = imgHeight;
   }

    if (direction == 1) {
        document.images.actSlide.src = nextSlide.src;
    } else if (direction == -1)
         document.images.actSlide.src = prevSlide.src;
        else if (direction == 0)
              document.images.actSlide.src = frstSlide.src; // első kép
             else if (direction == slideMax)
                   document.images.actSlide.src = lastSlide.src; // utolsó kép

   document.images.actSlide.alt = "   " + getLangStr2("T_SLIDE") + "  " + (slideIndex+1) + "   ";

   preLoadSlides();

   fadeIn(document.images.actSlide);

   setTextValue("countCell", getLangStr2("T_SLIDE") + "\t" + (slideIndex+1) + " / " + (slideMax+1) + "\n");

   setStatusText("");
   setElementVisibility ("statusCell", HIDE_E);

   if ( descStr.length )
    setTextValue("textCell", '<font color="'+descTextColor+'">'+descStr+'</font>');
   else
    setTextValue("textCell", " ");

   return (true);
 }
 // ----------------------------------------
 // --- check before change
 // ----------------------------------------
 function ready2Change(direction)
 {
  var enableChange = true;

  slideNext = direction;

  if (direction == -1)
   enableChange = (isComplete(prevSlide) && prevSlide.width && prevSlide.height);
  else if (direction == 1)
        enableChange = (isComplete(nextSlide) && nextSlide.width && nextSlide.height);
       else if (direction == 0) 
             enableChange = (isComplete(frstSlide) && frstSlide.width && frstSlide.height);
            else
             enableChange = (isComplete(lastSlide) && lastSlide.width && lastSlide.height);

  if (msie) {
   (enableChange <= 50) ? enableChange = false : enableChange = true;
  }

  if ( !enableChange ) {
   setStatusText("T_LOAD");
   if ( !processDL ) {
    setTextValue('statusCell', '<font class="status">' + getLangStr2("T_LOAD") + '</font>');
    setElementVisibility ('statusCell', SHOW_E);
   }
   processDL = true;
  }
  else {
   setElementVisibility ('statusCell', HIDE_E);
   processDL = false;
   cntTimeout = 0;
  }

  return (enableChange);
 }
 // ----------------------------------------
 // --- Auto mode function and timer
 // ----------------------------------------
 function autoStep()
 {
  var     prevSlideIndex = slideIndex, direction = 1;

  //setTextValue('timeCell', getLangStr2("T_TIME") + " " + getSlideTime() + " (Timeout= "+cntTimeout+")");
  setTextValue('timeCell', getLangStr2("T_TIME") + " " + getSlideTime());

  if (slideCounter == (slideTime-1) || processDL ) { // Következő slide
   prevSlideIndex = slideIndex++;

   if ( slideIndex == (slideMax+1) ) {
    if ( autoBackToMenu && !showAllControl )
     history.back();
    else
     slideIndex = 0;
   }

   if (prevSlideIndex == -1)
    direction = 0;

   if (prevSlideIndex != slideIndex)
    if ( ready2Change(direction) ) { // Csak akkor cserél, ha már letöltődött a következő
     fadeOut(document.images.actSlide);
    }
    else {
     slideIndex = prevSlideIndex;
    }
  }

  if ( processDL ) {
   cntTimeout++;
   if ( cntTimeout == slideTimeout ) {
    if ( slideNext != slideMax )
     slideIndex += slideNext;
    else slideIndex = slideMax;

    arPic[slideIndex].slValid = false;

    preLoadSlides ();
    cntTimeout = 0;
    processDL = false;

    slideCounter = slideTime-2;
   }
  }

  if ( !popupOpen ) // Csak akkor megy tovább, ha már bezárták a nagy ablakot
   if ( ++slideCounter > slideTime )
    slideCounter = 0;
 }
 // ----------------------------------------
 // --- Manual mode timer
 // ----------------------------------------
 function manualStepTimer(direction)
 {
  //setTextValue('timeCell', getLangStr2("T_TIME") + " " + getManualTime() + " (Timeout= "+cntTimeout+")");
  setTextValue('timeCell', getLangStr2("T_TIME") + " " + getManualTime());

  if ( processDL )
   manualStep (slideNext);
 }
 // ----------------------------------------
 // --- Manual mode function
 // ----------------------------------------
 function manualStep(direction)
 {
  var     prevSlideIndex = slideIndex;

  if (direction != 0) {
   if (direction != slideMax)
    slideIndex += direction;
   else slideIndex = slideMax;
  }
  else
   slideIndex = 0;

  if (slideIndex > slideMax)
   slideIndex = 0;

  if (slideIndex < 0)
   slideIndex = slideMax;

  if (prevSlideIndex != slideIndex)
   if ( ready2Change(direction) ) { // Csak akkor cserél, ha már letöltődött a következő
    fadeOut(document.images.actSlide);
   }
   else slideIndex = prevSlideIndex;

  if ( processDL ) {
   cntTimeout++;
   if ( cntTimeout == slideTimeout ) {
    if ( slideNext != slideMax )
     slideIndex += slideNext;
    else slideIndex = slideMax;

    arPic[slideIndex].slValid = false;

    preLoadSlides ();
    cntTimeout = 0;
   }
  }
 }
 // ----------------------------------------
 // --- Select auto/manual mode
 // ----------------------------------------
 function jumpTo(direction)
 {
  var     result, qStr;
  var     sign, newIdx;

  qStr = getLangStr2("H_JUMP_B").substring(0, getLangStr2("H_JUMP_B").indexOf(' [')) + ":";

  newIdx = slideIndex + (direction*jumpLength);

  if ( newIdx > slideMax )
   newIdx -= slideMax;

  if ( newIdx < 0 )
   newIdx += slideMax;

  result = prompt (qStr, newIdx+1);

  if (result) {
   sign = result.charAt(0);
   index = parseInt (result, 10);
   if ( !isNaN(index) ) {
    if ( sign == '+' || sign == '-' ) {
     // relativ position
     newIndex = slideIndex + index;

     if ( newIndex > slideMax )
      index = newIndex - slideMax;
     else
      if ( newIndex < 0 )
       index = newIndex + slideMax;
      else index = newIndex;

     if ( index > slideMax )
      index = slideMax;
     else if ( index < 0 )
           index = 1;

     slideIndex = index-1;
//     alert (slideIndex);
    }
    else {
     // absolute position
     if ( index > slideMax )
      index = slideMax;
     else
      index--;

     slideIndex = index - 1;
    }

    preLoadSlides ();
    manualStep (1);
   }
  }
 }
 // ----------------------------------------
 // --- Select auto/manual mode
 // ----------------------------------------
 function selectMode()
 {
  processDL  = false;
  cntTimeout = 0;

  if (autoMode == true) {
   
   autoMode = false;
   window.clearInterval(runid);

   //setTextValue('timeCell', ' ');

   setTextValue('autoSlide', '<b>' + getLangStr2("SL_MODE_M") + '</b>');

   // Show manual controls
   setElementVisibility ('slideControlAll', SHOW_E);

   setElementVisibility ('slideControlLeft', SHOW_E);
   setElementVisibility ('slideControlRight', SHOW_E);

   runid = setInterval("manualStepTimer()", 1000);
  }
  else
   if (autoMode == false) {
    window.clearInterval(runid);

    Clock = new Date();

    setTextValue('autoSlide', '<b>' + getLangStr2("SL_MODE_A") + '</b>');

    // Show all control in auto mode
    if ( showAllControl && startAutoMode )
     setElementVisibility ('slideControlAll', SHOW_E);

    // Hide manual controls
    setElementVisibility ('slideControlLeft', HIDE_E);
    setElementVisibility ('slideControlRight', HIDE_E);

    if (!codeInit)
     slideCounter = 0;

    autoMode  = true;
    popupOpen = false;
    runid = setInterval("autoStep()", 1000);
   }

  setStatusText("");
 }
 // ----------------------------------------
 // --- Waitin for first slide to download
 // ----------------------------------------
 function waitFirstSlide()
 {
  if (isComplete(frstSlide)) {
   window.clearInterval(waitid);

   if (autoMode)
    autoStep();
   else
    manualStep(0);

   setElementVisibility ("statusCell", HIDE_E);

   setElementVisibility ("slideTable", SHOW_E);
   setElementVisibility ("footerCell", SHOW_E);
   setElementVisibility ("otherControls", SHOW_E);
  }
  else
   setStatusText("T_LOAD");
 }

 // ----------------------------------------
 // --- Set page elements (->pageLang)
 // ----------------------------------------
 function pageInit()
 {
  // Fade tiltása, ha a képek linkje egy php oldal
  if ( msie && mediaPath.indexOf("php?") > 0 )
   slideEffect = "none";

  // Színek
  var pBody = document.all ? document.all["slidePage"] : document.getElementById ? document.getElementById("slidePage") : null;

  pBody.style.background = bodyBgColor;

  // Megjelenő szövegek
  setTextValue("firstSlide", getLangStr2("SL_FIRST"));
  setTextValue("prevSlide", getLangStr2("SL_PREV"));
  setTextValue("nextSlide", getLangStr2("SL_NEXT"));
  setTextValue("lastSlide", getLangStr2("SL_LAST"));
  setTextValue("jumpToSlide1", getLangStr2("SL_JUMP_B"));

  setTextValue("setupLink", getLangStr2("SL_OPTIONS"));
  setTextValue("helpLink", getLangStr2("SL_HELP"));
  setTextValue("backToLink", getLangStr2("SL_BACK"));
  setTextValue("listLink", getLangStr2("SL_LIST"));

  setTextValue('statusCell', '<font size="+1" color="red" style="font-style:italic; font-weight:bold;">'+getLangStr2("T_START")+'</font>');

  pageReInit();
 }

 function pageReInit()
 {
  // Átméretezés
  if ( resizePortrait ) {
   imgWidthP  = (imgHeight / imgWidth) * imgHeight;
   imgHeightP = imgHeight;
  }

   if (isFading){
    slideEffect = "fade";
   } else {
    slideEffect = "none";
   }

  // Effektus
  if ( slideEffect == "none") {
   if (document.images.actSlide.filters)
    document.images.actSlide.filters.alpha.opacity = 100;

   if (document.images.actSlide.style.MozOpacity)
    document.images.actSlide.style.MozOpacity = 1.0;

   if (document.images.actSlide.style.KhtmlOpacity)
    document.images.actSlide.style.KhtmlOpacity = 1.0;
  }
 
 }

 // ----------------------------------------
 // --- Check referrer
 // ----------------------------------------
 function checkReferrerPage()
 {
    //legyen ez mindig ok, nem kell az ellenőrzés
    return true;
 /*
  var     fResult = false;
  var     pos, sbuf, i = 0;

  if ( document.referrer.length ) {
   while ( i < validReferrer.length ) {
    sbuf = validReferrer[i++];
    pos = document.referrer.indexOf(sbuf);
    if ( pos == 7 ) {
     fResult = true;
     break;
    }
   }
  }
  else
   fResult = true;

  return (fResult);
  */
 }
 // ----------------------------------------
 // --- Find and set parameters from URL search part
 // ----------------------------------------
 function applyParam(paramstr)
 {
  var pname, pvalue;
  var pos;

  pos = paramstr.indexOf('=');
  if ( pos != -1 ) {
   pname = paramstr.substring(0, pos);
   pvalue = paramstr.substring(pos+1, paramstr.length);

   pname = pname.toLowerCase();
   pvalue= pvalue.toLowerCase();

   if (pname.indexOf("lang") != -1) { // Lang=
    if (pvalue.indexOf("hu") == 0)
     pageLang = LANG_HU;
   }
   else
    if (pname.indexOf("automode") != -1) { // StartAutoMode=
     if ((pvalue == "true") || (pvalue == "1"))
      startAutoMode = true;
    }
    else
     if (pname.indexOf("allcontrol") != -1) { // ShowAllControl=
      if ((pvalue == "true") || (pvalue == "1"))
       showAllControl = true;
     }
     else
      if (pname.indexOf("startaudio") == 0) { // StartAudio=
       if ((pvalue == "true") || (pvalue == "1"))
        startAudio = true;
      }
      else
       if (pname.indexOf("slidetime") != -1) { // slideTime=
        if (parseInt(pvalue) != NaN )
         slideTime = pvalue;
       }
       else
        if (pname.indexOf("imagewidth") != -1) { // ImageWidth=
         if (parseInt(pvalue) != NaN )
          imgWidth = pvalue;
        }
        else
         if (pname.indexOf("imageheight") != -1) { // ImageHeight=
          if (parseInt(pvalue) != NaN )
           imgHeight = pvalue;
         }
         else
          if (pname.indexOf("autoback") != -1) { // AutoBack=
           if ((pvalue == "true") || (pvalue == "1"))
            autoBackToMenu = true;
          }
          else
           if (pname.indexOf("project") != -1) { // project=
            if (parseInt(pvalue) != NaN )
             project = pvalue;
           }
           else
            if (pname.indexOf("simple") != -1) { // simple=
             if ((pvalue == "true") || (pvalue == "1"))
              simple = true;
            }
            else
             if (pname.indexOf("page") != -1) { // page=
              if (parseInt(pvalue) != NaN )
               page = pvalue;
             }
  } // if ( pos ...
 }
 // ----------------------------------------
 // --- Split parameters line from URL search part
 // ----------------------------------------
 function parseURL()
 {
  var str;
  var prevPos = 0, pos;

  if ( location.search.length ) {
   // Remove first char (?)
   str = location.search.substring(1, location.search.length);
   // Split strings
   pos = str.indexOf('&');
   while (pos != -1) {
    applyParam( str.substring(prevPos, pos) );
    prevPos = pos + 1;
    pos = str.indexOf('&', prevPos);
   }
   // Last parameter
   applyParam( str.substring(prevPos, str.length) );
  }
 }

 // ----------------------------------------
 // --- Initialize slideshow
 // ----------------------------------------
 function firstInit()
 {
  if ( checkReferrerPage() ) {
   parseURL();
   getSlideshowParams();

   // -- vajon a kicsi vagy a nagy kepet hasznaljuk previewnak?
   if (imgHeight>360) {
    imgName1  = "img_";
    imgName2  = ".jpg";
   }
   if (project>0) {
        mediaPath = "/scripts/dl.rta?p="+project+"&n=";
   }
   if (isPreview) {
    setThumbsVisibility();
   }

   setStatusText("T_LOAD");

   // --- Initialize internal variables
   autoMode = !startAutoMode;
   slideCounter = slideTime-1;

   if (simple) {
    setElementVisibility ("statusCell", HIDE_E);
    simpleSS();
    return;
   }

   selectMode();
   pageInit();

   frstSlide = new Image();
   frstSlide.src = mediaPath + imgName1 + arPic[0].slFile + imgName2;
   
   if (!isComplete(frstSlide))
    waitid = setInterval("waitFirstSlide()", 1000);
   else {
    setElementVisibility ("statusCell", HIDE_E);

    if (autoMode)
     autoStep();
    else
     manualStep(0);

    setElementVisibility ("slideTable", SHOW_E);
    setElementVisibility ("footerCell", SHOW_E);
    setElementVisibility ("otherControls", SHOW_E);
   }
  }
  else {
   //history.back();
//   alert ( getLangStr2("T_REFERRER") );
  }

  codeInit = false;
 }
 // ----------------------------------------
 // --- egyszerű listázás
 // ----------------------------------------

 function simpleSS() {
    var picPerPage = 20;
    var isPrev=0, isNext=0, pageLink = "";

    var str = location+"";
    var pos = str.indexOf('&page');
    if (pos<0) { 
        pos=str.length; 
    }
    var pageNext = parseInt(page)+1;
    var pagePrev = parseInt(page)-1;
    var urlNext = str.substring(0,pos)+"&page="+pageNext;
    var urlPrev = str.substring(0,pos)+"&page="+pagePrev;

    var numOffset = page*picPerPage;
    if ((parseInt(page)+1)*picPerPage<arPic.length) {
        isNext = 1;
    }
    if (page>0) {
        isPrev = 1;
    }
    if (isPrev) {
        pageLink = "<a href='"+urlPrev+"'>&lt;&lt;</a>&nbsp;&nbsp;";
    }
    if (isNext) {
        pageLink = pageLink + "<a href='"+urlNext+"'>&gt;&gt;</a>";
    }
    
    var back = document.getElementById("backToLink");    
    document.writeln("<div class='center'>");
    document.writeln("<a href=\""+back+"\">"+getLangStr2("SL_BACK")+"</a><br/><br/>");
    document.writeln("</div>");
    document.writeln("<div class='center'>");
    document.writeln(pageLink);
    document.writeln("</div>");
    document.writeln("<div class='center'>");
    var i = 1 + numOffset;
    while (i<arPic.length+1) {
        document.writeln("<a class='nobg' target='external' href='"+mediaPath+"img_"+arPic[i-1].slFile+".jpg'><img src='"+mediaPath+"preview/img_"+arPic[i-1].slFile+"_s.jpg' height='300'></a><br/>");
        var text = getDescStr(i-1);
        document.writeln("<p>"+text+"</p>");
        if (i%picPerPage==0) {
            break;
        }
        i++;
    }
    document.writeln("</div>");

    document.writeln("<div class='center'>");
    document.writeln(pageLink);
    document.writeln("</div>");
 }
 