jQuery(function(){
	// Ciclo de destaques
	jQuery('#destaque').cycle({
		fx:			'fade',
		timeout: 6000,
		delay:	 -2000,
		cleartype:	1, // enable cleartype corrections
		pager:	 '.navNumber'
	});

  // Resolução
  /*
  if( screen.width <= 640 )
  {
      jQuery( '#content' ).css( 'width', '620px' );
  }
  else if( screen.width <= 800 )
  {
        jQuery( '#content' ).css( 'width', '770px' );
    jQuery( '#header' ).css( 'background', 'url(img/bg/topo_800.jpg) repeat-x 0 0' );
    jQuery( '.blocos800' ).css( 'width', '217px' );
    jQuery( '#listMenuRoot' ).css( 'font-size', '11px' );
  }
  else if( screen.width <= 1024 )
  {
      jQuery( '#content' ).css( 'width', '900px' );
  }


  // Sombra nos comentários
  jQuery(".commentlist li").dropShadow({
    top:2,
    left:2,
    blur:3,
    opacity:0.2
  });*/

  // Limitar Caracteres
  jQuery('#participe').keyup(function(){
    limitChars('comment', 250, 'comment_limit');
    limitChars('sender_message', 250, 'question_limit');
  });

  // Aumentar e diminuir tamanho das letras
  jQuery('.diminuirFonte').hide();
  jQuery(".aumentarFonte a").click(function(){
    jQuery('#sort1 , #sort2 , #sort3').css('font-size', '15px');
    jQuery('.diminuirFonte').show();
    jQuery('.aumentarFonte').hide();

    return false;
  });
  jQuery(".diminuirFonte a").click(function(){
    jQuery('#sort1 , #sort2 , #sort3').css('font-size', '13px');
    jQuery('.aumentarFonte').show();
    jQuery('.diminuirFonte').hide();

    return false;
  });

  // Aba comentarios e Perguntas
  jQuery(".enviarPergunta .updated").parent().each(function(){
    jQuery('.titlePergunta').addClass('active');
    jQuery('.titleComentarios').removeClass('active');
    jQuery('.formComentarios').hide();
    jQuery('.enviarPergunta').show();
  });

  jQuery(".titleComentarios a").click(function(){
    jQuery('.titleComentarios').addClass('active');
    jQuery('.titlePergunta').removeClass('active');
    jQuery('.enviarPergunta').hide();
    jQuery('.formComentarios').show();

    return false;
  });
  jQuery(".titlePergunta a").click(function(){
    jQuery('.titlePergunta').addClass('active');
    jQuery('.titleComentarios').removeClass('active');
    jQuery('.formComentarios').hide();
    jQuery('.enviarPergunta').show();

    return false;
  });

  // Primeiro li sem borda
  jQuery('.grupoItem ul li:first-child').addClass('semBorda');
});

// function Voltar ao Topo
function backToTop()
{
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;

  if(document.documentElement)
  {
    x1 = document.documentElement.scrollLeft || 0;
    y1 = document.documentElement.scrollTop || 0;
  }

  if(document.body)
  {
    x2 = document.body.scrollLeft || 0;
    y2 = document.body.scrollTop || 0;
  }

  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;

  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));

  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

  if(x > 0 || y > 0)
  {
    window.setTimeout("backToTop()", 25);
  }
}

// function Limitar Caracteres
function limitChars(textid, limit, infodiv)
{
  var text = jQuery('#'+textid).val();
  var textlength = text.length;
  if(textlength > limit)
  {
    jQuery('#'+infodiv).html('(<strong>Voc&ecirc; n&atilde;o pode escrever mais de '+limit+' caracteres!</strong>)');
    jQuery('#'+textid).val(text.substr(0,limit));
    return false;
  }
  else
  {
    jQuery('#' + infodiv).html('('+ (limit - textlength) +' caracteres restantes)');
    return true;
  }
}

