// Rodrigo Polo Gallery, Front End


//--      constants      --//

// Start page
var cpag=0;

// back fordward
var goback_enable=false;
var gonext_enable=false;

var GUI_PICN = 8;
var BGTHUMB = '#d2c9a9 ';

//--      Functions      --//
// Draws the items
function drw(){
	from=GUI_PICN*cpag;
	to=from+GUI_PICN;
	ii=0;
	totalpages = Math.ceil(imfnfo.length / GUI_PICN);

	back_b = '|&lt; &lt;';
	next_b = '&gt; &gt;|';

	if(cpag>0){
		// back enabled
		back_b = '<a href="javascript:gotoPage(0)">|&lt;</a> '+
		'<a href="javascript:gotoPage('+(cpag-1)+')">&lt;</a> ';
	}
	if(to < imfnfo.length){
		// next enabled
		next_b = '<a href="javascript:gotoPage('+(cpag+1)+')">&gt;</a> '+
		'<a href="javascript:gotoPage('+(totalpages-1)+')">&gt;|</a>';
	}

	if(imfnfo[0].length > 0){	
		tdv='';
		//gen elements
		for(i=0;i<imfnfo.length;i++) {
			show = (i>(from-1) && i<(to));
			tdv += pitem(i,show);
		}
		$('rpg_thu').setHTML(tdv);
		// page numbers
		
		nhtml=back_b;
		for(pi=0;pi<totalpages;pi++) {
			if(pi==cpag){
				str_a='<strong>';
				str_b='</strong>';
				url_a=' ';
				url_b=' ';
			}else{
				str_a='';
				str_b='';
				url_a=' <a href="javascript:gotoPage('+pi+')"> ';
				url_b='</a> ';
			}
			nhtml+=' : '+str_a+url_a+str_a+(pi+1)+str_b+url_b+str_b;
		}

		$('rpg_pag_a').setHTML(nhtml+next_b);
		$('rpg_pag_b').setHTML(nhtml+next_b);
	}else{

		$('rpg_pag_a').setHTML('-');
		$('rpg_pag_b').setHTML('-');
		$('rpg_thu').setHTML('<div align="center"><strong><br>No existen imagenes en la galer&iacute;a.<br><br></strong></div>');

	}
	// OnLoad Others
	Lightbox.init({descriptions: '.lightboxDesc', showControls: true});
}

// generate every thumbnail
function pitem(i,show){
	dis=(show)?'block':'none';
	img = imfnfo[i];
	img_descr = unescape(imdsc[i]);
	if(img_descr==undefined || img_descr == 'undefined'){
		img_descr = '';
	}
	if(img_descr!=''){
		img_descr='<br />'+img_descr;
	}
	//
	imgbk=(show)?'url('+ABS_PATH+'gallery/'+CURR_GAL+'s/'+img+'.jpg)':'';
	html = '<div class="rpg_th" style="background:'+BGTHUMB+imgbk+' no-repeat center; display:'+dis+';">'+
	'<a id="th_'+i+'" href="'+ABS_PATH+'gallery/'+CURR_GAL+img+'.jpg" rel="lightbox[rp_gal]" title="'+unescape(imlab[i])+'">'+
	'<img src="'+ABS_PATH+'images/blank.gif" width="126" height="126" /></a>'+
	//'+ABS_PATH+'gallery/'+CURR_GAL+'l/'+img+'.jpg
	//onclick="PhotoX('+i+')" 
	'<div class="lightboxDesc th_'+i+'"><a href="'+ABS_PATH+'gallery/fd.php?file='+CURR_GAL+'l/'+img+'.jpg&fn='+imlab[i]+'">Download</a>'+img_descr+'<br /></div>'+
	'</div>';
	return html;
}
// change page
function gotoPage(n){
	cpag = n;
	drw();
}

// Hide
function $h(id){   
	$(id).style.display = 'none';
}

//--      OnLoad Triguer      --//
window.addEvent('domready',function(){
	drw();
});