/* Simple Image Trail script- By JavaScriptKit.com
   Visit http://www.javascriptkit.com for this script and more
   This notice must stay intact                                              */

var offsetfrommouse=[25,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 400;	// maximum image size.
var currentimagewidth  = 400;	// maximum image size.

if (document.getElementById || document.all){
  document.write('<div id="foto_div" style="position: absolute; visibility: hidden; top: 0px; left: -500px; width: 300px; height: 1px; z-index: 1000">');
	document.write('</div>');
}

function gettrailobj(){
if (document.getElementById)
	return document.getElementById("foto_div").style
else if (document.all)
	return document.all.trailimagid.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
	{
		return document.getElementById("foto_div");
	}
	else if (document.all)
	{
		return document.all.trailimagid;
	}
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showtrail(imageName, imageWidth, imageHeight, imageTitle){
	counterAdjustment = 0;
	document.onmousemove=followmouse;

  newHTML = '<div style="border: 3px solid #939393; background-color: #ffffff; padding: 3px; width: ' + imageWidth + 'px; float: left; text-align: center; font-family: Arial; color: #828282">';
  newHTML = newHTML + '<div style="width: ' + imageWidth + 'px; margin-bottom: 2px; padding-top: 2px; padding-bottom: 3px; background-color: #009900; font-size: 12px; color: #FFFFFF; font-weight: bold">' + js_web_name + '</div>';
  newHTML = newHTML + '<div style="width: ' + imageWidth + 'px; height: ' + imageHeight + 'px; background-color: #ffffff"><img src="' + imageName + '" width="' + imageWidth + '" height="' + imageHeight + '" alt="" /></div>';

  if (imageTitle.length > 0) {
    newHTML = newHTML + '<div style="width: ' + imageWidth + 'px; margin-top: 2px; padding-bottom: 2px; background-color: #ffffff; font-size:11px; border-top: 1px solid #C0C0C0; border-bottom: 1px solid #C0C0C0;">' + imageTitle + '</div>';
  }

  newHTML = newHTML + '</div>';

	gettrailobjnostyle().innerHTML = newHTML;

	gettrailobj().visibility="visible";
}

function hidetrail(){
  gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined") {
		if (docwidth - e.pageX < currentimagewidth + 25){
  		if(navigator.userAgent.indexOf("Firefox")!=-1) {
        xcoord = e.pageX - xcoord - currentimagewidth; // JacSoft quito para Firefox + 2*offsetfrommouse[0]
      }
      else {
        xcoord = e.pageX - xcoord - currentimagewidth + 6*offsetfrommouse[0] ;
      } // Move to the left side of the cursor
		}
    else {
			xcoord += e.pageX;
		}

		if (docheight - e.pageY < (currentimageheight + 110)) {
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		}
    else {
			ycoord += e.pageY;
		}
	}
  else if (typeof window.event != "undefined") {
		if (docwidth - event.clientX < currentimagewidth + 25) {
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth; // JacSoft quito para IE + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		}
    else {
			xcoord += truebody().scrollLeft+event.clientX
		}

    if (docheight - event.clientY < (currentimageheight + 110)) {
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		}
    else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}



/* Muestra una imagen indicando título, origen y licencia en su caso. La función se llama desde
   ImageGalleryLicensed para mostrar una galería de imágenes */
function ShowLicensedImage(curimg,curtitle,curfont,curfonturl,curlic,curlicurl)
{
  if (document.getElementById)
  {
    var fontext = '';

    if ((curfont != '') && (curfonturl != ''))
	  {
      fontext = 'Imagen obtenida de <a href="' + curfonturl + '">' + curfont + '</a> ';
  	}
    else if (curfont != '')
    {
      fontext = 'Imagen obtenida de ' + curfont + ' ';
    }

    if ((fontext == '') && (curlic != ''))
    {
      fontext = 'Imagen obtenida ';
    }

    // Licencia de la imagen
    if ((curlic != '') && (curlicurl != ''))
	  {
      fontext = fontext + 'bajo licencia <a href="' + curlicurl + '">' + curlic + '</a>';
  	}
    else if (curlic != '')
    {
      fontext = fontext + 'bajo licencia ' + curlic;
    }

    document.getElementById('fotogrande').src     = curimg;
    document.getElementById('titulo').innerHTML   = curtitle;
    document.getElementById('licencia').innerHTML = fontext;
  }
}