/* Feed.js
================================================*/
$(function(){
	$('.pic-preview').click(function(){
		var 
			a=$(this),
			li=a.closest('li'),
			container=$('#pic-view');
		if (!container.length){
			container=
				$('<div id="pic-view"></div>')
				.appendTo(document.body)
				.click(function(e){
					var 
						target=$(e.target),
						li=$.data(this,'_galleryTarget');
					if (target.is('.step')){
						var pli;
						if (target.hasClass('step-prev')){
							pli=li.prev('li:not(.more)');
							if (!pli.length){
								pli=li.siblings('li:not(.more):last')
								}
							}
						else{
							pli=li.next('li:not(.more)');
							if (!pli.length){
								pli=li.siblings('li:not(.more):first')
								}
							}
						if (pli.length){
							li=pli;
							a=li.find('.pic-preview').click();
							}
						return false;
						}
					container.hide();
					unblockScreen();
					return false;
					})
				.css({
					position:'absolute',
					zIndex:10001,
					cursor:'pointer',
					textAlign:'center'
					});			
			}
		blockScreen(function(){
			unblockScreen();
			container.hide();
			});
		container.empty().show();
		var caption=$('strong',$(this).parent()).html();
		$.status.progress('Загрузка изображения');
		getImgSize(this.href,function(img){
			$.status().hide();
			$.data(container[0],'_galleryTarget',li)
			container.html(''
				+img.html
				+(caption?'<strong style="width:'+(img.width+(BROWSER.isIE6?20:0))+'px">'+caption+'</strong>':'')
				+'<span class="step step-prev" title="Перейти к предыдущей картинке"></span><span class="step step-next" title="Перейти к следующей картинке"></span>'
				);
			putInScreenCenter(container[0],true);
			});
		return false;
		});
	
	
	$('.gallery').each(function(){
		var 
			gal=$(this),
			galCore=$('.gallery-list',gal),
			moreLink=$('.more',gal),
			itemsCount=galCore.find('li:not(.more)').size();
		if (itemsCount<=4){
			return;
			}
		var actualize=function(){
			moreLink.toggle(gal.hasClass('gallery-collapsed') && (galCore.height()-gal.height()>50));
			};
		$(window).resize(function(){
			actualize();
			})
		.load(function(){
			actualize();
			});		
			
		
		moreLink.find('a').click(function(){
			
			if (gal.hasClass('gallery-collapsed')){
				gal.removeClass('gallery-light').removeClass('gallery-collapsed').find('.adv').fadeIn();
				}		
			moreLink.hide();
			return false;
			});
		});
	});
	

