	 var apid = 0;
	 var nowPage = 1;
	 var perPage = 4;
	 var currentBG = 0;
	 image_photo = new Image;	 
	 var numPhotos = 0
	 var maxPage = 0;
	 var preloadphoto_timeout = 0;
	 
	 var nowPage_All = 1;
	 var perPage_All = 16;
	 var currentBG_All = 0;
	 var maxPage_All = 0;	 
	
	function album_init(){
	
		$('album_photo_list').setOpacity(0);
	
		numPhotos = tnArray.length
	    maxPage = Math.round((numPhotos+1)/perPage)-1;
	    currentBG = 0;
	    preloadphoto_timeout = 0;
	    $('photo_description').setOpacity(0);
	    $('album_arrow_next').setOpacity(0);
	    $('album_arrow_prev').setOpacity(0);
	    
		currentBG_All = 0;
		maxPage_All = Math.ceil((numPhotos+1)/perPage_All)-1;	
		    

	    
	    createTN('start');
	} 
	 
	function createTN(page){
		//alert(fromNum +" - "+ toNum)

			if (page=='prev') {
				nowPage--;
				if (nowPage<1) {
					nowPage=0;
				}
			} else if (page=='next') {
				nowPage++;
				if (nowPage>maxPage) {
					nowPage=maxPage;
				}
			} else if(IsNumeric(page)){
				nowPageTmp = Math.floor((page)/perPage);
				if (nowPageTmp!=nowPage){
					nowPage = nowPageTmp;
				}
			}
			
			else {
				nowPage=0;
				album_show_photo (0);
			}
			if (maxPage==nowPage) {
				document.getElementById('sroll_right_sm').style.visibility = 'hidden'; 
			} else {
				document.getElementById('sroll_right_sm').style.visibility = 'visible'; 
			}
			
			if (nowPage==0) {
				document.getElementById('sroll_left_sm').style.visibility = 'hidden'; 
			} else {
				document.getElementById('sroll_left_sm').style.visibility = 'visible'; 
				
			}	
			
			if (nowPage==0) {
			p_start = nowPage*perPage;
			} else {
			p_start = nowPage*perPage;
			}
			if (nowPage>0) {
			p_end = p_start + (perPage);
			} else {
			p_end = p_start + (perPage);
		}

			num_photo=0;
			for (i=p_start; i<p_end; i++) {
					if (tnArray[i]) {
					document.getElementById('album_photo_'+num_photo).src = tnArray[i][0] + tnArray[i][2]; 
					document.getElementById('album_photo_'+num_photo).photo = i; 
					} else {
					document.getElementById('album_photo_'+num_photo).src = 'images/spacer.gif'; 
					document.getElementById('album_photo_'+num_photo).photo = 'none'; 
					}
					num_photo++;
				}
	}
	
	function album_show_photo (p_id) {
		if (p_id!='none') {
		    createTN(p_id)
		    $('photo_description').setOpacity(0);

			document.getElementById('show_album_num_photo').innerHTML = p_id + 1;
			document.getElementById('show_album_sum_photo').innerHTML = numPhotos;
			
			document.getElementById('bg_foto_album').style.background = 'url(images/ajax-loader1.gif) no-repeat center';

				image_photo = new Image;
				image_photo.src = tnArray[p_id][0]+tnArray[p_id][1];
				
				album_set_photo(p_id); //Вызов функции Показа большой фотографии с подгрузкой
				closeButton = "<div align=right class=\"photo_description_close\" onclick=\"div_hide_fade('photo_description')\"><img src='images/icon_close.gif' border=0></div>"
				$('album_photo_left_navigation').setOpacity(1);
				$('album_photo_right_navigation').setOpacity(1);
				document.getElementById('sroll_right_sm_all').style.visibility = 'hidden'; 
				document.getElementById('sroll_left_sm_all').style.visibility = 'hidden';
				document.getElementById('album_photo_list').style.display = "none";
				 
				descriptionPhoto = tnArray[p_id][3]
				if (descriptionPhoto!=""){
					document.getElementById('photo_description').innerHTML = descriptionPhoto + closeButton
					new Fx.Style('photo_description', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);
				}
			apid=tnArray[p_id][4];
			//alert('test'+tnArray[p_id][3]);	
			loadToDiv('comment.php?'+s+'do=view&apid='+tnArray[p_id][4],'album_tabs_info');
		}
	}
	
	function album_set_photo (p_id) {
		if (image_photo.complete) {
		//
			//big_photo_now=tnArray[p_id][1];
			//setTimeout("document.getElementById('bg_foto_album').style.background = 'url('+tnArray[p_id][0]+big_photo_now+') no-repeat center'",100);
			setTimeout("album_photo_set_background('"+tnArray[p_id][0]+tnArray[p_id][1]+"')",100);
			currentBG = p_id;
			clearTimeout (preloadphoto_timeout);
		} else {
			preloadphoto_timeout = setTimeout ( "album_set_photo("+p_id+");", 50 );
		}
	}
	
	function album_photo_set_background(img_p_t) {
		document.getElementById('bg_foto_album').style.background = 'url('+img_p_t+') no-repeat center';
	}
	
	function SetBG(color){
		document.getElementById('bg_foto_album').style.backgroundColor = color;
	}
	
	function album_photo_go(act){
		if(act=="next"){
			if(numPhotos>currentBG+1){
			currentBG++
			album_show_photo(currentBG);
			}else{
			    currentBG = 0;
				album_show_photo(0);
			}
		}else if(act=="prev"){
			if(0<currentBG){
			currentBG--
			album_show_photo(currentBG);
			}else{
			    currentBG = numPhotos-1;
				album_show_photo(currentBG);
			}
		}
		//createTN(currentBG);
	}
	
/*SHOW SMALL ALBUM GALLERY*/	
	 
	function createALL_TN(page){

			if (page=='prev') {
				nowPage_All--;
				if (nowPage_All<1) {
					nowPage_All=0;
				}
			} else if (page=='next') {
				nowPage_All++;
				if (nowPage_All>maxPage_All) {
					nowPage_All=maxPage_All;
				}
			} else if(IsNumeric(page)){
				nowPageTmp_All = Math.floor((page)/perPage_All);
				if (nowPageTmp_All!=nowPage_All){
					nowPage_All = nowPageTmp_All;
				}
			}
			
			else {
				nowPage_All=0;
			}
		
			if (maxPage_All==nowPage_All) {
				document.getElementById('sroll_right_sm_all').style.visibility = 'hidden'; 
			} else {
				document.getElementById('sroll_right_sm_all').style.visibility = 'visible'; 
			}
			
			if (nowPage_All==0) {
				document.getElementById('sroll_left_sm_all').style.visibility = 'hidden'; 
			} else {
				document.getElementById('sroll_left_sm_all').style.visibility = 'visible'; 
				
			}	

			if (nowPage_All==0) {
			p_start = nowPage_All*perPage_All;
			} else {
			p_start = nowPage_All*perPage_All;
			}
			if (nowPage_All>0) {
			p_end = p_start + (perPage_All);
			} else {
			p_end = p_start + (perPage_All);
		}

			num_photo=0;
			for (i=p_start; i<p_end; i++) {
					if (tnArray[i]) {
					document.getElementById('album_gallery_photo_'+num_photo).src = tnArray[i][0] + tnArray[i][2]; 
					document.getElementById('album_gallery_photo_'+num_photo).photo = i; 
					} else {
					document.getElementById('album_gallery_photo_'+num_photo).src = 'images/spacer.gif'; 
					document.getElementById('album_gallery_photo_'+num_photo).photo = 'none'; 
					}
					num_photo++;
				}
		document.getElementById('album_photo_list').style.display = "block";
		$('album_photo_left_navigation').setOpacity(0);
		$('album_photo_right_navigation').setOpacity(0);
		$('photo_description').setOpacity(0);
		//document.getElementById('bg_foto_album').style.background = "url(images/spacer.gif) no-repeat center";
		new Fx.Style('album_photo_list', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,1);
		
		
	}
