var module = module || {};
(function() {

	var Slide = new function() {
		var _amount = 0,
			_path = 'img/slideshow/main/',
			_dom,
			_speed = 6000,
			_interval,
			_index = 1,
			_lastRand;
		
		var rand = function() {
			var result = Math.floor(Math.random()*(_amount));
			
			while(result == _lastRand) {
				result = Math.floor(Math.random()*(_amount));
			}
			
			_lastRand = result;
			return result;
		};
		
		this.init = function(id, amount, speed) {
			if(typeof amount !== 'number') {
				throw new Error('No valid number.');
			}
			
			_dom = $('#'+id);
			_amount = amount;
			
			if(!!speed && typeof speed === 'number') {
				_speed = speed;
			}
			
			_dom.append('<img class="last" src="'+_path+'ss_main'+rand()+'.jpg">');
			
			_interval = window.setInterval(function() {
				_dom.find('.last').removeClass('last').addClass('remove');
				_dom.append('<img class="last" src="'+_path+'ss_main'+rand()+'.jpg">');
				_dom.find('.last').css({ position : 'absolute', 'z-index' : ++_index , top : '0px', left : '0px', display : 'none' }).fadeIn(1000, function() {
					_dom.find('.remove').remove();
				});
			}, _speed);
		};
	};
	
	module.Slide = Slide;
})();
