function initGallery(){
	
	var _duration = 6000;
	var _timer;
	var _active = 0;
	var _hold = $('.gallery .visual');
	var _list = $('.image-list li', _hold);
	var _btn = $('.number ul a', _hold).each(function(_ind, _el){
		if($(_el).hasClass('active')){ _active = _ind;}
		$(_el).click(function(){
			_active = _ind;
			_changeEl();
			return false;
		});
	});
	
	_list.css('opacity', '0');
	_list.eq(_active).css('opacity', '1');
	_list.eq(_active).css('z-index', '21');
	
	var btn_stop = $('.number .stop' , _hold).click(function(){
		if(_hold.hasClass('stoped')){
			_hold.removeClass('stoped');
			btn_stop.html('STOP');
			_timer = setTimeout(function(){  nextEl();}, _duration);
		}
		else{
			if (_timer) clearTimeout(_timer);
			_hold.addClass('stoped');
			btn_stop.html('PLAY');	
		}
	});
	
	_timer = setTimeout(function(){ nextEl();}, _duration);
	
	function  nextEl(){
		if(_active < _list.length -1 ){ _active++;}
		else{ _active = 0;}
		_changeEl();
	}
	
	function _changeEl(){
		if (_timer) clearTimeout(_timer);
		_btn.removeClass('active');
		_btn.eq(_active).addClass('active');
		_list.css('z-index','10').animate({opacity: 0}, { queue:false, duration: 1000 });
		_list.eq(_active).css('z-index', '20').animate({ opacity: 1}, { queue:false, duration: 1000 });
		if(!_hold.hasClass('stoped')){ _timer = setTimeout(function(){  nextEl();}, _duration);}
	}
	
}
if (window.addEventListener)
	window.addEventListener("load", initGallery, false);
else if (window.attachEvent)
	window.attachEvent("onload", initGallery);

