

function popOpen()
{
	popOpen2(4);
}
function popOpen2(idG)
{
	$('#pop_bg').show();
	$('#popup_wnd').fadeIn();
	galleryShow(idG);
}


function popClose()
{
	$('#popup_wnd').hide();
	$('#pop_bg').fadeOut();
	galleryPause();
}




var iGallery = -1;
var iPhoto = -1;
var gallerySlidePlay = false;
var timerSlide = 0;
var arrPhotoID = new Array();
var arrPhotoSrc = new Array();
var arrPhotoTitle = new Array();

function galleryShow(id)
{
	if(iGallery >= 0) {
		$('#gallery_menu_'+iGallery).removeClass('active');
	}
	
	iGallery = id;
	$('#gallery_menu_'+iGallery).addClass('active');

	
	$('#gallery_info').fadeOut('slow');
	$('#gallery_thumbs').fadeOut('slow');
	
	$.get('/gallery.php', { id: id }, function(data) {
		var c = data.split('#sep#');
		arrPhotoTitle = c[2].split(',');
		arrPhotoID    = c[1].split(',');
		arrPhotoSrc   = c[3].split(',');
		
		var thumbs = "";
		for(var i=0; i<arrPhotoID.length; i++) {
			arrPhotoTitle[i] = arrPhotoTitle[i].replace('^', ','); 
			thumbs += '<a href="#thumb" onfocus="blur()" id="thumb' + i + '" onclick="selectPhoto(' + i + ')"><img src="/files/gallery/min/'+arrPhotoID[i]+'.jpg" width="50" height="50"></a>';
		}

		$('#gallery_info').html(c[0]);
		$('#gallery_thumbs').html(thumbs);
		$('#gallery_info').fadeIn('slow', function() {
			$('#gallery_thumbs').fadeIn('slow');
		});
		
		iPhoto = 0;
		showPhoto();
		galleryPlay();
	});
}


function showPhoto()
{
	$(".thumb_active").removeClass('thumb_active');
	$("#thumb"+iPhoto).addClass('thumb_active');
	$('#gallery_img').fadeOut('slow', function() {
		$('#gallery_img').html('<img src="/files/gallery/'+arrPhotoSrc[iPhoto]+'">');
		$('#gallery_photo_title').html((iPhoto+1) + ". " + arrPhotoTitle[iPhoto]);
		$('#gallery_img').fadeIn();
	});
}

function selectPhoto(i)
{
	galleryPause();
	iPhoto = i;
	showPhoto();
}




function galleryPlay()
{
	$("#nav_play").removeClass("pause");
	gallerySlidePlay = true;
	clearTimeout(timerSlide);
	timerSlide = setTimeout('galleryNext();', 1000*5);
}

function galleryPause()
{
	$("#nav_play").addClass("pause");
	gallerySlidePlay = false;
	clearTimeout(timerSlide);
}


function galleryPlayPause()
{
	if(gallerySlidePlay) {
		galleryPause();
	}
	else {
		galleryPlay();
	}
}



function galleryPrev()
{
	iPhoto --;
	if(iPhoto < 0) {
		iPhoto = arrPhotoID.length - 1;
	}
	showPhoto();

	if(gallerySlidePlay) {
		clearTimeout(timerSlide);
		timerSlide = setTimeout('galleryNext();', 1000*5);
	}
}

function galleryNext()
{
	iPhoto ++;
	if(iPhoto >= arrPhotoID.length) {
		iPhoto = 0;
	}
	showPhoto();
	
	if(gallerySlidePlay) {
		clearTimeout(timerSlide);
		timerSlide = setTimeout('galleryNext();', 1000*5);
	}
}


