// (C) 2002 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header.

// ==============================
// Set the following variables...
// ==============================

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 4000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var Picture = new Array(); // don't change this
var Caption = new Array(); // don't change this

// Specify the image files...
// To add more images, just continue
// the pattern, adding to the array below.
// To use fewer images, remove lines
// starting at the end of the Picture array.
// Caution: The number of Pictures *must*
// equal the number of Captions!

// Picture[1]  = 'Image001.jpg';
// Picture[2]  = 'Image002.jpg';
// Picture[3]  = 'Image003.jpg';
// Picture[4]  = 'Image004.jpg';
// Picture[5]  = 'Image005.jpg';
// Picture[6]  = 'Image006.jpg';
// Picture[7]  = 'Image007.jpg';
// Picture[8]  = 'Image008.jpg';
// Picture[9]  = 'Image009.jpg';
// Picture[10] = 'Image010.jpg';

// Specify the Captions...
// To add more captions, just continue
// the pattern, adding to the array below.
// To use fewer captions, remove lines
// starting at the end of the Caption array.
// Caution: The number of Captions *must*
// equal the number of Pictures!

// Caption[1]  = "This is the first caption.";
// Caption[2]  = "This is the second caption.";
// Caption[3]  = "This is the third caption.";
// Caption[4]  = "This is the fourth caption.";
// Caption[5]  = "This is the fifth caption.";
// Caption[6]  = "This is the sixth caption.";
// Caption[7]  = "This is the seventh caption.";
// Caption[8]  = "This is the eighth caption.";
// Caption[9]  = "This is the ninth caption.";
// Caption[10] = "This is the tenth caption.";
// 
// =====================================
// Do not edit anything below this line!
// =====================================

// var tss;
var iss = 1;
var jss = 1;
var pss = 0;
var preLoad = new Array();


function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function initSlideShow(){
  if (!document.getElementsByTagName)
  {
    return;
  }

  var anchors = document.getElementsByTagName('img');
  var j = 1;
  anchors = getElementsByClassName(document, "img", "home-slideshow");

  // loop through all anchor tags
  for (var i=0; i<anchors.length; i++)
  {
    var anchor = anchors[i];
    // use the string.match() method to catch 'lightbox' references in the rel attribute
    //alert( 'test3:' + String(i) + ' ' + anchor.getAttribute('src') + "\n" + String( anchor.getAttribute('class') ) + "\n" + String( anchor.class ) );
    //var myClass=String(anchor.getAttribute('class'));
    //if ( anchor.getAttribute('src') && anchor.getAttribute('class') && myClass.toLowerCase().match('ors') )
    //{
    //  alert(j);
      Picture[j]=String(anchor.getAttribute('src'));
      Caption[j]=String(anchor.getAttribute('alt'));
      //Picture[j]=String(anchor.src);
      //Caption[j]=String(anchor.alt);
      j = j+1;
    //}
    
   // if ( anchor.class && anchor.className.toLowerCase().match('ors') )
   // {
    //    j = j+1;
    //}
  }

  pss = Picture.length-1;
  // 
  for (iss = 1; iss < pss+1; iss++){
  preLoad[iss] = new Image();
  preLoad[iss].src = Picture[iss];}
  // 
  // alert( 'length: ' + String(preLoad.length) +
  //        preLoad[iss].src );
  setTimeout("Event.observe(window, 'load', runSlideShow(), false)", 4000);
}

function runSlideShow()
{ 
  if (document.all)
  {
    document.images.picturebox.style.filter="blendTrans(duration=2)";
    document.images.picturebox.style.filter="blendTrans(duration=CrossFadeDuration)";
    document.images.picturebox.filters.blendTrans.Apply();
    //document.images.picturebox.src = preLoad[jss].src;
    //document.images.picturebox.src = 'http://www2.bertagnolli.it' + Picture[jss];
    document.images.picturebox.src = Picture[jss];
    //alert( jss + ' ' + String(Picture[jss]) );
  }
  if (document.getElementById) {
  //document.getElementById("picturebox").src = preLoad[jss].src;
  //alert( jss + ' ' + String(Picture[jss]) );
  //document.getElementById("picturebox").src = 'http://www2.bertagnolli.it' + Picture[jss];
  document.getElementById("picturebox").src = Picture[jss];
  }
  if (document.getElementById)
    document.getElementById("captionbox").innerHTML= Caption[jss];
  if (document.all)
    document.images.picturebox.filters.blendTrans.Play();

  jss = jss + 1;

  if (jss > (pss))
    jss=1;

  var tss = setTimeout('runSlideShow()', SlideShowSpeed);
}

setTimeout("Event.observe(window, 'load', initSlideShow(), false)", 4000);

// Event.observe(window, 'load', runSlideShow());
