var ddSlideshow = {
	options: {
		itemContainer: '#slideshow-items',
		imageContainer: '#slideshow-image',
		loadingCss: 'loading',
		auto_play: false,
		speed: 5000
	},
	imageWrapper: null,
	gallery: null,
	count: 0,
	_interval: null,
	Setup: function(itemContainer, options) {
		ddSlideshow.options.itemContainer = itemContainer ? itemContainer : ddSlideshow.options.itemContainer;
		ddSlideshow.options = $.extend(ddSlideshow.options, options);
		ddSlideshow.imageWrapper = $(ddSlideshow.options.imageContainer).addClass(ddSlideshow.options.loadingCss);
		
		var items = new Array();
		gallery = document.createElement("div");
		gallery = $(gallery).addClass('gallery-inner').hide().appendTo(ddSlideshow.imageWrapper);
		
		var imageLinks = $(ddSlideshow.options.itemContainer).hide().find('a');
		var count = 0;
		imageLinks.each(function() {																			
			  var img = new Image();
			  $(img).appendTo(gallery).load(function() {													 
					count++;					
					if (count >= imageLinks.length) {
						ddSlideshow.Run();
					} else {
						ddSlideshow.Show();	
					}
				  })
			  	.error(function() {

					//same as success load, just remove img from DOM
					$(this).remove();
					count++;
					if (count >= imageLinks.length) {
						ddSlideshow.Run();
					}
				  })
				.attr('src', $(this).attr('href'));
	    });
	},
	Show: function() {
		ddSlideshow.imageWrapper.removeClass(ddSlideshow.options.loadingCss);
		gallery.show();
	},
	Run: function() {
		ddSlideshow.imageWrapper.removeClass(ddSlideshow.options.loadingCss);
		gallery.show();
		gallery.cycle({fx:'fade'});		
	},
	Pause: function() {
		window.clearInterval(ddSlideshow._interval);
		ddSlideshow._advanceIndex();
	}, 
	Stop: function() {
		ddSlideshow.Pause();
		ddSlideshow.index = 0;
	}
};
