function loop_photos(nr_of_photos, nr_of_loops) {
  
  if (loop_state == 1) {
    
	var hide_photo_id = 'photo_'+hide_photo_nr;
  
    if (hide_photo_nr == nr_of_photos) {
	  
      var show_photo_id = 'photo_1';
	  show_photo_nr = 1;
  
    } else {
  
      var show_photo_id = 'photo_'+(hide_photo_nr + 1);
	  show_photo_nr = hide_photo_nr + 1;
    }
   
	if (show_photo_nr == 1 && nr_of_loops > 0) {
      
	  loop_counter++;
	  
	  if (loop_counter == nr_of_loops) {
	    
		loop_state = 0;
	  }
	}
	
    var photo_to_hide = document.getElementById(hide_photo_id);
    var photo_to_show = document.getElementById(show_photo_id);
    
	setTimeout("do_fade('" + hide_photo_id + "', '" + show_photo_id + "' , '" + nr_of_photos + "', " + nr_of_loops + ")", loop_time);
  }
}

function show_other_photo(nr_of_photos, direction) {
  
  loop_state		= 0;
  var hide_photo_id	= 'photo_'+hide_photo_nr;
  
  if (direction == 'next') {
    
	var show_photo_id	= 'photo_'+(hide_photo_nr + 1);
	show_photo_nr		= hide_photo_nr + 1;
	
  } else if (direction == 'previous') {
    
	var show_photo_id	= 'photo_'+(hide_photo_nr - 1);
	show_photo_nr		= hide_photo_nr - 1;  
  }
  
  if (show_photo_nr > nr_of_photos) {
	  
    show_photo_id = 'photo_1';
	show_photo_nr = 1;
  
  } else if (show_photo_nr < 1) {
  
    show_photo_id = 'photo_'+nr_of_photos;
	show_photo_nr = nr_of_photos;
  }
  
  hide_photo_nr = show_photo_nr;
  
  var photo_to_hide = document.getElementById(hide_photo_id);
  var photo_to_show = document.getElementById(show_photo_id);
  
  fade('out', hide_photo_id, fade_time);
  fade('in', show_photo_id, fade_time);
  
  setTimeout("do_change_current_photo_nr(" + hide_photo_nr + ")", (fade_time / 2));
  setTimeout("do_hide_photo('" + hide_photo_id + "', '" + hide_photo_nr + "')", fade_time);
}

function do_fade(hide_photo_id, show_photo_id, nr_of_photos, nr_of_loops) {
  
  if (loop_state == 1) {
    
    hide_photo_nr = show_photo_nr;
	
    fade('out', hide_photo_id, fade_time);
    fade('in', show_photo_id, fade_time);
	
	setTimeout("do_change_current_photo_nr(" + hide_photo_nr + ")", (fade_time / 2));
	setTimeout("do_fade_loop('" + hide_photo_id + "', " + nr_of_photos + ", " + hide_photo_nr + ", " + nr_of_loops + ")", fade_time);
  }
}

function do_fade_loop(hide_photo_id, nr_of_photos, init_hide_photo_nr, nr_of_loops) {
    
  do_hide_photo(hide_photo_id, init_hide_photo_nr);
  
  if (loop_state == 1) {

	loop_photos(nr_of_photos, nr_of_loops);
  }
}

function do_hide_photo(hide_photo_id, init_hide_photo_nr) {
  
  if (init_hide_photo_nr == hide_photo_nr) {
    
	document.getElementById(hide_photo_id).className = class_name+' hidden';
  }
}

function do_change_current_photo_nr(init_hide_photo_nr) {
  
  if (init_hide_photo_nr == hide_photo_nr) {
	
	document.getElementById('current_photo_nr').innerHTML = hide_photo_nr;  
  }
}

function fade(direction, id, fade_time) {
  
  var element = document.getElementById(id);
  
  if (direction == 'out') {
    
	if (element.fade_state == null || element.fade_state == '') {
	  
	  element.style.opacity	= '1';
	  element.style.filter	= 'alpha(opacity = 100)';
      element.fade_state	= 2;	
	}
	  
  } else if (direction == 'in') {
    
	if (element.fade_state == null || element.fade_state == '') {
      
	  element.style.opacity	= '0';
	  element.style.filter	= 'alpha(opacity = 0)';
      element.fade_state	= -2;
	}

    element.className		= class_name;
  }
  
  if (element.fade_state == 1 || element.fade_state == -1) {
    
    element.fade_state		= element.fade_state * (-1);
    element.fade_time_left	= fade_time - element.fade_time_left;
  
  } else {

    element.fade_state		= element.fade_state / 2;
    element.fade_time_left	= fade_time;
   
    setTimeout("fade_animation('" + new Date().getTime() + "','" + id + "', " + fade_time + ")",33);
  }
}

function fade_animation(init_time, id, fade_time) {
  
  var time = new Date().getTime();
  var element = document.getElementById(id);
  
  if (element.fade_time_left <= (time - init_time)) {
    
    element.style.opacity = element.fade_state == -1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '+ (element.fade_state == -1 ? '100' : '0') +')';
    element.fade_state = element.fade_state == 1 ? -2 : 2;
    return;
  }
  
  element.fade_time_left = element.fade_time_left - (time - init_time);
  
  var new_opacity_value = element.fade_time_left / fade_time;
  
  if (element.fade_state == -1) {
    
    new_opacity_value = 1 - new_opacity_value;
  }
  
  element.style.opacity = new_opacity_value;
  element.style.filter = 'alpha(opacity = '+ (new_opacity_value * 100) +')';
  
  setTimeout("fade_animation('" + time + "', '" + id + "', " + fade_time + ")",33); 
}

function show_box(nr_of_boxes, hash_page) {
  
  var location_string	= String(window.location);
  var location_array	= location_string.split('#');
  
  for (i = 1; i <= nr_of_boxes; i++) {
    
	if (page_array[i] == hash_page) {
      
	  document.getElementById('box_'+i).className	= "text_box_content";
	  document.getElementById('link_'+i).className	= "submenu here";
	
	} else {
      
	  document.getElementById('box_'+i).className	= "text_box_content hidden";
	  document.getElementById('link_'+i).className	= "submenu";
	}
  }
  
  if (location_array[1] == null) {
  
    window.location = location_array[0]+hash_page;
  
  } else {
  
    var location_array = location_string.split('#');
   
    if (window.location != location_array[0]+hash_page) {
	
	  window.location = location_array[0]+hash_page;
	}
  }
}

function show_hash_page(nr_of_boxes, hash_page, default_page) {
	
  if (hash_page == null || hash_page == '') {
  
    hash_page = default_page;
  }
	  
  show_box(nr_of_boxes, hash_page);
}
