/* Gallery (fade-on-click, auto-fade) */
jQuery.fn.gallFade = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: 5000
	},_options);

	return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		var _timer = _options.autoSlide;
		var _wrap = _hold.find('ul.intro-image > li');
		
		_wrap.each(function(){
			jQuery(this).css({'left':'0'});
		});
		
		var _count = _wrap.index(_wrap.filter(':last'));
		var _t;
		var _active = _wrap.index(_wrap.filter('.active'));
		if (_active < 0) _active = 0;
		var _last = _active;
		_wrap.css({opacity:0}).eq(_active).css({opacity:1});
		_wrap.removeClass('active').eq(_active).addClass('active');
		function fadeEl(){
			_wrap.eq(_last).animate({
				opacity:0
			}, {queue:false, duration: _speed});
			_wrap.eq(_active).animate({
				opacity:1
			}, {queue:false, duration: _speed});
			_wrap.removeClass('active').eq(_active).addClass('active');
			_last = _active;
		}
		function runTimer(){
			_t = setInterval(function(){
				_active++;
				if (_active > (_count)) _active = 0;
				fadeEl();
			}, _timer);
		}
		runTimer();
	});
}

$(window).load(function(){
	$('div.gallery-fade').gallFade({
		duration: 1500,
		autoSlide: 6000
	});
});
