function fadeGall(){
	var _stopFlag = false; // the auto slide will work if _stopFlag = false;
	var wait_time = 5000; // in ms time between transitions 
	var change_speed = 1200; // in ms
	var _hold = $('div.gallery-hold');
	if(_hold.length){
		var _t;
		var _f = true;
		var _list = _hold.find('ul.gallery-list > li');
		var _wrap = _hold.find('ul.gallery-list');
		var _btn = $('<ul class="paging"></ul>');
		var _prev = _hold.find('a.prev');
		var _next = _hold.find('a.next');
		_list.each(function(_i){
			_btn.append('<li><a href="#">'+(_i+1)+'</a></li>');
		});
		_btn = $('ul.controls').find('a');
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		
		if($.browser.msie) _list.removeClass('active').hide().eq(_a).addClass('active').show();
		else _list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1);
		
		var _H = _list.eq(_a).outerHeight(true);
		var _W = _list.eq(_a).outerWidth(true);
		if ($.browser.msie && $.browser.version < 8) {
			_H = _H + 33
		}
		_wrap.css({
			height : _H,
			width : _W
		});
		
		_btn.eq(_a).parent('li').addClass('active');
		_btn.click(function(){
			changeEl(_btn.index(this));
			return false;
		});
		if(!_stopFlag){
			_hold.mouseenter(function(){
				_f = false;
				if(_t) clearTimeout(_t);
			}).mouseleave(function(){
				_f = true;
				if(_t) clearTimeout(_t);
				if(_f && wait_time){
					_t = setTimeout(function(){
						if(_a < _list.length - 1) changeEl(_a + 1);
						else changeEl(0);
					}, wait_time);
				}
			});
			_btn.mouseenter(function(){
				_f = false;
				if(_t) clearTimeout(_t);
			}).mouseleave(function(){
				_f = true;
				if(_t) clearTimeout(_t);
				if(_f && wait_time){
					_t = setTimeout(function(){
						if(_a < _list.length - 1) changeEl(_a + 1);
						else changeEl(0);
					}, wait_time);
				}
			});
		}
		_prev.click(function(){
			if(_a <= 0) changeEl(_list.length-1);
			else changeEl(_a-1);
			return false;
		});
		_next.click(function(){
			if(_a < _list.length - 1) changeEl(_a + 1);
			else changeEl(0);
			return false;
		});
		
		
		if(!_stopFlag){
			if(_f && wait_time){
				_t = setTimeout(function(){
					if(_a < _list.length - 1) changeEl(_a + 1);
					else changeEl(0);
				}, wait_time);
			}
		}
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			if(_ind != _a){
				if($.browser.msie){
					_list.eq(_a).removeClass('active').hide();
					_list.eq(_ind).addClass('active').show();
					_H = _list.eq(_ind).outerHeight(true);
					_W = _list.eq(_ind).outerWidth(true);
					if ($.browser.msie && $.browser.version < 8) {
						_H = _H + 33
					}
					_wrap.css({
						height : _H,
						width : _W
					});
				}
				else{
					_list.eq(_a).removeClass('active').animate({opacity: 0}, {queue:false, duration:change_speed});
					_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:change_speed});
					_H = _list.eq(_ind).outerHeight();
					_W = _list.eq(_ind).outerWidth();
					_wrap.animate({height: _H, width : _W}, {queue:false, duration:change_speed/2});
				}
				
				_btn.eq(_a).parent('li').removeClass('active');
				_btn.eq(_ind).parent('li').addClass('active');
				_a = _ind;
			}
			if(!_stopFlag){
				if(_f && wait_time){
					_t = setTimeout(function(){
						if(_a < _list.length - 1) changeEl(_a + 1);
						else changeEl(0);
					}, wait_time);
				}
			}
		}
	}
}
	
$(document).ready(function(){
	fadeGall();
});


