function toggleHidden() {
  for( var i=arguments.length-1; i >= 0; i -- ) {
    var el = arguments[i];
    var c = el.className;
    el.className = c.indexOf("hidden") >= 0 ? c.replace( /\s*hidden\s*/, "" ) : c + " hidden";
  }
  return false;
}

var Slideshow = {
  isRunning: false,
  current: 1,
  interval: 4, //seconds
  timeout: null,
  lastIndex: 0, // same as count of items

  setTimeout: function() {
    this.timeout && window.clearTimeout( this.timeout );
    var self = this;
    this.timeout = window.setTimeout( function() { self.forward(); }, this.interval * 1000 );
  },

  start: function( lastIndex ) {
    this.lastIndex = lastIndex;
    this.isRunning = true;
    this.show();
    var self = this;
    this.setTimeout();
    $("#SlideshowCtl a").hover( 
      function() { 
//        alert( this.className );
        $("#SlideshowCtl div." + this.className).show(); 
      },
      function() {
        $("#SlideshowCtl div").hide(); 
      }
    );
  },

  stop: function() {
    this.isRunning = false;
    this.timeout && window.clearTimeout( this.timeout );
    if( document.referrer.indexOf('http://'+document.location.host) >= 0 ) {
      document.location = document.referrer;
    } else {
      document.location = "/";
    }
  },

  pause: function() {
    var i = document.getElementById( "SlideshowPause" );
    if ( "c5" == i.className ) { // paused
      $("#SlideshowCtl div.c5").hide(); 
      $("#SlideshowCtl div.c3").show(); 
      i.className = "c3";
      this.isRunning = true;
      this.show();
      var self = this;
      this.setTimeout();
    } else {
      $("#SlideshowCtl div.c3").hide(); 
      $("#SlideshowCtl div.c5").show(); 
      i.className = "c5";
      this.isRunning = false;
      this.timeout && window.clearTimeout( this.timeout );
    }
  },

  forward: function() {
    this.hide();
    this.current = (this.current+1) % this.lastIndex;
    this.show();
    this.isRunning && this.setTimeout();
  },

  back: function() {
    this.hide();
    this.current = (this.lastIndex + this.current - 1) % this.lastIndex;
    this.show();
    this.isRunning && this.setTimeout();
  },

  show:  function() {
    var i = this.current + 1;
    /* -- IE bug -- */
    var bh = document.documentElement.clientHeight;
    ( bh < 600 ) && ( bh = 600 );
    /* -- end IE bug -- */
    $("#Slide"+i).css( {height: bh} ).fadeIn();
    this.updateInfo();
  },

  hide:  function() {
    var i = this.current + 1;
    $("#Slide"+i).fadeOut();
  },

  updateInfo: function() {
    var i = 1 + (this.lastIndex + this.current - 1) % this.lastIndex;
    $("#SlideshowCtl div.c2 b").html( $("#Slide"+i+" span.name").html() ); //prev slide name
    var i = 1 + (this.current+1) % this.lastIndex;
    $("#SlideshowCtl div.c4 b").html( $("#Slide"+i+" span.name").html() ); //next slide name
  }

} // Slideshow


$(document).ready( function() {
  $("#Menuleft").accordion( { collapsible: true, active: false, autoHeight: false } );

});


