//Funcoes armazenadas apos carregamento da pagina
$(function(){

  //----------------------------------------------------------------
  // Produtos recomendados
  //----------------------------------------------------------------
  //Slide
  $('#slider3')
	.anythingSlider({
    width            : '100%',          // Override the default CSS width
    height           : '100%',          // Override the default CSS height
    resizeContents   : false,           // If true, solitary images/objects in the panel will expand to fit the viewport
		startStopped     : true,            // If autoPlay is on, this can force it to start stopped

    // Navigation
    hashTags         : true,            // Should links change the hashtag in the URL?
    buildArrows      : true,            // If true, builds the forwards and backwards buttons
    buildNavigation  : false,           // If true, buildsa list of anchor links to link to each panel

    // Slideshow options
    hashTags         : true,            // Should links change the hashtag in the URL?
    pauseOnHover     : true,            // If true & the slideshow is active, the slideshow will pause on hover
    resumeOnVideoEnd : true,            // If true & the slideshow is active & a youtube video is playing, it will pause the autoplay until the video has completed
    stopAtEnd        : false,           // If true & the slideshow is active, the slideshow will stop on the last page
    playRtl          : false,           // If true, the slideshow will move right-to-left
    startText        : "Iniciar Slide", // Start button text
    stopText         : "Para Slide",    // Stop button text
    delay            : 3000,            // How long between slideshow transitions in AutoPlay mode (in milliseconds)
    animationTime    : 600,             // How long the slideshow transition takes (in milliseconds)
    easing           : "swing"          // Anything other than "linear" or "swing" requires the easing plugin
	});

  //----------------------------------------------------------------
  // Busca
  //----------------------------------------------------------------
  //Botao de busca assume o envio (submit) do formulario
  $('#busca_btn').click(function(){
    $('#form_busca').submit();
  });

  $("#busca_txt").focus(function(){
    if ("Buscar..." == $(this).val()) $(this).val("");
  }).blur(function(){
    if ("" == $(this).val().trim()) $(this).val("Buscar...");
  });


  //Balao de informacoes nos links [Requer o plugin: "jquery.qtip"]
  $('.balao[title], a[title]').qtip({
    position: {
      my      : 'bottom left',
      target  : 'mouse',
      viewport: $(window),
      adjust  : { x:0, y:-10 }
    }
  });
});

//Metodo para aceitar apenas: backspace, tab, delete, setas <- e ->, numeros e por erro "%"
jQuery.fn.soNumeros = function(){
  return this.each(function(){
    $(this).bind('keydown keypress keyup',function(e){
      var key = e.charCode || e.keyCode || 0;
      
//      alert(key);
      return (key==8||key==9||key==46||key==35||key==36||key==37||key==39||(key>=48&&key<=57)||(key>=96&&key<=105));
    })
  })
}

//Metodo para verificar se o elemento existe
jQuery.fn.existe = function(){
  return jQuery(this).length > 0;
}

//Funcao para rolar a pagina ate a posicao do obj ou topo da pagina
function rolaPagina(obj){
  $('html, body').animate({ scrollTop: $(obj).existe() ? $(obj).offset().top : 0 }, 1000);
}

