$(document).ready(function(){
	InitGalary();
});
function InitGalary(){
	var _speed = 1200, _duration = 5000;	
	var _hold = $("div.block-gallery");
	var _list=_hold.find("ul.gallery > li");
	var _a = 0,_old=_a;
	var _t, _t1;
	
	if(jQuery.browser.msie && jQuery.browser.version < 7){	
		_list.eq(_a).show();
	}else{
		_list.css({opacity:0}).eq(_a).show().css({opacity:1});
	}
	var _thumb = $(".switcher li");
	_thumb.eq(_a).addClass("active");
	_thumb.each(function(_i){
		$(this).click(function(){
			ChangeFade(_i);
			return false;
		});
	});

	
	Run(_a);
	function Run(_a){	
		_t = setTimeout(function(){
			_a++; if (_a == _list.length){_a=0}
			ChangeFade(_a);
		}, _duration);
	};
	function ChangeFade(_new){
		if(jQuery.browser.msie && jQuery.browser.version < 7){	
			_list.eq(_old).hide();
			_list.eq(_new).show();
		}else{
			_list.eq(_old).animate({opacity:0}, {queue:false, duration:_speed, complete:function(){$(this).hide();}});
			_list.eq(_new).show().animate({opacity:1}, {queue:false, duration:_speed});
		}
		_thumb.eq(_old).removeClass("active");
		_thumb.eq(_new).addClass("active");
		_old=_new;_a=_new;
		if(_t) clearTimeout(_t);
		if(_t1) clearTimeout(_t1);
		Run(_new);
	};
};

