// JavaScript Document
var maxfotos=10;
var totalfotos=1;
var cur=0;
var next=0;
init();
function init(){
	contarfotos();
}
function contarfotos(){
	totalfotos=0;
	for(i=1;i<=maxfotos;i++){
		next=i.toString();
		if(next.length==1){next="0"+next}
		/*alert("myimg/foto"+next+".jpg");*/
		if (isFile("myimg/foto"+next+".jpg")==true){
			totalfotos=i;
		}	
	}
		/*if (isFile(newimg)==false){
			next="01";
			newimg="imglocal/foto"+next+".gif";
		}*/
}
function showcurfoto(){
			var showfoto= new Fx.Tween ('fotocont', {
			property: 'opacity',
			duration: 250, 
			transition: Fx.Transitions.Quart.easeInOut,
			link: 'chain'});
			/*showfoto.onComplete=function(){
			}*/	
			showfoto.start(0,1);
}
function selectfoto(order){
	
	$('fotocont').onload=function(){
		showcurfoto();
	}
	/*alert($('fotocont').src.slice(-6,-4));*/
		cur=Math.ceil($('fotocont').src.slice(-6,-4));
		next=cur+order;
		
		if(next>totalfotos){next=1}
		if(next<1){next=totalfotos}
		
		next=next.toString();
		if(next.length==1){next="0"+next}

		var newimg="myimg/foto"+next+".jpg";
		/*if (isFile(newimg)==false){
			next="01";
			newimg="imglocal/foto"+next+".gif";
		}*/


		if(cur!=parseInt(next,2)){
				
			$('fotocont').nextfoto=newimg;
			var hidefoto= new Fx.Tween ('fotocont', {
				property: 'opacity',
				duration: 250, 
				transition: Fx.Transitions.Quart.easeInOut,
				link: 'chain'});
			hidefoto.onComplete=function(){
				$('fotocont').src=$('fotocont').nextfoto
			}
			hidefoto.start(1,0);
		}
}
function isFile(str){
        var O= AJ();
        if(!O) return false;
        try
        {
            O.open("HEAD", str, false);
            O.send(null);
            return (O.status==200) ? true : false;
        }
        catch(er)
        {
            return false;
        }
}
function AJ()
    {
        var obj;
        if (window.XMLHttpRequest)
        {
            obj= new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            try
            {
                obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
            }
            catch(er)
            {
                obj=false;
            }
        }
        return obj;
}
