/*
******************************************************************************
SLIDESHOW v0.4 (c)Dynavox
******************************************************************************
*/
function smartphone() {var a=navigator.userAgent.toLowerCase(); return (a.search(/iphone|android|palm|symbian|blackberry/)!=-1); }
function ss_so(o,v) { o.style.filter = (v!=1)?"alpha(opacity="+v*100+")":""; o.style.opacity = v; } // bug-fix for IE's 0x02050a color bug
function ss_time() { return (new Date).getTime(); }
function ss_wait(o) {
  if(o.ss_last) o.ss_last.style.visibility = "hidden";
  if(o.ss_imgs.length) {
    var isrc = o.ss_imgs.shift();
    if(isrc.substr(0,1)=='<') {
      var d = document.createElement("div");
      d.innerHTML = isrc;
      var i = d.firstChild;
    } else {
      var i = document.createElement("img");
      i.src = isrc;
    }
    i.style.position = "absolute";
    i.style.top = "0px"; i.style.left = "0px";
    i.style.visibility = "hidden";
    ss_so(i,0);
    o.insertBefore(i, o.firstChild);
  }
  var w = o.lastChild?o.ss_waittime:0;
  window.setTimeout(function(){ss_waitend(o)},w);
}
function ss_waitend(o) {
  var i = o.firstChild;
  i.style.zoom = 1; // IE needs to have layout
  i.style.visibility = "visible";
  ss_so(i,0);
  o.appendChild(i);
  o.ss_last = o.ss_next;
  o.ss_next = i;
  o.ss_time = ss_time();
  window.setTimeout(function(){ss_anim(o)},20);
}
function ss_anim(o) {
  var v = (Math.max(0,ss_time()-o.ss_time))/o.ss_fadetime;
  if(v<1.0) {
    ss_so(o.ss_next,0.5-Math.cos(v*Math.PI)*0.5);
    window.setTimeout(function(){ss_anim(o)},20);
  } else {
    ss_so(o.ss_next,1);
    ss_wait(o);
  }
}

function slideshow(id, imgs, fadetime, waittime, smartphones) {
  if(((smartphones===undefined)?1:smartphones) || !smartphone()) {
    var o = document.getElementById(id);
    o.style.position = "relative";
    var c = o.firstChild;
    while(c) {
      var nc = c.nextSibling;
      if(c.nodeType!=1) o.removeChild(c);
      else {
        c.style.position = "absolute";
        c.style.top = "0px"; c.style.left = "0px";
      }
      c = nc;
    }
    if(o.hasChildNodes()) {
      o.ss_next = o.lastChild;
      o.ss_next.style.position = "absolute";
    }
    o.ss_imgs = imgs;
    o.ss_fadetime = fadetime?fadetime:2000;
    o.ss_waittime = waittime?waittime:2000;
    ss_wait(o);
  }
}

