function initGallery(){
	var _holder = $('.gallery ul');
	
	_holder.each(function(){
		var _els = $(this).find('li');
		var __hovered = false;
		var _fadeDur = 500; // animation speed
		var _autoSlide = 7000; // autoslide each 7 seconds
		
		var _currEl = _els.index(_els.filter('.active').eq(0));
		var _nextEl = _currEl;
		_els.filter('.active').removeClass('active').css('z-index',2)
		
		_els.each(function(){
			$(this).css('left',0);
		});
		
		function autoRotate(){
			_currEl = _nextEl;
			if(_nextEl<_els.length-1) _nextEl++
			else _nextEl = 0;
			
			_els.eq(_currEl).css('z-index',3);
			_els.eq(_nextEl).css('z-index',2);
			
			_els.eq(_currEl).animate({
				'opacity':0
			},_fadeDur,function(){
				_els.eq(_currEl).css({
					'z-index':1,
					'opacity':1
				});
			});
		}
		
		$(this).hover(function(){
			__hovered = true;
		},function(){
			__hovered = false;
		});
		
		setInterval(function(){
			if(!__hovered) autoRotate();
		},_autoSlide);
	});
}
function initVertical(){
	$('.pictures-gallery').each(function(){
		var _ulHeight = 372;
		var _liHeight = 93;
		var _li = $(this).find('li');
		var _padding = (_ulHeight - _li.length*_liHeight)/2;
		$(this).css('paddingTop',_padding);
	});
}

if (window.addEventListener){
	window.addEventListener("load", initGallery, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", initGallery);
}

$(function(){
	initVertical();
});