//the revolution will not be framed

if (self!=top) top.location=self.location;

window.onload=dostuff;

var slidedir=0;
var slideshow=false;

function scrolltothumb() {
// function to scroll the thumbs div so thumb for current image is showing.
// variable t is used because not all browsers report the position of an element at the top/left of the div as the same thing. some report the distance from edge of viewport, some from edge of the div.
// Attributes used not part of DOM but work in IE, Firefox, Mozilla, Opera, Konqueror and Safari
   if (document.getElementById('marker')) {
      if (document.getElementById('marker').offsetTop) {
         var tt=parseInt(document.getElementById('thumbtop').offsetTop,10); 
         var pt=parseInt(document.getElementById('marker').offsetTop,10);
	 var tl=parseInt(document.getElementById('thumbtop').offsetLeft,10); 
         var pl=parseInt(document.getElementById('marker').offsetLeft,10);
         document.getElementById("thumbs").scrollTop=(pt-tt);
         document.getElementById("thumbs").scrollLeft=(pl-tl);
      }
   }
}

var sst_fwd="Start slideshow - forwards"
var sst_back="Start slideshow - backwards"

function toggleslideshow(dir) {
   if (dir==slidedir) {
      if (!slideshow) startslideshow(dir);
      else stopslideshow(dir);
   } else {
      if (!slideshow) {
         startslideshow(dir);
      } else {
         stopslideshow(slidedir);
         startslideshow(dir);
      }
   }
}

function startslideshow(d) {
   slidedir=parseInt(d,10);
   var e=(slidedir>0) ? "fwd" : "back"
   var oe=(slidedir>0) ? "back" : "fwd"
   document.getElementById("slide"+e).className="slidecontrolon"
   document.getElementById("slide"+e).title="Stop slideshow"
   document.getElementById("slide"+oe).title="Reverse slideshow direction"
   //var l=document.location.href;
   //var l=l.substring(0,l.indexOf('?'));
   //slideshowtimer=setTimeout("document.location.href='"+l+"?photo="+(currentimage+dir)+"&slide="+dir+"'",5000);
  // var t=document.getElementById("thumb"+(currentimage+dir));
 //  slideshowtimer=setTimeout( function() { showbigphoto(t); },5000);
   if (d>0) {
      slideshowtimer=setInterval("nextimage()",5000);
   } else {
      slideshowtimer=setInterval("previousimage()",5000);
   }
   slideshow=true;
}
     //woosh=setTimeout(function() {
    // expandimg(sw,sh,bw,bh,st,sl,bt,bl,stbw,stbh);
  // }, 50);

function stopslideshow(d) {
   var dir=parseInt(d,10);
   clearTimeout(slideshowtimer);
   slideshow=false;
   var e=(dir>0) ? "fwd" : "back"
   document.getElementById("slide"+e).className="control";
   document.getElementById("slidefwd").title=sst_fwd;
   document.getElementById("slideback").title=sst_back;
}

function makeslideshowcontrols() {
   //var classback=(slideshow && slidedir<0) ? "slidecontrolon" : "control"
   //var classfwd=(slideshow && slidedir>0) ? "slidecontrolon" : "control"
   document.write('<p id="slideshowcontrols"><a class="control" id="slideback" href="#" title="'+sst_back+'" onclick="toggleslideshow(-1)">&lt;&lt;</a> auto <a class="control" id="slidefwd"  href="#" title="'+sst_fwd+'" onclick="toggleslideshow(1)">&gt;&gt;</a></p>');
}

function showbigphoto(thumb) {
   showspinner(true);
   currentimage=parseInt(thumb.id.replace("thumb",""),10);
   var src=thumb.src.replace("thumbs/","");
   if (currentthumb) {
      currentthumb.className="thumb";
   }
   thumb.className+=" current";
   document.getElementById("bigphoto").style.display="block";
   document.getElementById("bigphoto").setAttribute("src","");
   document.getElementById("bigphoto").setAttribute("src",src);
   currentthumb=thumb;
   setcontrolclasses();
   if (self.searchpage) {
      if (searchpage) {
         showsscontrols();
         changexofy();
         showxofy();
         showcontrols();
      }
   }
}

// wrap set in php
function nextimage() {
   currentimage++;
   if (currentimage>noimages-1) currentimage=(wrap) ? 0 : currentimage-1;
   var thumb=document.getElementById("thumb"+currentimage);
   showbigphoto(thumb);
   return false;
}

function previousimage() {
   currentimage--;
   if (currentimage<0) currentimage=(wrap) ? noimages-1 : 0;
   var thumb=document.getElementById("thumb"+currentimage);
   showbigphoto(thumb);
   return false;
}

function firstimage() {
   var thumb=document.getElementById("thumb0");
   showbigphoto(thumb);
   return false;
}

function lastimage() {
   var thumb=document.getElementById("thumb"+(noimages-1));
   showbigphoto(thumb);
   return false;
}

function setcontrolclasses() {
   var cf=document.getElementById("control_first");
   var cp=document.getElementById("control_previous");
   var cn=document.getElementById("control_next");
   var cl=document.getElementById("control_last");
   var cca="control";
   var ccia="control inactive";
   if (currentimage==0) {
      cf.className=ccia;
      cp.className=ccia;
      cn.className=cca;
      cl.className=cca;
   } else if (currentimage>0 && currentimage<noimages-1) {
      cf.className=cca;
      cp.className=cca;
      cn.className=cca;
      cl.className=cca;
   } else {
      cf.className=cca;
      cp.className=cca;
      cn.className=ccia;
      cl.className=ccia;
   }
}

function addeventhandlers() {
// use onclick 'cos need it to work in IE and IE doesn't support the W3C addEventlistener like every other browser does  
   document.getElementById("control_first").onclick=firstimage;
   document.getElementById("control_previous").onclick=previousimage;
   document.getElementById("control_next").onclick=nextimage;
   document.getElementById("control_last").onclick=lastimage;
}

function dostuff() {
   scrolltothumb(); // call it all the time if there's no thumbdiv it just doesn't do anything. yes it's called twice opera doesn't take notice of the first one but the first one makes things nicer in other browsers.
   addeventhandlers();
  // if (self.slideshow) { // if exists
  //    if (slideshow) startslideshow(slidedir);
 //  }
   if (self.searchpage) {
      if (searchpage) initsearchstuff()
   }
}
