/*<![CDATA[*/
//******************************************************************************
// @name:        cbnews.js
// @purpose:     scripts que sao utilizados em todo o site.
//
//
// @author:      Ruhan Bidart - ruhan@2xt.com.br
// @created:     12/02/2008
//******************************************************************************
// tempo do slideshow em segundos
var _slideshow_time = 5;
// marcador de timeout do slideshow
var _slideshow_timeout = null;
var _slideshow_foto_atual = 0;


function iniciar_slideshow(sender) {
   var attr = 'iniciar';
   var img = document.getElementById('img_show');
   var url_iniciar = document.getElementById('iniciar').value;
   var url_parar = document.getElementById('parar').value;	
   var iniciar = parseInt(sender.getAttribute(attr));
   sender.removeAttribute(attr);
   sender.setAttribute(attr, iniciar == 1 ? '0' : '1');
   
   if(iniciar) {       
       //sender.value = 'Parar SlideShow';
	   img.src = url_parar;
       iniciar_automatico();
   } else {
       //sender.value = 'Iniciar SlideShow';
	   img.src = url_iniciar;
       clearTimeout(_slideshow_timeout);
   }
}

function iniciar_automatico() {
    var e_table = document.getElementById('tabela_de_thumbs');
    var e_l_thumbs = e_table.getElementsByTagName('img');
    var len = e_l_thumbs.length; 
    
    if(_slideshow_foto_atual == len-1) {
        clearTimeout(_slideshow_timeout);
        return;
    } else _slideshow_foto_atual++;
    
    var el = e_l_thumbs[_slideshow_foto_atual];
    el.parentNode.onclick();
    
    _slideshow_timeout = setTimeout('iniciar_automatico()', _slideshow_time * 1000);
}
