var destaque_index = 1;

function select_destaque(index) {
  destaque_index = index;    
  var d1 = $('destaque1');
  var d2 = $('destaque2');
  var d3 = $('destaque3');
  
  var t1 = $('thumb_destaque1');
  var t2 = $('thumb_destaque2');
  var t3 = $('thumb_destaque3');

  
  d1.style.display = 'none';
  d2.style.display = 'none';
  d3.style.display = 'none';
  
  t1.className = "thumb_image";      
  t2.className = "thumb_image";      
  t3.className = "thumb_image";      
  
  if (index == 1) {
    t1.className = "thumb_image_selected";      
    new Effect.Appear(d1, {duration: 3});  
  }
  else if (index == 2) {
    t2.className = "thumb_image_selected";      
    new Effect.Appear(d2, {duration: 3});  
  }
  else {
    t3  .className = "thumb_image_selected";      
    new Effect.Appear(d3, {duration: 3});  
  }  
}

function slide_show_handler() {    
  var d1 = $('destaque1');
  var d2 = $('destaque2');
  var d3 = $('destaque3');
  
  var subtitle = $('subtitle');
  
  var t1 = $('thumb_destaque1');
  var t2 = $('thumb_destaque2');
  var t3 = $('thumb_destaque3');
  
  
  switch (destaque_index) {
    case 1:
      new Effect.Fade(d3, {duration: 1});
      d3.hide();
      subtitle.innerHTML = "<span>" + subtitles[0] + "</span>";
      new Effect.Appear(d1, {duration: 3});  
      
      t3.className = "thumb_image";
      t1.className = "thumb_image_selected";            
      break;
      
    case 2:
      new Effect.Fade(d1, {duration: 1});      
      d1.hide();
      subtitle.innerHTML = "<span>" + subtitles[1] + "</span>";
      new Effect.Appear(d2, {duration: 3});            
      
      t1.className = "thumb_image";
      t2.className = "thumb_image_selected";      
      break;
      
    case 3:
      new Effect.Fade(d2, {duration: 1});      
      d2.hide();
      subtitle.innerHTML = "<span>" + subtitles[2] + "</span>";
      new Effect.Appear(d3, {duration: 3});            

      t2.className = "thumb_image";
      t3.className = "thumb_image_selected";      
      break;
  }
  
  destaque_index = (destaque_index % 4) + 1;
}




function startSc(scroller) {

    setInterval("scroller.scrollBy(-1, 0)" ,150);
//  setInterval("startSc2(scroller)" ,5000);
//  setInterval("stopSc(scroller)" ,6000);

}

function startSc2(scroller) {
    setInterval("scroller.scrollBy(-1, 0)" ,100);
    
    setTimeout("scroller.stopScroll(); clearInterval(window.intervalo);",500);

}

function stopSc(scroller,intervalo) {
    scroller.stopScroll()

}


function init() {
  var el = document.getElementById("scroll");
  scroller = new jsScroller(el, 668, 79);
  setInterval(slide_show_handler, 5000);
/*
var intervalo = window.setInterval(function() {
//<funcao>
}, 50);
window.setTimeout(function() {
clearInterval(intervalo);
}, 3000);
*/

    setTimeout("startSc(scroller)",10000);

//  setInterval("scroller.scrollBy(-2, 0)" ,100);
//  setInterval("scroller.stopScroll",5200);

//  setTimeout(scroller.autoStop(-5, 0),2000);
}
