function ImageSlideshow(obj, podID, options){
	var nextIndex = 0;
	var timer = 0;
	var currentSlide = -1;
	var opacityChange;
	var durationSpeed = 600;
	var jsonObj = jQuery.parseJSON(obj);
	var slides = jsonObj.slides;
	var currentImageLoaded = 1;
	options["delay"] = options["delay"] ? options["delay"] * 1000 : 6000;
	
	function init(){
		// if show buttons is selected and there is more than one slide
		if(options["buttons"] == 1 && slides.length > 1){
			var buttons = document.createElement("div");
			buttons.className = "buttons";
			
			for(var i = 1; i <= slides.length; i++){
				var a = document.createElement("a");
				a.innerHTML = i;
				a.rel = i - 1;
				a.href = "javascript:void1();";
				a.id = "slideshow_" + podID + "_" + i;
				
				a.onclick = function(){
					clearTimeout(timer);
					//function 
					nextIndex = this.rel;
					next_slide();
				};
				
				buttons.appendChild(a);
			}
			$("#isWrapper" + podID).append(buttons);
		}
		
		if(slides.length > 1){
			preload_images();
		}
		next_slide();
	}
	
	function next_slide(){
		show_slide(nextIndex);
	}
	
	function show_slide(index){
		index = parseInt(index);
		
		if(currentSlide > -1){
			clearTimeout(timer);
			
			if($(slides[currentSlide].divID).innerHTML == ""){
				load_content_into_slidearea(currentSlide);
			}
			
			if(options["buttons"] == 1){
				$("#slideshow_" + podID + "_" + (currentSlide + 1)).removeClass();
			}
			
			if(options["buttons"] == 1){
				$("#slideshow_" + podID + "_" + (index + 1)).addClass("current");
			}
			
			// fade out the current slide
			$("#" + slides[currentSlide].divID).animate(
				{opacity: 0.0}, durationSpeed,
				function(){
					// hide the current slide
					$("#" + slides[currentSlide].divID).css("display","none");
					// if buttons are shown, change the class of the current button
					
					
					// fade in the next slide
					$("#" + slides[index].divID).css("display","block");
					
					$("#" + slides[index].divID).animate(
						{opacity: 1.0}, durationSpeed,
						function(){
							if(slides.length > 1){
								timer = setTimeout(next_slide, options["delay"]);
								
								
								nextIndex = (index + 1 < slides.length ? index + 1 : 0);
								currentSlide = index;
							}
						}
					);
				}
			);
		}else{	// if the first time, just fade in the new slides
			$("#" + slides[0].divID).css("display","block");
			
			if(options["buttons"] == 1){
				$("#slideshow_" + podID + "_1").addClass("current");
			}
			
			$("#" + slides[0].divID).animate(
				{opacity: 1.0},durationSpeed,
				function(){
					if(slides.length > 1){
						timer = setTimeout(next_slide, options["delay"]);
						
						
						nextIndex = (index + 1 < slides.length ? index + 1 : 0);
						
						currentSlide = index;
					}
				}
			);
		}
	}
	
	function load_content_into_slidearea(slideIndex){
		base_ajax(slides[slideIndex].divID, "/includes/modules/images/controllers/fn-slideshow.php", "mode=displaySlide&imageID=" + slides[slideIndex].id,"");
	}
	
	function preload_images(){
		var img = new Image();
		
		if(currentImageLoaded < slides.length){
			img.onload = function(){
				// once the image loades, load the content into the slide area
				load_content_into_slidearea(currentImageLoaded);
				// load the next image
				currentImageLoaded++;
				preload_images();
			}
			
			img.src = slides[currentImageLoaded].image;
		}
	}
	
	function randOrd(){
	return (Math.round(Math.random())-0.5); }
	
	// run the constructor
	init();
}

function void1(){}

