//var slides= new Array('slide1', 'slide2'); 
var number_of_slides = 10;
var previous_i = number_of_slides - 1;
var i = 0; // The index of the slide currently shown

var wait = 7000; // Wait 7 seconds before next picture is shown
var slideshow_id = 0; // The setInterval id, to be able to stop and restart it
var duration = 3; // The duraction in seconds the effects should take
var hide_translucency = 0; // The translucency when hidden
var show_translucency = 1; // The translucency when shown

// Fades out the current slide and fades in the next slide.
function slideshow() {
	fade();
        previous_i = i;
	i = Math.floor(Math.random() * number_of_slides);
        if (i == previous_i) { i++; }
        if (i >= number_of_slides) { i = 0; }
	appear();
}

// Fades out the current slide and fades in the next slide, but also restarts the slideshow.
function next_picture() {
	slideshow();
	restart_slideshow();
}

// Fades out the current slide and fades in the previous slide, and restarts the slideshow.
function previous_picture() {
	fade();
	i = previous_i;
        if (i < 0) { i = number_of_slides - 1; }
	appear();
	restart_slideshow();
}

function fade() {
	Effect.Fade('slide' + (i + 1), { duration:duration, from:show_translucency, to:hide_translucency }); 
}

function appear() {
	Effect.Appear('slide' + (i + 1), { duration:duration, from:hide_translucency, to:show_translucency });
}

function start_slideshow() { 
	slideshow_id = setInterval('slideshow()',wait); 
}

function stop_slideshow() { 
	clearInterval(slideshow_id); 
}

function restart_slideshow() {
	stop_slideshow();
	start_slideshow();
}

function set_active_li(li) {
  var ul = $('sub_menu');
			
  var children = ul.childElements();
		
  for (var i = 0; i < children.length; i++) {
    children[i].removeClassName('active');
  }
		
  li.addClassName('active');
}

