(function($){
	$.fn.wpgallery = function(num) {
		if (!num) var num = 2;
		$('.vert-gal-mid',this).height(168*num-3);
		var size = $('li', this).size()
		var position = 0;
		var $piclist = $('ul.vert-gal-pics', this);
		var piclistHeight = $('ul.vert-gal-pics', this).height();
		var shift = $('li', this).outerHeight();
		var movingTime = 500;
		var slideTime = 4000;
		
		$piclist.height(piclistHeight)
		
		var $next = $('.vert-gal-btm span', this)
		var $prev = $('.vert-gal-top span', this)
		
		
		function checkFirst(){
			if (position == 0){
				$prev.hide();
				return false
			} else {
				$prev.css({'display':'block'});
				return true
			}
		}
		function checkLast(){
			if (position == -size+num){
				$next.hide();
				return false
			} else {
				$next.css({'display':'block'});
				return true
			}
		}
		function checkBorders(){
			checkFirst()
			checkLast()
		}
		checkBorders()
		
		
		function forward(){
			$piclist.animate({
				top: (position-1)*shift + 'px'
			}, movingTime)
			position--;
			checkBorders()
		}
		function backward(){
			$piclist.animate({
				top: (position+1)*shift + 'px'
			}, movingTime)
			position++;
			checkBorders()
		}
		
		
		$next.click(function(){
			forward()
		})
		
		$prev.click(function(){
			backward()
		})
		
	};
	
	
	
	
	$.fn.wpgallery2 = function() {
		var $pic15 = this;
		var $tops = $('.top a', this);
		var $sides = $('.side a', this);
		var sidesSize = $sides.size();
		var topsSize = $tops.size();
		
		var $a;
		
		//$pic15.find('.large img.top').not('.large img.top:first').css({'top':-320});
		//$pic15.find('.large img.top:first').addClass('active');
		//$pic15.find('.large img.side').css({'left':-482});
		//$pic15.find('.top:first a').css({'top':-81}).addClass('disabled');
		
		$pic15.find('.large img.top:first').css({'top':0});
		$pic15.find('.large img.top:first').addClass('active');
		

		$pic15.find('.top:first a').css({'top':-90}).addClass('disabled');
		


		function changePic(){
			$pic15.find('.top a.disabled').animate(
				{'top':0},function(){
					$(this).removeClass('disabled')
				}
			);
			$pic15.find('.side a.disabled').animate(
				{'left':0},function(){
					$(this).removeClass('disabled')
				}
			);
			
			if ($a.parent('li').hasClass('top')) {
				$a.animate(
					{'top':-90}
				);
			} else {
				$a.animate(
					{'left':-121}
				);
			}
			$a.addClass('disabled');
			
			$('.large img.active.top').animate(
				{'top':-365}
			).removeClass('active');
			
			$('.large img.active.side').animate(
				{'left':-486}
			).removeClass('active');
			
			var index = $a.attr('rel');
			
			var $big = $pic15.find('.large img.top').eq(index);
			if ($a.parent('li').hasClass('top')) {
				$pic15.find('.large img.top').eq(index).animate({
					'top': 0
				},function(){
					$pic15.find('.large img.top').eq(index).addClass('active');
				});
			}
			if ($a.parent('li').hasClass('side')) {
				$pic15.find('.large img.side').eq(index).animate({
					'left': 0
				},function(){
					$pic15.find('.large img.side').eq(index).addClass('active');
				});
			}
			$(".large").css({'background':'none'});
			
		
		}
		
		
		
		$tops.live('click',function(e){
			$a = $(this);
			e.preventDefault();
			changePic();
		})
		
		$sides.live('click',function(e){
			$a = $(this);
			e.preventDefault();
			changePic();
		})
		
	};
})(jQuery);
