var indxFoto = parseInt(getQueryVariable('foto'));
var byUrl = false;
var ctrSlide = (indxFoto)?indxFoto:0 ;
var showSlide = false ;
var t = "" ;


function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
	
	return "";
}
function chPhoto(num) {
   indxFoto = (indxFoto)?indxFoto:num;
	if(byUrl){
		if(indxFoto >= numFt){
			document.location = "?foto="+(numFt-1);
		}
		if(indxFoto < 0){
			document.location = "?foto="+0;
		} 	   
	}
  
   var objPainel = document.getElementById('painel') ;
   var idFoto = "ft_id_" + indxFoto ;
   var objFt = document.getElementById(idFoto) ;
   var tmp = objFt.innerHTML.replace('.jpg','.jpg') ;
   objPainel.innerHTML = tmp.replace('.gif','.gif') ;

   if (document.getElementById('selo')){
	   var objSelo = document.getElementById('selo');
	   var idSelo = "selo_id_" + indxFoto;
	   objSelo.innerHTML = document.getElementById(idSelo).innerHTML;
   }
   
}




function altFoto(num) {
	indxFoto = num;
	if(byUrl){
		document.location = "?foto="+indxFoto; 
	}else{
	   var objPainel = document.getElementById('painel') ;
	   var idFoto = "ft_id_" + indxFoto ;
	   var objFt = document.getElementById(idFoto) ;
	   var tmp = objFt.innerHTML.replace('.jpg','.jpg') ;
	   objPainel.innerHTML = tmp.replace('.gif','.gif') ;
	   ctrSlide = indxFoto ;		
	} 
}


function slideShow() {

   
    altFoto(ctrSlide);
    ctrSlide++;
    
    if (ctrSlide==numFt) {ctrSlide = 0};
    
    if (showSlide) {
      t = setTimeout("slideShow()",2500);
    }
}

function ligaDesliga() {
    var p = document.getElementById('OnOff') ;
    
    showSlide = !showSlide ;
    if (showSlide)  {
      slideShow();
      p.innerHTML = "<div id=\"OnOff\"><a href=\"javascript:ligaDesliga()\"><img src=\"/img/b_desligar_slide.jpg\"></a></div>" ;
    } else {
      clearTimeout(t);
      p.innerHTML = "<div id=\"OnOff\"><a href=\"javascript:ligaDesliga()\"><img src=\"/img/b_ligar_slide.jpg\"></a></div>" ;
    }
}

function navFoto(step) {
    clearTimeout(t);

    if (step == -1) {

      if (ctrSlide == 0) { 
        ctrSlide = numFt - 1 ;
      } else {
        ctrSlide = ctrSlide - 1 ;
      }

    } else {

      if (ctrSlide == (numFt - 1) ) { 
        ctrSlide = 0 ;
      } else {
        ctrSlide = ctrSlide + 1 ;
      }
    }

    altFoto(ctrSlide);
}
 