$(document).ready(function(){
    $('#divLogin').load('login.php');
    $('#boxEnqueteHome').load('enquete.php');
 
    $('#divModalErro').dialog({ autoOpen: false, title: 'Erro!', modal: true, closeText: 'Fechar',buttons: { "Retornar ao Formulário": function() { $(this).dialog("close"); } }});
    $('#divModal').dialog({ autoOpen: true, modal: true, closeText: 'Fechar', buttons: { "Fechar": function() { $(this).dialog("close"); } }});
    $('#divModal2').dialog({ autoOpen: false, modal: true, closeText: 'Fechar', buttons: { "Fechar": function() { $(this).dialog("close"); } }});
 
 
        $('#divCarrossel').jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
      
 
    hTimeoutCarrossel=setInterval(function() {         
                 myCarousel.next();
           return false;
          }, 5000);
 
 
    $("#divLoadingBars").ajaxStart(function(){ $(this).fadeIn()})
                     .ajaxStop(function(){ $(this).fadeOut()})
                     .ajaxComplete(function(){ $(this).fadeOut()})
                     .ajaxError(function(){ $(this).fadeOut()});
 
    $(window).resize(jsResize);
    jsResize();
 
    if (location.hash.length==0) {
      jsCarregaPagina('indexCentro.php');
    }
 
    $.historyInit(jsCarregaPagina);
  });
 
 
  function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, 20);
    carousel.add(i, $('#divCarrossel_'+(idx-1)).html());
  };
 
  function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {
    carousel.remove(i);
  };
 
  var myCarousel;
  function mycarousel_initCallback(carousel) {
    myCarousel=carousel;
    $('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
 
    $('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
  }
 
  function jsCarrosselIE6(iIncremento) {
    iIndiceCarrossel+=iIncremento;
 
    if (iIndiceCarrossel<0) iIndiceCarrossel=19;
    else if (iIndiceCarrossel>=20) iIndiceCarrossel=0;
 
    iIndice1=iIndiceCarrossel; 
    iIndice2=iIndiceCarrossel+1; 
    if (iIndice2==20) iIndice2=0;
 
    iIndice3=iIndiceCarrossel+2; 
    if (iIndice3==20) iIndice3=0;
    if (iIndice3==21) iIndice3=1;
 
    $('#divCarrossel').html($('#divCarrossel_'+iIndice1).html()+$('#divCarrossel_'+iIndice2).html()+$('#divCarrossel_'+iIndice3).html());
    $('#divCarrossel li').addClass('jcarousel-item');
  }
 
 
 
  function jsResize() {
    $('#divLoadingBars').css({'left':Math.round(($(document).width()/2)-16), 'top':Math.round(($(document).height()/2)-16)});
  }
 
  hTimeOutTv=false;
  function jsCarregaPagina(sURL) {
    if (sURL!="") {
      if (sURL!="indexCentro.php") {
        $('#divCarrosselHolder').hide();
        if (typeof(hTimeoutCarrossel)!='undefined') {
          clearInterval(hTimeoutCarrossel);
        }
 
        if (hTimeOutTv) clearTimeout(hTimeOutTv);
        if (!$('#divCentro').hasClass('interno')) $('#divCentro').addClass('interno');
      }    
      else {
        $('#divCarrosselHolder').show();
        $('#divCarrosselHolder').show();
        hTimeoutCarrossel=setInterval(function() { 
                   myCarousel.next();
            return false;
               },5000);
      }
      
      if ((sURL!='premioDetalhe.php')&&(sURL!='premios.php')) {
        $('#divCentro').load(sURL,'',function(){  
          window.scrollTo(0,0); 
        });
      }
    }
    return false;
  }
 
  function jsLinkTopo(sPagina,hLi) {
    $('#nav li').removeClass('active');
    $('#'+hLi).addClass('active');
    $.historyLoad(sPagina);
  }
