slideshow = {
	current:0,
	init:function(){
		if(document.getElementById && document.createTextNode){
			var list = document.getElementById(slideshow.css.showID);
			if(list){
				slideshow.items = list.getElementsByTagName('li');
				slideshow.all = slideshow.items.length;
				if(slideshow.all > 1){
					tools.addClass(list, slideshow.css.dynamicClass);
					slideshow.createNav(list);
				}
			}
			slideshow.show();
		}
	},
	createNav:function(o){
		var p = document.createElement('p');
		tools.addClass(p, slideshow.css.slideNavigationClass);
		if (slideshow.all>0) {
			var tempImg = new Image();
			tempImg.src = "/img/smallprevslide.png";
			slideshow.prev = document.createElement('a');
			slideshow.prev.setAttribute('href', 'javascript:void(null)');	
			slideshow.prev.appendChild(tempImg);
			tools.addEvent(slideshow.prev, 'click', slideshow.show);		
			p.appendChild(slideshow.prev);
			/*
			for (i=0; i<slideshow.all; i++) {
				var l = document.createElement('a');
				l.setAttribute('href', 'javascript:slideshow.showImageByNr('+i+')');
				l.setAttribute('id', 'link_'+i)
				var templabel = document.createTextNode(' '+(i+1)+' ');
				l.appendChild(templabel);
				p.appendChild(l);
				if (i<slideshow.all-1) {
					p.appendChild(document.createTextNode('|'));
				}
			}
			*/
			var l = document.createElement('a');
			l.setAttribute('href', 'javascript:void(null)');
			l.setAttribute('id', 'link_nr')
			var templabel = document.createTextNode(' 1 ');
			l.appendChild(templabel);
			p.appendChild(l);
			p.appendChild(document.createTextNode('/'));
			var l = document.createElement('a');
			l.setAttribute('href', 'javascript:void(null)');
			l.setAttribute('id', 'link_all')
			var templabel = document.createTextNode(' ' + slideshow.all + ' ');
			l.appendChild(templabel);
			p.appendChild(l);
			
			var tempImg = new Image();
			tempImg.src = "/img/smallnextslide.png";	
			slideshow.next = document.createElement('a');
			slideshow.next.setAttribute('href', 'javascript:void(null)');		
			slideshow.next.appendChild(tempImg);
			tools.addEvent(slideshow.next, 'click', slideshow.show);		
			p.appendChild(slideshow.next);	
		}
		o.parentNode.insertBefore(p, o);
	},
	show:function(e){
	  var slideshowOld = null;
		if(this === slideshow.next || this === slideshow.prev){
			tools.removeClass(slideshow.items[slideshow.current], slideshow.css.currentClass);
			var addto = this === slideshow.next ? 1 : -1;
			slideshowOld = slideshow.current;
			slideshow.current = slideshow.current + addto;
			if(slideshow.current < 0){
				slideshow.current = (slideshow.all-1);
			}
			if(slideshow.current > slideshow.all-1){
				slideshow.current = 0;
			}
			
		}
		if (slideshowOld != null) {
		  slideshow.showImage(slideshowOld, slideshow.current);
		}
		tools.cancelClick(e);
	},
  changeImage:function(){
    tools.removeClass(slideshow.items[slideshow.current], slideshow.css.currentClass);
    var addto = 1;
    slideshowOld = slideshow.current;
    slideshow.current = slideshow.current + addto;
    if(slideshow.current > slideshow.all-1){
      slideshow.current = 0;
    }
    slideshow.showImage(slideshowOld, slideshow.current);
  },
  showImage: function(old, curr){
	  if (slideshow.items[old] && slideshow.items[curr]) {
		$("#"+slideshow.items[old].id).fadeOut("fast");
	    $("#"+slideshow.items[curr].id).hide();
		$("#"+slideshow.items[curr].id).fadeIn("slow");
		$("#link_nr").text(' ' + (curr + 1) + ' ');
	  }        
  },	
  showImageByNr: function(nr) {
	clearInterval(timer);
	tools.removeClass(slideshow.items[slideshow.current], slideshow.css.currentClass);
    slideshowOld = slideshow.current;
    slideshow.current = nr;
    slideshow.showImage(slideshowOld, slideshow.current);	
    timer = setInterval(slideshow.changeImage, (seconds_between_photos * 1000));
  }
}

function checkForLoaded () {
	if (document.getElementById(slideshow.css.showID) != null && slideshow.items != null) {
		clearInterval(timer);
		slideshow.current = slideshow.all-1;
		slideshow.changeImage();
		timer = setInterval(slideshow.changeImage, (seconds_between_photos * 1000));
	}
}

seconds_between_photos = 5;

// check every second to see if DIV exists, when it does, start photo changing timer
timer = setInterval(checkForLoaded, 500); 

//tools.addEvent(window,'load',slideshow.init);