var total_gal_cnt 		= 0;
var curr_load	  		= 0;
var galery_link   		= new Array();
var galery_first_photo 	= new Array();
var galery_title 		= new Array();
var galery_link_full 	= new Array();

function thumbNavNext()
{
	curr_load 	= curr_load + 1;

	if (curr_load > total_gal_cnt-1)
	{
		curr_load = 0;
	}

	f1 = curr_load;


	if (f1+1 > total_gal_cnt-1)
	{
		f2 = 0;
	}
	else
	{
		f2 = f1+1;
	}

	if (f2+1 > total_gal_cnt-1)
	{
		f3 = 0;
	}
	else
	{
		f3 = f2+1;
	}

	$('#galleryfoto-related-gallery-3x-photo-1 img').attr('src', 'http://s2.15cdn.lt/img/thumb-loader.gif').addClass('galleryfotoloader');
	$('#galleryfoto-related-gallery-3x-photo-2 img').attr('src', 'http://s2.15cdn.lt/img/thumb-loader.gif').addClass('galleryfotoloader');
	$('#galleryfoto-related-gallery-3x-photo-3 img').attr('src', 'http://s2.15cdn.lt/img/thumb-loader.gif').addClass('galleryfotoloader');


	$('#galleryfoto-related-gallery-3x-photo-1').click( function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[f1];
	});
	$('#galleryfoto-related-gallery-3x-photo-1 img').attr('src', galery_first_photo[f1]).removeClass('galleryfotoloader');
	$('#galleryfoto-gal-title1').html(galery_link_full[f1]);


	$('#galleryfoto-related-gallery-3x-photo-2').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[f2];
	});
	$('#galleryfoto-related-gallery-3x-photo-2 img').attr('src', galery_first_photo[f2]).removeClass('galleryfotoloader');
	$('#galleryfoto-gal-title2').html(galery_link_full[f2]);

	$('#galleryfoto-related-gallery-3x-photo-3').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[f3];
	});
	$('#galleryfoto-related-gallery-3x-photo-3 img').attr('src', galery_first_photo[f3]).removeClass('galleryfotoloader');
	$('#galleryfoto-gal-title3').html(galery_link_full[f3]);

}

function thumbNavPrev()
{
	curr_load 	= curr_load - 1;

	if (curr_load < 0)
	{
		curr_load = total_gal_cnt-1;
	}
	f1 = curr_load;


	if (f1+1 > total_gal_cnt-1)
	{
		f2 = 0;
	}
	else
	{
		f2 = f1+1;
	}

	if (f2+1 > total_gal_cnt-1)
	{
		f3 = 0;
	}
	else
	{
		f3 = f2+1;
	}


	$('#galleryfoto-related-gallery-3x-photo-1 img').attr('src', 'http://s2.15cdn.lt/img/thumb-loader.gif').addClass('galleryfotoloader');
	$('#galleryfoto-related-gallery-3x-photo-2 img').attr('src', 'http://s2.15cdn.lt/img/thumb-loader.gif').addClass('galleryfotoloader');
	$('#galleryfoto-related-gallery-3x-photo-3 img').attr('src', 'http://s2.15cdn.lt/img/thumb-loader.gif').addClass('galleryfotoloader');


	$('#galleryfoto-related-gallery-3x-photo-1').click( function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[f1];
	});
	$('#galleryfoto-related-gallery-3x-photo-1 img').attr('src', galery_first_photo[f1]).removeClass('galleryfotoloader');
	$('#galleryfoto-gal-title1').html(galery_link_full[f1]);


	$('#galleryfoto-related-gallery-3x-photo-2').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[f2];
	});
	$('#galleryfoto-related-gallery-3x-photo-2 img').attr('src', galery_first_photo[f2]).removeClass('galleryfotoloader');
	$('#galleryfoto-gal-title2').html(galery_link_full[f2]);


	$('#galleryfoto-related-gallery-3x-photo-3').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[f3];
	});
	$('#galleryfoto-related-gallery-3x-photo-3 img').attr('src', galery_first_photo[f3]).removeClass('galleryfotoloader');
	$('#galleryfoto-gal-title3').html(galery_link_full[f3]);
}

function changeMarking (el)
{
	$('.galleryfoto-catlg-col p').removeClass('fotocatactive');
	$(el).parent().addClass("fotocatactive");
}

function loadThumbs(nm, t)
{
	$(this).parent().toggleClass('fotocatactive');
	$('#catalog_titlex').text(t);

	jq_galleryfoto_loader = $('#galleryfoto-loader');
	jq_galleryfoto_loader.css('display','block');
	$('#rltd-gllr').css('display','none');


	//taupom vartotojo trafika
	var gpt 	= '#galleryfoto-gal-title';
	var gprg 	= '#galleryfoto-related-gallery-3x-photo-';

	//nuimam visus
	$(gpt + '1, '+ gpt + '2, ' + gpt + '3').html('&nbsp;');
	$(gprg + '1 img, '+gprg + '2 img, '+gprg + '3 img').addClass('galleryfotoloader');

	ret 			= ax_getGaleriesCatalogsByName(nm);
	total_gal_cnt 	= curr_load = 0;
	str 			= '';
	jQuery.each(ret, function(i, val)
	{
		if (val.id != gal_id)
		{
			galery_link[total_gal_cnt] 			= base + gal_path + '/' + val.gal_url;
			galery_link_full[total_gal_cnt]		= '<a href="'+galery_link[total_gal_cnt]+'" title="'+val.gal_title+'" onclick="_gaq.push([\'_trackPageview\', \'/navigacija/galeriju_katalogai\']);">'+val.gal_title+'</a>';
			galery_first_photo[total_gal_cnt] 	= base + 'sir/img.php?image=' + val.first_photo + '&type=thumb';
			galery_title[total_gal_cnt] 		= val.gal_title;

			str 								+= '<img src="'+galery_first_photo[total_gal_cnt]+'" alt="" />';
			total_gal_cnt++;
		}
	});

	//uzlodina backgrounde
	$('#galeryfoto').html(str);

	jq_galleryfoto_loader.hide();
	$('#rltd-gllr').show();


	$(gprg + '1').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location = galery_link[curr_load];
	});

	$(gprg + '1 img').attr('src', galery_first_photo[curr_load]).removeClass('galleryfotoloader');
	$(gpt + '1').html(galery_link_full[curr_load]);


	$(gprg + '2').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[curr_load+1];
	});

	$(gprg + '2 img').attr('src', galery_first_photo[curr_load+1]).removeClass('galleryfotoloader');
	$(gpt + '2').html(galery_link_full[curr_load+1]);


	$(gprg + '3').click(function () {
		_gaq.push(['_trackPageview', '/navigacija/galeriju_katalogai']);
		window.location=galery_link[curr_load+2];
	});
	$(gprg + '3 img').attr('src', galery_first_photo[curr_load+2]).removeClass('galleryfotoloader');
	$(gpt + '3').html(galery_link_full[curr_load+2]);
}

