slideshow = {
	current:0,
	init:function(){
			var list = $('#' + slideshow.css.showID);
			if(list.length > 0){
				slideshow.items = $('#' + slideshow.css.showID + ' li');
				slideshow.all = slideshow.items.length;
				if(slideshow.all > 1){
					list.addClass(slideshow.css.dynamicClass);
					slideshow.createNav(list);
				}
			}
			slideshow.show();	
	},
	createNav:function(o){
		//var p = document.createElement('p');
		var p = $(o).parent().before('<p/>').addClass(slideshow.css.slideNavigationClass);

		if (slideshow.all > 1) {
			$('#hotelFotosNav').show();
			slideshow.prev = $('#hotelFotos_prev');
			slideshow.next = $('#hotelFotos_next');
			$('#hotelFotos_prev').click(function() { 
				  var slideshowOld = null;
						$(slideshow.items[slideshow.current]).removeClass(slideshow.css.currentClass);
						var addto = -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);
		        return false;
		    });
			$('#hotelFotos_next').click(function() { 
				  var slideshowOld = null;
				  		$(slideshow.items[slideshow.current]).removeClass(slideshow.css.currentClass);
						var addto = 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);
		        return false;
		    });			
		}
	},
	show:function(e){
	  var slideshowOld = null;
		if(this === slideshow.next || this === slideshow.prev){
			$(slideshow.items[slideshow.current]).removeClass(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(){
	$(slideshow.items[slideshow.current]).removeClass(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);
	$(slideshow.items[slideshow.current]).removeClass(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 ($('#'+slideshow.css.showID) != null && slideshow.items != null) {
		clearInterval(timer);
		slideshow.current = slideshow.all-1;
		slideshow.changeImage();
		if (slideshow.all > 1) {
			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);