/***********************************************
* Photo Album script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//var dimension="4x1" //Specify dimension of gallery (number of images shown), such as 4x2, 3x1 etc

//Specify images:
//galleryarray[x]=["path_to_image", "optional_title_attribute", "optional_text_description", "optional_link"]

var href_target="" //Enter target attribute of links, if applicable

var totalslots=dimension.split("x")[0]*dimension.split("x")[1]

function buildimage(i){
	var tempcontainer=galleryarray[i][3]!=""? '<a href="javascript://doNothing();" onclick="javascript:window.open(\'includes/fotodetalle.jsp?'+galleryarray[i][3]+'?'+galleryarray[i][2]+'?'+galleryarray[i][1]+'\', \'fotop\', \'resizable=1,HEIGHT=200,WIDTH=200\');" >' : ""
	tempcontainer+='<img id="img' + i + '" src="'+galleryarray[i][0]+'" border="0" title="'+galleryarray[i][2]+'">'
	tempcontainer=galleryarray[i][4]=="map"? tempcontainer+'<br><span class="textoContenido">Ver Mapa</span>' : tempcontainer
	tempcontainer=galleryarray[i][3]!=""? tempcontainer+'</a>' : tempcontainer
	//tempcontainer=galleryarray[i][2]!=""? tempcontainer+'<br \/>'+'<span class="texto">' + galleryarray[i][2] + '</span>' : tempcontainer
	tempcontainer=galleryarray[i][2]!=""? tempcontainer+'<div class="texto" align="left" style="display:none;position:absolute;align:left;color:#' + galleryarray[i][1]  +';text-shadow:Yellow;font-weight:bold" id="txt' + i + '" title="' + galleryarray[i][2]  +'">' + galleryarray[i][2] + '</div>' : tempcontainer
	//alert(i);
	return tempcontainer
}

function jumptopage(p){
	var startpoint=(p-1)*totalslots
	var y=1;
	for (i=0; i<totalslots; i++){
		document.getElementById("slide"+i).innerHTML=(typeof galleryarray[startpoint+i]!="undefined")? buildimage(startpoint+i) : ""
	}
	placeText();
	if ((p+1)>Math.ceil(galleryarray.length/totalslots)){
		document.getElementById("LnkMore").href = "javascript://donothing";
		document.getElementById("LnkMore").className = "toggleopacity";	
	}
	else{
		document.getElementById("LnkMore").href = "javascript:jumptopage(" + (p+1) +")";
		document.getElementById("LnkMore").className = "";	
	}
	
	if ((p-1)>0){
		document.getElementById("LnkLess").href = "javascript:jumptopage(" + (p-1) +")";
		document.getElementById("LnkLess").className = "";
	}
	else{
		document.getElementById("LnkLess").href = "javascript://donothing";
		document.getElementById("LnkLess").className = "toggleopacity";	
	}
}

function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function placeText(){
	//alert('Total : ' + galleryarray.length);
	for (j=0; j<galleryarray.length; j++){
		//alert(j);
		if (document.getElementById('img'+j)&&galleryarray[j][2]!=""){
			el = document.getElementById('img'+j);
			//alert('X : ' + findPosX(el) + ' Y : ' + findPosY(el));
			/*el = document.getElementById('img2');
			alert('X : ' + findPosX(el) + ' Y : ' + findPosY(el));
			alert('Size : ' + el.width + ' x ' + el.height);*/
			d = document.getElementById('txt'+j);
			d.style.left = findPosX(el);
			//alert(d.innerText.length);
			d.style.width = el.width;
			//alert('width : ' + d.style.width + ' len : ' + d.innerText.length);
			var rulerSpan = document.getElementById('ruler');
			rulerSpan.innerHTML = d.innerText;
			
			//alert(rulerSpan.offsetWidth);
			
			if (rulerSpan.offsetWidth < el.width){
				d.style.top = findPosY(el)+el.height-11;
			}else{
				d.style.top = findPosY(el)+el.height-22;
			}
			d.style.display = 'block';
			//alert(d.style.left);	
		}
	}	
}

window.onresize= placeText;

document.write('<span class="texto" id="ruler" style="visibility:hidden;align:left;color:#FFFFFF;text-shadow:Yellow;font-weight:bold"></span>');

function buildNow(){

	document.write('<table border="0" cellspacing="3" align="center"><tr align="center"><td><a class="toggleopacity" href="javascript://donothing" id="LnkLess"><img border="0" src="imagenes/flechaizq.gif" width="13" height="13"></a>&nbsp;</td>');
	var curimage=0
	for (y=0; y<dimension.split("x")[1]; y++){
		for (x=0; x<dimension.split("x")[0]; x++){
			if (curimage<galleryarray.length)
				document.write('<td id="slide'+curimage+'" class="slideshow">'+buildimage(curimage)+'</td>')
		curimage++
		}
		//document.write('<br style="clear: left" />')
	}
	document.write('<td>&nbsp;<a href="javascript:jumptopage(2)" id="LnkMore"><img border="0" src="imagenes/flechader.gif" width="13" height="13"></a></td></tr></table>');
	
	if ((Math.ceil(galleryarray.length/totalslots)==1)||(Math.ceil(galleryarray.length/totalslots)==0)){
		document.getElementById("LnkMore").href = "javascript://donothing";
		document.getElementById("LnkMore").className = "toggleopacity";	
	}
	
}
