var ss = new Array()
var sscurr = new Array()

// Scroll through the DIVs that are part of classname
// Direction is 1 = forward, -1 backward
function ssnext( classname, direction ) {
 var previtem = sscurr[classname]
 
 if( direction == 1 ) {
  sscurr[classname] = (sscurr[classname] < ss[classname].length-1) ? sscurr[classname] + 1 : 0
 } else {
  sscurr[classname] = (sscurr[classname] > 0) ? sscurr[classname] - 1 : ss[classname].length-1
 }
 ss[classname][previtem].style.display="none"
 ss[classname][sscurr[classname]].style.display="block"
 ssshowimages( ss[classname][sscurr[classname]] )
}

// Jump to a specific DIV and hide the rest
function sspick( classname, item ) {
 for( i = 0; i < ss[classname].length; i++ ) {
  if( i != item ) {
   ss[classname][i].style.display = "none"
  } else {
   ss[classname][i].style.display = "block"
   ssshowimages( ss[classname][i] )
  }
 }
}

// Show all elements
function ssexpand( classname ) {
 for( i = 0; i < items.length; i++ ) {
  ss[classname][i].style.display="block"
  ssshowimages( ss[classname][i] )  
//  ctrls[i].style.display="none"
 }
 document.getElementById("ssctrlall").innerHTML = '<a href="javascript:sscollapse()">View slideshow</a>'
}

// Hide all elements except first
function sscollapse( classname ) {
 for( i = 0; i < items.length; i++ ) {
  ss[classname][i].style.display="none"
  ctrls[i].style.display="block"
 }
 ss[classname][sscurr[classname]].style.display="block"
 document.getElementById("ssctrlall").innerHTML = '<a href="javascript:ssexpand()">Show all photos</a>'
}

// Deferred image loader
function ssshowimages( elt ) {
 var imgs = elt.getElementsByTagName("var")
 if( imgs ) {
  for( j = 0; j < imgs.length; j++ ) {
   var imgurl = imgs[j].textContent
   if( imgurl ) {
    var parent = imgs[j].parentNode
    parent.innerHTML = '<img src="' + imgurl + '">'
   }
  } 
 }
}

// Loop through all tags, find and record those with a class name starting with "ss"
window.onload = function() {
 if( document.all || document.getElementById ) {
  var alltags = document.all ? document.all : document.getElementsByTagName("*")
  var re = /^ss/
  for( i = 0; i < alltags.length; i++ ) {
   var cn = alltags[i].className
   if( re.test( cn ) ) {
    if( !ss[cn] ) { 
     ss[cn] = Array(); 
    }
    var lh = ss[cn].length
    ss[cn][lh] = alltags[i]
    if( lh == 0 ) {
     sscurr[cn] = 0  
     ss[cn][lh].style.display="block"
    } else {
     ss[cn][lh].style.display="none"
    }
   }
  }
 }
}

