function fadeGallery(){
	var _swichTime = 7000;
	var _d = $.browser.msie ? 0 : 1000;
	$('.s-holder').each(function(){
		var _this = $(this);
		var _list = $('.s-items > li', _this);
		var _linksHold = $('.s-nav', _this);
		var _htmlNav ='<ul>';
		for(var i=0; i<_list.length; i++) {
			_htmlNav += '<li><a href="#">'+i+'</a></li>';
		}
		_htmlNav +='</ul>';
		_linksHold.html(_htmlNav);
		var _links = $('li', _linksHold);
		var _btnPrev = $('.back a',_this);
		var _btnNext = $('.next a', _this);
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_swichTime) _swichTime +=_d;
		if(_a == -1) _a = 0;
		_list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1).css('opacity', 'auto');
		_links.eq(_a).addClass('active');
		var _t;
		if (_swichTime){
			_t = setTimeout(function(){
				if(_a < _list.length - 1) changeEl(_a + 1);
				else changeEl(0);
			}, _swichTime);
		}
		if (_btnPrev){
			_btnPrev.click(function(){
				var _prevItem = 0;
				if (_a > 0) _prevItem = _a-1;
				else _prevItem = _list.length-1;
				changeEl(_prevItem);
				return false;
			})
		}
		if(_links){
			_links.click(function(){
				var _ind = _links.index(this);
				changeEl(_ind);
				return false;
			})
		}
		if (_btnNext){
			_btnNext.click(function(){
				var _nextItem = 0;
				if (_a < _list.length - 1) _nextItem = _a+1;
				else _nextItem = 0;
				changeEl(_nextItem);
				return false;
			})
		}
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			if(_ind != _a){
				_links.each(function(i){
					$(this).removeClass('active');
					if(i==_ind) {$(this).addClass('active');}
				});
				_list.eq(_a).removeClass('active').css({display:'block'}).animate({opacity: 0}, {queue:false, duration:_d});
				_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:_d,complete:function(){
					$(this).css('opacity', 'auto');
				}});
				_a = _ind;
			}
			if (_swichTime){
				_t = setTimeout(function(){
					if(_a < _list.length - 1) changeEl(_a + 1);
					else changeEl(0);
				}, _swichTime);
			}
		}
	});
}

$(function(){
	fadeGallery();
})

function fadeGallery2(){
	var _swichTime = 7000;
	var _d = $.browser.msie ? 0 : 1000;
	$('.v-holder').each(function(){
		var _this = $(this);
		var _list = $('.v-items > li', _this);
		var _linksHold = $('.v-nav', _this);
		var _htmlNav ='<ul>';
		for(var i=0; i<_list.length; i++) {
			_htmlNav += '<li><a href="#">'+i+'</a></li>';
		}
		_htmlNav +='</ul>';
		_linksHold.html(_htmlNav);
		var _links = $('li', _linksHold);
		var _btnPrev = $('.back a',_this);
		var _btnNext = $('.next a', _this);
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_swichTime) _swichTime +=_d;
		if(_a == -1) _a = 0;
		_list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1).css('opacity', 'auto');
		_links.eq(_a).addClass('active');
		var _t;
		if (_swichTime){
			_t = setTimeout(function(){
				if(_a < _list.length - 1) changeEl(_a + 1);
				else changeEl(0);
			}, _swichTime);
		}
		if (_btnPrev){
			_btnPrev.click(function(){
				var _prevItem = 0;
				if (_a > 0) _prevItem = _a-1;
				else _prevItem = _list.length-1;
				changeEl(_prevItem);
				return false;
			})
		}
		if(_links){
			_links.click(function(){
				var _ind = _links.index(this);
				changeEl(_ind);
				return false;
			})
		}
		if (_btnNext){
			_btnNext.click(function(){
				var _nextItem = 0;
				if (_a < _list.length - 1) _nextItem = _a+1;
				else _nextItem = 0;
				changeEl(_nextItem);
				return false;
			})
		}
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			if(_ind != _a){
				_links.each(function(i){
					$(this).removeClass('active');
					if(i==_ind) {$(this).addClass('active');}
				});
				_list.eq(_a).removeClass('active').css({display:'block'}).animate({opacity: 0}, {queue:false, duration:_d});
				_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:_d,complete:function(){
					$(this).css('opacity', 'auto');
				}});
				_a = _ind;
			}
			if (_swichTime){
				_t = setTimeout(function(){
					if(_a < _list.length - 1) changeEl(_a + 1);
					else changeEl(0);
				}, _swichTime);
			}
		}
	});
}

$(function(){
	fadeGallery2();
})
