
	
	var maxAlbumsInCategory = 16;  // количество альбомов на категорию
	var albumScrollValue    = 4;   // прокрутка превью альбомов (альбомов)
	var requestNumber       = 0;
	
	positions = new Array();
	
	function getphoto(pid){
		$('#photomonitor img').hide();
		$('#photomonitor img').attr('src','/filestorage/photoalbum/photos/medium-'+pid);
		$('#photomonitor img').show();
		return false;
	};
	
$(document).ready(function(){
	for(iter = 0; iter < categories.length; iter++)
	{
		positions[categories[iter]] = 1;
		
		categoryId    = categories[iter];
		categoryCount = catcount[iter];
			
		if(categoryCount > maxAlbumsInCategory)
		{
			for(sub = maxAlbumsInCategory+1; sub<=categoryCount; sub++)$('#alblink_'+categoryId+'_'+sub).hide();
			$('#left_'+categoryId).show();
			$('#right_'+categoryId).show();
			
			/*
			$('#right_'+categories[iter]).click(function(){
				
				if(positions[categories[iter]]< (catcount[iter]-maxAlbumsInCategory))
				{
					scrollvalstart = positions[categories[iter]];
					scrollvalstop  = scrollvalstart + albumScrollValue;
				
					for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+categories[iter]+'_'+scrollval).hide();
					scrollvalstart = maxAlbumsInCategory + positions[categories[iter]];
					scrollvalstop  = scrollvalstart + albumScrollValue;
					positions[categories[iter-1]] = positions[categories[iter]] + albumScrollValue;
					for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+categories[iter]+'_'+scrollval).show();
				}	
			});
			
			$('#left_'+categories[iter]).click(function(){
				positions[categories[iter-1]] = positions[categories[iter-1]] - albumScrollValue;
				if(positions[categories[iter-1]]<1)positions[categories[iter-1]] = 1;
				scrollvalstart = positions[categories[iter-1]];
				scrollvalstop  = scrollvalstart + albumScrollValue;
				for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+categories[iter-1]+'_'+scrollval).show();
				scrollvalstart = maxAlbumsInCategory + positions[categories[iter-1]];
				scrollvalstop  = scrollvalstart + albumScrollValue;
				for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+categories[iter-1]+'_'+scrollval).hide();
			});	
			*/
			
			$('.goleft').click(function(){
				albid = this.alt;
				
				positions[albid] = positions[albid] - albumScrollValue;
				if(positions[albid]<1)positions[albid] = 1;
				scrollvalstart = positions[albid];
				scrollvalstop  = scrollvalstart + albumScrollValue;
				for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+albid+'_'+scrollval).show();
				scrollvalstart = maxAlbumsInCategory + positions[albid];
				scrollvalstop  = scrollvalstart + albumScrollValue;
				for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+albid+'_'+scrollval).hide();
				})
			
			$('.goright').click(function(){
				albid = this.alt;
				//alert(catcountbyid[albid])
				if(positions[albid]< (catcountbyid[albid]-maxAlbumsInCategory))
				{
					scrollvalstart = positions[albid];
					scrollvalstop  = scrollvalstart + albumScrollValue;
					//alert(positions[albid]+' '+scrollvalstart+' '+scrollvalstop);
					for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++)$('#alblink_'+albid+'_'+scrollval).hide();
					scrollvalstart = maxAlbumsInCategory + positions[albid];
					scrollvalstop  = scrollvalstart + albumScrollValue;
					positions[albid] = positions[albid] + albumScrollValue;
					for(scrollval = scrollvalstart; scrollval<scrollvalstop; scrollval++){$('#alblink_'+albid+'_'+scrollval).show();}
					}
				})
		}	
	}
	
	$('.photozoom').click(function(){
		$('#photomonitor img').hide();
		$('#photomonitor img').attr('src','/filestorage/photoalbum/photos/medium-'+this.rel);
		$('#photomonitor img').show();
		return false;
	});
	
	
	
	$('.albumpreview').click(function(){
		golink = false;
		JsHttpRequest.query('?mod=standart&command=getelement', {module: 'photoalbum', uid: this.rel},
			function(result, debugMessages)
			{
				if(result.loaded)
				{
					$('#albname').text(result.objectdata.name);
					$('#photomonitor img').hide();
					//$('.slide').hide();
					if(result.objectcover)
					{
						$('#photomonitor img').attr('src','/filestorage/photoalbum/photos/medium-'+result.objectcover.id+'.'+result.objectcover.image);
						$('#photomonitor img').show();
					}
					else if(result.objectdata.image!='')
					{
						$('#photomonitor img').attr('src','/filestorage/photoalbum/elements/medium-'+result.objectdata.id+'.'+result.objectdata.image);
						$('#photomonitor img').show();
					}
					
					if(result.photos>1)
					{
						$('.lenta tr').remove();
						longstr = '<tr>';
						for(i=0; i<result.photos; i++)
						{
							str = '';
							str += '<td';
							if(i==0)str+=' class="first"';
							str +='><div style="height: 90px;"><a class="photozoom" rel="'+result.album[i].id+'.'+result.album[i].image+'" href="" onclick="getphoto(\''+result.album[i].id+'.'+result.album[i].image+'\'); return false;">';
							str +='<img src="/filestorage/photoalbum/photos/small-'+result.album[i].id+'.'+result.album[i].image+'" alt="">';
							str += '</a></div></td>';
							longstr += str;
						}
						longstr += '</tr>';
						$('.lenta').append(longstr);
											
						document.getElementById('lenta').style.marginLeft=0+'px';
						reDrawScroll();
					}
					else 
					{
						$('.lenta tr').remove();
						$('img.back, img.forward').hide();
					}	
					golink = false;
				}
				else
				{
					golink = true;
				}
			});
		
		
		return golink;
	})
})


