document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/system/modules/org.opencms.frontend.photoalbum2/resources/css/elenco_gallerie.css\" />");
document.write("<script type=\"text/javascript\" src=\"/system/modules/org.opencms.frontend.photoalbum2/resources/jquery_lightbox/js/jquery.lightbox.js\"></script>");
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/system/modules/org.opencms.frontend.photoalbum2/resources/jquery_lightbox/css/jquery.lightbox.css\" media=\"screen\" />");


$(function() {
        var countGalleries = $( "#lista_gallerie div[id^='img_galleria']" ).length;
        //$( '#lista_gallerie' ).data("tot", countGalleries );

	for ( k = 1; k <= countGalleries; k++)
	{
		$('#img_galleria' + k + ' li a').lightBox();
	}
});


$(document).ready( function(){

	var perpag = new Array();// = [ eval( $("#perpag1").val() ),  eval( $("#perpag2").val() ) ];
	var start  = new Array();// = [0, 0];

        //var countGalleries = $( '#lista_gallerie' ).data("tot");

        var countGalleries = $( "#lista_gallerie div[id^='img_galleria']" ).length;

	for ( k = 1; k < countGalleries; k++)
	{
		perpag[k] = eval( $( "#perpag" + k ).val() );
		start[k]  = 0;

		if( perpag[k]!=0 && perpag[k] < $('#img_galleria' + k + ' li').length ){
			pager( k, start[k], perpag[k]);

			$('#img_galleria' + k).append( "<a href=\"#\" id=\"galindietro" + k + "\">Indietro</a>" );
			$('#img_galleria' + k).append( "<a href=\"#\" id=\"galavanti" + k + "\">Avanti</a>" );
		}


		$( "#galindietro" + k ).click( function(){
			if( start[k] >= perpag[k] ){
				start[k] -= perpag[k];
				pager( k, start[k], perpag[k])
			}
		});

		$( "#galavanti" + k ).click( function(){
			if( (start[k]+perpag[k]) < $('#img_galleria' + k + ' li').length ){
				start[k] += perpag[k];
				pager( k, start[k], perpag[k] );
			}
		});
	}


	function pager( galleria, start, perpag){
		checkState( galleria );
		$( '#img_galleria' + galleria + ' li' ).hide();

		for ( i=start[galleria]; i<start[galleria]+perpag[galleria]; i++){
			$('#img_galleria' + galleria + ' li:eq('+i+')').fadeIn();
		}
	}

	function checkState( galleria ){
		if( start[galleria]==0 ){ $("#galindietro" + galleria ).addClass('off'); }
		if( start[galleria] >= ( $('#img_galleria' + galleria + ' li').length - perpag[galleria] ) ){ $("#galavanti" + galleria).addClass('off'); }
	}


});

