/*
******************************************************************************
SLIDESHOW v0.5 (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();
    var d = document.createElement("div");
    if(isrc.substr(0,1)=='<') {
      d.innerHTML = isrc;
    } else {
      var i = document.createElement("img");
      i.src = isrc;
      i.style.verticalAlign = "middle";
      d.insertBefore(i, d.firstChild);
    }
    d.style.position = "absolute";
    d.style.top = "0px"; d.style.left = "0px";
    d.style.width = "100%"; d.style.height = "100%";
    d.style.textAlign = "center";
    d.style.visibility = "hidden";
    d.style.background = "white";
    ss_so(d,0);
    o.insertBefore(d, o.firstChild);
    d.style.height = o.offsetHeight+"px";
    d.style.lineHeight = (o.offsetHeight-4)+"px"; // correction
    d.style.overflow = "hidden"; // correction
  }
  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);
    if(!o) return false;
    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);
  }
}

function slideshowEx(id, width, height, imgs, fadetime, waittime, smartphones) {
  var o = document.getElementById(id);
  if(!o) return false;
  o.style.width = width+"px";
  o.style.height = height+"px";
  slideshow(id, imgs, fadetime, waittime, smartphones);
}


