var Mylan = window.Mylan || {};

Mylan.SlideShow = (function(){
	
	///
	/// Private Constants
	CROSS_FADE_DURATION = "slow";
	DELAY_BEFORE_CROSS_FADE = 8000; // Milliseconds

	///
	/// Private Variables
	_container = null;
	_slideshowTimerId = 0;
	
	///
	/// Private Methods
	function showNextImage() {
		
		var currentImage = _container.children().first().remove();
		_container.append(currentImage);
		_container.children().first().css("display", "block");
		
		currentImage.fadeOut(CROSS_FADE_DURATION, queueNextImageDisplay);
	}
	
	function queueNextImageDisplay() {
		_slideshowTimerId = setTimeout(showNextImage, DELAY_BEFORE_CROSS_FADE);
	}
	
	///
	/// Public Interface
	return {
		init: function(container) {
			_container = container;
			
			_container.css({
				margin: "0 auto",
				width: "1300px",
				overflow: "hidden"
			});
		
			// Setup Image CSS Properties
			jQuery.each(_container.children(), function(index, item) {
				jQuery(item).css({
					position: "absolute",
					display: "none"
				});
			});			
	
			_container.children().first().css("display", "block");
			queueNextImageDisplay();
		},
		pause: function() {
			clearTimeout(_slideshowTimerId);
		},
		resume: function() {
			queueNextImageDisplay();
		}
	};
})();
