window.addEventListener?window.addEventListener('load',cambia,false):window.attachEvent('onload',cambia);
var navegador=navigator.appName;
var NUM_FOTOS=7;
var MOV_MIN=40;
var l1,l2, j=1;
var op=.99;
var ancho,alto,step_ancho,step_alto;
var _top,test;
var fin=false;
var anchomode=false,
	altomode=false,
	gradmode=true,
	posmode=true,
	gradstep=1/40;
//if(navegador=="Microsoft Internet Explorer") posmode=false;
var qq1=new Image();
var qq2=new Image();
	document.onkeypress=teclaPulsada;
var anchomax=717, altomax=255;
//////////////////////////CAMBIA/////////////////////////////////////////////////////
function cambia()
{
if(!document.getElementById || !document.createElement)return;
l1=document.getElementById('primera');
qq1.src=l1.src;
l1.style.height=anchomax*qq1.height/qq1.width;
l2=document.getElementById('segunda');
qq2.src=l2.src;
l2.style.height=anchomax*qq2.height/qq2.width;
step_ancho=anchomax*gradstep;
step_alto=altomax*gradstep;
ancho=0;
alto=0;
if(posmode==true&&l1.height>altomax+MOV_MIN){_top=0;test=false;setTimeout(pasea,3000);}
else setTimeout(baja,3000);
}
///////////////////////CHANGE/////////////////////////////////////////////////////////
function change()
{
if(!fin){
//document.title="change";
ancho=0;
alto=0;
	j++;
	if (j>NUM_FOTOS-1) j=0;
	op=.99;
	l1.src=l2.src;
	qq1.src=l1.src;
	l1.style.height=anchomax*qq1.height/qq1.width;
	l2.src='Imagenes/cabecera' + (j+1)+'.jpg';
//	l2.src='c:/Namibia/3Namibia (04-I-10)/DSC0' + (j+1+1272)+'.jpg';
	qq2.src=l2.src;
	l2.style.height=anchomax*qq2.height/qq2.width;
	l1.style.opacity = op;
	l1.style.MozOpacity = op;
	l1.style.filter = 'alpha(opacity=' + (op*100) + ')';
	l1.style.top="0px";
if(posmode==true&&l1.height>altomax+MOV_MIN){_top=0;test=false;pasea();}
else setTimeout( baja,3000);
}
return;
}
/////////////////////////////////////BAJA///////////////////////////////////////////
function baja(){
//document.title="baja";
op-=gradstep; 
if(op<0) setTimeout(change,3000);
else{
ancho+=step_ancho; 
alto+=step_alto;
if (ancho>anchomax) ancho=anchomax;
if (altomax>alto) alto=altomax;
if (gradmode==true){
l1.style.opacity = op;
l1.style.MozOpacity = op;
l1.style.filter =  'alpha(opacity=' + (op*100) + ')';
l2.style.opacity = 1-op;
l2.style.MozOpacity =1- op;
l2.style.filter =  'alpha(opacity=' + (100-op*100) + ')';

}
if(anchomode==true)l2.style.width = ancho+'px';
if (altomode==true)l2.style.height = alto+'px';
setTimeout(baja,50);
}
return;
}
////////////////////////////////////////PASEA////////////////////////////////////////
function pasea(){
//document.title="pasea"+_top;
if (_top==0&&test==true){/*l1.style.top=0+"px";document.title="retorna"+j;*/
setTimeout(baja,3000);}
else{
if(test==false)_top-=step_alto; else _top+=step_alto;
if (_top<-altomax) test=true;
if(_top>0)_top=0;
l1.style.top=_top+"px";
setTimeout(pasea,90);
}
return;
}
////////////////////////////////////TECLAPULSADA//////////////////////////////////////
function teclaPulsada(evt)
{
evt = (evt) ? evt : window.event
if (!evt ) evt=window.Event;
var teclaASCII=evt.keyCode; 
var teclaCHAR=String.fromCharCode(teclaASCII);
switch (teclaCHAR.toUpperCase())
{ 
case 'G': gradmode=!gradmode;break; 
case 'A': altomode=!altomode;break; 
case 'W': anchomode=!anchomode;break; 
case 'P': posmode=!posmode;break; 
case '+': j++;if (j>NUM_FOTOS-1) j=0;break;
case '-': j--;if (j<0) j=0;break;
case 'S':fin=!fin;if(!fin) change();break;
default: 
} 
}
