//FADE IN

document.write("<style type='text/css'>#fadein {visibility:hidden;display:block}</style>");

function initImage() {
  imageId = 'fadein';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  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() {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, imagetype)
{
  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+',"'+imagetype+'")', delay*500);
}
function cueNextSlide(path, imgno, numimgs, slotno, numslots, timer, rnd, imagetype)
{
  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+'","'+imagetype+'")', delay*750);
     fade(backId,0.5, 'in');
     fade(frontId, 0.5, 'out');
  }
  else
  {
     window.setTimeout('changeimg("back","'+path+'","'+thisslot+'","'+nextimgforthisslot+'","'+imagetype+'")', delay*750);
     fade(frontId,0.5,'in');
     fade(backId,0.5,'out');
  }
  window.setTimeout('cueNextSlide("'+path+'",'+nextimg+','+numimgs+','+nextslot+','+numslots+','+timer+','+rnd+',"'+imagetype+'")', delay*1000);
}
function changeimg(layer, path, thisslot, imgno,imagetype)
{
  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 (typeof img.style.opacity != 'undefined')
  {
    var otype='w3c';
  }
  else if (typeof img.style.MozOpacity != 'undefined')
  {
    var otype='moz';
  }
  else if (typeof img.style.MKhtmlOpacity != 'undefined')
  {
    var 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';}
  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);
  }
}


function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}
addLoadEvent(preload);

function preload() {
a = new Image();
a.src = 'images/gallery/1.jpg';
b = new Image(); 
b.src = 'images/gallery/2.jpg'; 
c = new Image(); 
c.src = 'images/gallery/3.jpg'; 
d = new Image(); 
d.src = 'images/gallery/4.jpg'; 
e = new Image(); 
e.src = 'images/gallery/5.jpg'; 
f = new Image(); 
f.src = 'images/gallery/6.jpg'; 
g = new Image(); 
g.src = 'images/gallery/7.jpg'; 
h = new Image(); 
h.src = 'images/gallery/8.jpg'; 
i = new Image(); 
i.src = 'images/gallery/9.jpg'; 
j = new Image(); 
j.src = 'images/gallery/10.jpg'; 
k = new Image(); 
k.src = 'images/gallery/11.jpg'; 
l = new Image(); 
l.src = 'images/gallery/12.jpg'; 
m = new Image(); 
m.src = 'images/gallery/13.jpg'; 
n = new Image(); 
n.src = 'images/gallery/14.jpg'; 
o = new Image(); 
o.src = 'images/gallery/15.jpg'; 
p = new Image(); 
p.src = 'images/gallery/16.jpg'; 
q = new Image(); 
q.src = 'images/gallery/17.jpg'; 
r = new Image(); 
r.src = 'images/gallery/18.jpg'; 
s = new Image(); 
s.src = 'images/gallery/19.jpg'; 
t = new Image(); 
t.src = 'images/gallery/20.jpg'; 
}