//FADE IN

var otype = '';
document.write("<style type='text/css'>#ss1-sl1front {display:none;}</style>");

function initImage() {
  var imageId = 'ss1-sl1front';
  var image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.display = "inline";
  image.style.visibility = "visible";
  fadeIn(imageId,0);
}
function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


window.onload = function() {
    // Browser detection - do this before the fade widget interferes with the result!
    img = document.getElementById('ss1-sl1front');
    if (typeof img.style.opacity != 'undefined')
    {
        otype='w3c';
    }
    else if (typeof img.style.MozOpacity != 'undefined')
    {
        otype='moz';
    }
    else if (typeof img.style.MKhtmlOpacity != 'undefined')
    {
        otype='khtml';
    }
    else if (typeof img.filters =='object')
    {
          otype = (img.filters.length >0
          && typeof img.filters.alpha == 'object'
          && typeof img.filters.alpha.opacity == 'number')
          ? 'ie' : 'none';
    }
    else { otype = 'none';}

    initImage();
}

function swapimg(id) {
   var targetImg = document.getElementById('mainimg');
   targetImg.src="images/gallery/"+id+".jpg";
}

//slideshow script
function startSlideshow(path, numimgs, numslots, timer, rnd, start)
{
  if (start==0) var firstimg = 1 + Math.floor(Math.random()*numimgs);   // random first image
      else var firstimg = start;
       // we use base 0 for our slot calculations
  var delay = timer + ( Math.random()*rnd)- (rnd/2)  // random length of time if rnd is non-zero
  window.setTimeout('cueNextSlide("'+path+'",'+firstimg+','+numimgs+',0,'+numslots+','+timer+','+rnd+')', delay*1000);
}
function cueNextSlide(path, imgno, numimgs, slotno, numslots, timer, rnd)
{
  if (slotno >= numslots) { toback=false; } else { toback=true;  }
  var nextimg = (imgno % numimgs) + 1;
  var nextimgforthisslot = ((imgno+numslots)%numimgs)+1
  var nextslot = (slotno+1)%(numslots*2);
  var thisslot = (slotno%numslots)+1;
  var frontId = path+'-sl'+thisslot+'front';
  var backId = path+'-sl'+thisslot+'back';
  var delay = timer + ( Math.random()*rnd)- (rnd/2);  // random length of time if rnd is non-zero
  if (toback) {
     window.setTimeout('changeimg("front","'+path+'","'+thisslot+'","'+nextimgforthisslot+'")', delay*500);
     fade(backId, 0.4, 'in');
     fade(frontId, 0.4, 'out');
  }
  else
  {
     window.setTimeout('changeimg("back","'+path+'","'+thisslot+'","'+nextimgforthisslot+'")', delay*500);
     fade(frontId, 0.4, 'in');
     fade(backId, 0.4, 'out');
  }
  window.setTimeout('cueNextSlide("'+path+'",'+nextimg+','+numimgs+','+nextslot+','+numslots+','+timer+','+rnd+')', delay*1000);
}
function changeimg(layer, path, thisslot, imgno)
{
  var chgimgId = path+'-sl'+thisslot+layer;
  chgimg = document.getElementById(chgimgId);
  chgimg.src="images/"+path+"/sshow"+imgno+".jpg";
}
function fade(img, time, dir)
{
  img = document.getElementById(img);
  var steps=time*10;
  if (otype != 'none')
  {
    if (dir == 'out') { dofade(steps,img,1,false,otype);}
    else { dofade(steps, img, 0, true, otype); }
  }
}
function dofade(steps, img, value, targetvisibility, otype)
{
  value += (targetvisibility ? 1 : -1) / steps;
  if (targetvisibility ? value >1 : value <0)
    value = targetvisibility ? 1:0;
  setfade(img,value,otype);
  if (targetvisibility ? value <1 : value >0)
  {
    setTimeout(function()
    {
      dofade(steps, img, value, targetvisibility, otype);
    }, 100);
  }
}
function setfade(img,value, otype)
{
  switch(otype)
  {
    case 'ie':
      img.filters.alpha.opacity = value * 100;
      break;
    case 'khtml':
      img.style.KhtmlOpacity = value;
      break;
    case 'moz':
      img.style.MozOpacity = (value==1?0.9999999 : value);
      break;
    default:
      img.style.opacity = (value == 1?0.9999999 : value);
  }
}