//            __       _                                      _           
//__   _____ / _| ___ | |_ ___  ___  __ _ _ __ __ _ _ __   __| | ___  ___ 
//\ \ / / __| |_ / _ \| __/ _ \/ __|/ _` | '__/ _` | '_ \ / _` |/ _ \/ __|
// \ V / (__|  _| (_) | || (_) \__ \ (_| | | | (_| | | | | (_| |  __/\__ \
//  \_/ \___|_|  \___/ \__\___/|___/\__, |_|  \__,_|_| |_|\__,_|\___||___/.js
//                                  |___/                             v2.0

//Una librería de alberto viñuela - voet cranf - http://voet.cranf.net - julio 2004
//prohibido su empleo comercial - aficionados e iniciativas no lucrativas usadlo libremente
//las empresas NO pueden vender esta librería

//CONFIGURACIÓN
var VCFdir="vcfimage"; //directorio de iconitos
var VCFmargen=30; //margen con respecto al borde de página, mínimo 30 con mozilla, please



//VARIABLES GLOBALES
var VCFtitulo=""; //titulo de la foto
var VCFmargen2=VCFmargen*2; //no tocar
var VCFxraton,VCFyraton,VCFxcentro,VCFycentro; //coordenadas de ratón en tiempo real y lugar del click
var VCFcroLeft,VCFcroTop,VCFcliWidth,VCFcliHeight; //cropping y ancho de la imagen
var VCFganfoto,VCFgalfoto; //altura y anchura originales de la foto
var VCFotoactiva=false; //foto visible o no visible
var VCFzoom=false; //si se ha realizado algún zoom desde la primera carga
var VCFotobuffer=new Image(); //lugar de carga real de la aphoto
var VCFoffx="",VCFoffy=""; //offset

//definición de estilos
document.write('<style>');
document.write('.vcfoboton {background-color:#587D87}');
document.write('.vcfinstruccion {font-family:verdana; font-size:10px;color:#9FB5BA;background:#114654; vertical-align:top;display:table-cell;padding-left:20px;padding-top:5px;line-height:10px}');
document.write('</style>');
//definición de la capa de trabajo
document.write('<div id=VCFportafoto style="position:absolute;width:600px;height:30px;top:-1000px;left:-1000px;z-index:9000;"><img src="'+VCFdir+'/fotcargando.gif"></div>');

//           _              
// _ __ __ _| |_ ___  _ __  
//| '__/ _` | __/ _ \| '_ \ 
//| | | (_| | || (_) | | | |
//|_|  \__,_|\__\___/|_| |_|
                         
//****************
function VCFclicafoto(e)
{
if(document.all) VCFclana=event.srcElement.className;
else VCFclana=e.target.className;

if(VCFclana=="VCFotogrande") 
	{
	if(document.getElementById("VCFportafoto"))
		{
	VCFxcentro=VCFxraton;
	VCFycentro=VCFyraton;
	VCFotoactiva=true;
		}
	}
return false;
}

//****************
function VCFmueveraton(e)
{
if(document.all)
	{
VCFxraton=event.clientX+document.body.scrollLeft;
VCFyraton=event.clientY+document.body.scrollTop;
	}
	else
	{
VCFxraton=e.pageX;
VCFyraton=e.pageY;
	}

return VCFcalculaF();
}

//***************
function VCFsueltafoto()
{VCFotoactiva=false;}


// _           _                        
//| |__   ___ | |_ ___  _ __   ___  ___ 
//| '_ \ / _ \| __/ _ \| '_ \ / _ \/ __|
//| |_) | (_) | || (_) | | | |  __/\__ \
//|_.__/ \___/ \__\___/|_| |_|\___||___/
                                     
//***************
function VCFzoom2x()
{
lancho=document.VCFoto.width;lalto=document.VCFoto.height;
if(!VCFzoom) {VCFganfoto=lancho;VCFgalfoto=lalto;VCFzoom=true}
document.VCFoto.width=lancho*2;
if(VCFoffx!="desac") {VCFoffx=VCFoffx*2+VCFcliWidth/2;} 
	else{
		anchopan=(document.all? document.body.clientWidth-VCFmargen2: self.innerWidth-VCFmargen2);
		if(lancho*2>anchopan) VCFoffx=lancho-anchopan/2;
		}	
if(VCFoffy!="desac") {VCFoffy=VCFoffy*2+VCFcliHeight/2;}
	else{ 
		altopan=(document.all? document.body.clientHeight-VCFmargen2: self.innerHeight-VCFmargen2);
		if(lalto*2>VCFcliHeight) VCFoffy=lalto-altopan/2;
		}


VCFcalculaF();
}

//***************
function VCFzoom100()
{
if(!VCFzoom) return;
else 
	{document.VCFoto.width=VCFganfoto;
	VCFcalculaF();}
}


//***************
function VCFzoom05x()
{
if(!VCFzoom) {VCFganfoto=document.VCFoto.width;VCFgalfoto=document.VCFoto.height;VCFzoom=true}
document.VCFoto.width=document.VCFoto.width/2;
if(VCFoffx!="desac")VCFoffx=(VCFoffx-VCFcliWidth/2)/2;
if(VCFoffy!="desac")VCFoffy=(VCFoffy-VCFcliHeight/2)/2;
VCFcalculaF();

}

//***************
function VCFzoomcierra()
{document.getElementById("VCFportafoto").style.display="none";
document.getElementById("VCFportafoto").innerHTML="";
VCFtitulo="";
VCFotoactiva=false;
VCFoffx="desac";VCFoffy="desac";
VCFzoom=false;
}

//                 _             
// _ __ ___   ___ | |_ ___  _ __ 
//| '_ ` _ \ / _ \| __/ _ \| '__|
//| | | | | | (_) | || (_) | |   
//|_| |_| |_|\___/ \__\___/|_|   
                               
//****************
function VCFcalculaF()
{
if(!document.getElementById("VCFfoto")) return true;


divfo=document.getElementById("VCFportafoto");
VCFdivfoto=divfo.style;
divlafo=document.getElementById("lafoto");
divlafoto=divlafo.style;

anfoto=document.VCFoto.width;
alfoto=document.VCFoto.height;

if(document.all) //explorer
{
VCFcroLeft=document.body.scrollLeft;
VCFcroTop=document.body.scrollTop;
VCFcliWidth=document.body.clientWidth;
VCFcliHeight=document.body.clientHeight;
}
else //mozilla
{
VCFcroLeft=self.pageXOffset;
VCFcroTop=self.pageYOffset;
VCFcliWidth=self.innerWidth;
VCFcliHeight=self.innerHeight;
}

altomenu=document.getElementById("VCFalturacelda").offsetHeight;

VCFcliWidth-=VCFmargen2;
VCFcliHeight-=VCFmargen2;
sobrax=anfoto-VCFcliWidth;
sobray=alfoto-VCFcliHeight+altomenu;

if(VCFoffx=="desac" && sobrax>0) VCFoffx=sobrax/2;
if(VCFoffy=="desac" && sobray>0) VCFoffy=sobray/2;

document.getElementById("vcfinstruccion").innerHTML=VCFtitulo;

if(sobrax<=0 && sobray<=0) 	document.getElementById("VCFfoto").style.cursor="default";
else document.getElementById("VCFfoto").style.cursor="move";


if(sobrax>0)
	{//cropeado
	if(VCFotoactiva) //solo si está calcada
			VCFoffx+=(VCFxraton-VCFxcentro)/4;

			if(VCFoffx<0) VCFoffx=0;
			if(VCFoffx>sobrax) VCFoffx=sobrax;
			dlfsl=VCFoffx;
			fotoizquierda=VCFcroLeft+VCFmargen;
			VCFdivfoto.width=VCFcliWidth;
			divlafoto.width=VCFcliWidth;
	}
	else
	{fotoizquierda=VCFcroLeft+(VCFcliWidth-anfoto)/2+VCFmargen;
	  VCFdivfoto.width=anfoto;
	  divlafoto.width=anfoto}

if(sobray>0)
	{//cropeado
	if(VCFotoactiva) //solo si está calcada
			VCFoffy+=(VCFyraton-VCFycentro)/4;

			if(VCFoffy<0) VCFoffy=0;
			if(VCFoffy>sobray) VCFoffy=sobray;
			dlfst=VCFoffy;
			fotoarriba=VCFcroTop+VCFmargen;
			VCFdivfoto.height=VCFcliHeight;
			divlafoto.height=VCFcliHeight-altomenu;
	}
	else
	{
	fotoarriba=VCFcroTop+(VCFcliHeight-alfoto)/2+VCFmargen;
	VCFdivfoto.height=alfoto+altomenu;
	divlafoto.height=alfoto;
	}


VCFdivfoto.top=fotoarriba;
VCFdivfoto.left=fotoizquierda;

if(document.all)
	{
if(sobrax>0) divlafo.scrollLeft=dlfsl;
if(sobray>0) divlafo.scrollTop=dlfst;
	}
	else //mozilla
	{
	if(sobrax>0 || sobray>0)
		{
		if(sobrax<=0) dlfsl=0;
		if(sobray<=0) dlfst=0;
		divlafoto.left=-dlfsl;

		divlafoto.top=-dlfst+altomenu;
		divlafoto.width=VCFcliWidth+dlfsl;
		divlafoto.height=VCFcliHeight+dlfst;
		divlafoto.clip="rect("+dlfst+"px," +(dlfsl+VCFcliWidth)+"px,"+(dlfst+VCFcliHeight-altomenu)+"px,"+dlfsl+"px)";
		}
	}

if(alfoto<50) setTimeout("VCFcalculaF()",100);
return false;
}

//  __ _      _                    
// / _(_) ___| |__   ___ _ __ ___  
//| |_| |/ __| '_ \ / _ \ '__/ _ \ 
//|  _| | (__| | | |  __/ | | (_) |
//|_| |_|\___|_| |_|\___|_|  \___/ 
                               
//****************
function VCFabrefoto(url,VVVtitulo)
{
if(VVVtitulo) VCFtitulo=VVVtitulo;
VCFoffx="desac";VCFoffy="desac";
VCFzoom=false;
VCFdivfoto=document.getElementById("VCFportafoto");
VCFblanco=' onmouseover=this.style.background="#ffffff" onmouseout=this.style.background="#587D87" ';
q='<table cellspacing=0 border=0 cellpadding=0 width=100%><tr><td  nowrap width=60 style="background:#114654" id=VCFalturacelda align=left><span id=VCFbotones style="display:none"><img '+VCFblanco+' class=vcfoboton src="'+VCFdir+'/fotmas.gif" onclick="VCFzoom2x()"><img '+VCFblanco+' class=vcfoboton  src="'+VCFdir+'/fot100.gif" onclick="VCFzoom100()"><img '+VCFblanco+' class=vcfoboton  src="'+VCFdir+'/fotmenos.gif" onclick="VCFzoom05x()"></span></td><td nowrap id=vcfinstruccion class=vcfinstruccion></td><td style="background:#114654" align=right><img '+VCFblanco+' class=vcfoboton src="'+VCFdir+'/fotequis.gif" onclick="VCFzoomcierra()"></td></tr>';
q+='<tr><td colspan=3><div id=lafoto style="position:absolute;left:0px;top:20px;overflow:hidden" ondblclick="VCFzoomcierra()"><img id=VCFfoto name=VCFoto class=VCFotogrande src="'+VCFdir+'/fotcargando.gif" ondrag=VCFcalculaF()></div></td></tr></table>';
VCFdivfoto.innerHTML=q;
VCFotobuffer=new Image();
VCFotobuffer.src=url;
setTimeout("VCFcargado()",200);
VCFdivfoto.style.display="";
}

//***************
function VCFcargado()
{if(VCFotobuffer.complete) 
	{
	document.VCFoto.src=VCFotobuffer.src; 
	document.getElementById("VCFbotones").style.display="";
	VCFcalculaF();
	}
	else setTimeout("VCFcargado()",200);}

//                      _            
//  _____   _____ _ __ | |_ ___  ___ 
// / _ \ \ / / _ \ '_ \| __/ _ \/ __|
//|  __/\ V /  __/ | | | || (_) \__ \
// \___| \_/ \___|_| |_|\__\___/|___/
// cuida la compatibilidad de tu código con estos eventos                                   


if (!document.all)
{
window.document.captureEvents(Event.MOUSEUP | Event.MOUSEDOWN | Event.MOUSEMOVE); 
document.onmousedown=VCFclicafoto;
document.onmousemove=VCFmueveraton;
document.onmouseup=VCFsueltafoto;
}
else
{
document.onmousedown=VCFclicafoto;
document.onmousemove=VCFmueveraton;
document.onmouseup=VCFsueltafoto;
}