/*--- slide gallery ---*/
function slideGall(){
	var _speed = 800; //in ms
	var _hold = $('#slider');
	if(_hold.length){
		var btn_up = _hold.find('a.up');
		var btn_down = _hold.find('a.down');
		var list_hold = _hold.find('ul.block');
		var _list = list_hold.children();
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		_list.removeClass('active').css('top',-9999).eq(_a).addClass('active').css('top', 0);
		btn_up.click(function(){
			changeEl(false);
			return false;
		});
		btn_down.click(function(){
			changeEl(true);
			return false;
		});
		var _f = true;
		var _ind;
		function changeEl(_flag){
			if(_f){
				_f = false;
				if(_flag){
					if(_a < _list.length - 1) _ind = _a + 1;
					else _ind = 0;
					list_hold.animate({height: _list.eq(_ind).outerHeight()}, _speed);
					_list.eq(_a).removeClass('active').animate({top: - _list.eq(_a).outerHeight()}, _speed);
					_list.eq(_ind).addClass('active').css('top', _list.eq(_a).outerHeight()).animate({top: 0}, _speed, function(){ 
						list_hold.height('auto');
						_list.eq(_a).css('top', -9999);
						_a = _ind;
						_f = true;
					});
				}
				else{
					if(_a > 0) _ind = _a - 1;
					else _ind = _list.length - 1;
					list_hold.animate({height: _list.eq(_ind).outerHeight()}, _speed);
					_list.eq(_a).removeClass('active').animate({top: _list.eq(_ind).outerHeight()}, _speed);
					_list.eq(_ind).addClass('active').css('top', -_list.eq(_ind).outerHeight()).animate({top: 0}, _speed, function(){ 
						list_hold.height('auto');
						_list.eq(_a).css('top', -9999);
						_a = _ind;
						_f = true;
					});
				}
			}
		}
	}
}
$(document).ready(function(){
	slideGall();
});