//Função variáveis
// Read a page's GET URL variables and return them as an associative array.
var $a = jQuery.noConflict()
var $b = jQuery.noConflict()



function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


// Carousel Gustavo Ferraz




//function carrousel 
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

//Jquery index banner
$a(document).ready(function() {
    $a('#mycarousel').jcarousel({
        auto: 7,
        wrap: 'last',
        initCallback: mycarousel_initCallback

    });
});

// Carroucel index fornecedores
$a(document).ready(function() {
    $a('#mycarousel2').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

//arccodion by Gustavo Ferraz
$a(function() {
  $a( "#accordion" ).accordion({
    collapsible : true,
    active: numeroAc
  });
});

// sistema de abas - by Gustavo Ferraz
$a(document).ready(function(){
  //pega a variável da url
  var first = getUrlVars()["cadastro"];
  var seccond = getUrlVars();
  
  var teste = seccond.toString().split("/");
  
  if(first == 'fornecedores'){
    var aberto = '#cadastro-fornecedores';
    var aba = "#nav-aba li:nth-child(2) a"
  } else if (teste[teste.length-1] == '#wpcf7-f4-p93-o1') {
	  var aberto = '#cadastro-fornecedores';
	  var aba = "#nav-aba li:nth-child(2) a";
  } else {
    var aberto = '#cadastro-revenda';
    var aba = "#nav-aba li a:first"
  }
  
  $a(aberto).show();
  $a(aba).addClass('currenti');
  
  $a("#nav-aba li a").click(function(){
  $a(".aba").hide();
  var div = jQuery(this).attr('href');
  $a(div).show();

  $a(div).fadeIn(""); // faz a div correspondente clicada ficar visivel
    $a("#nav-aba li a").removeClass('currenti'); // remove a class no link clicado para que nao fica marcado
    $a(this).addClass('currenti'); // adiciona a classe no link clicado para que o usuario saiba em qual link ele esta    
    
  return false;
  });
});
// News letter

      $a(document).ready(function(){
        $a("#cadastra-news").validate({
          // Define as regras
          rules:{
               nome_cadastro:{
              required: true
            },
            email_cadastro:{
              required: true,
              email: true
            }
          },
          // Define as mensagens de erro para cada regra
          messages:{
            nome_cadastro:{
              required: "Você deve Digitar seu nome"
            },
            email_cadastro:{
             // required: "Você deve Digitar seu email",
              email: "Email Inválido"
            }
          }
        });
      })
      

// COLOR BOX

    $a(document).ready(function(){
      //Examples of how to assign the ColorBox event to elements
      $a("a[rel='example1']").colorbox();
      $a("a[rel='example2']").colorbox({transition:"fade"});
      $a("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
      $a("a[rel='example4']").colorbox({slideshow:true});
      $a(".example5").colorbox();
      $a(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
      $a(".example7").colorbox({width:"80%", height:"80%", iframe:true});
      $a(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
      $a(".example9").colorbox({
        onOpen:function(){ alert('onOpen: colorbox is about to open'); },
        onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
        onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
        onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
        onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
      });
      
      //Example of preserving a JavaScript event for inline calls.
      $a("#click").click(function(){ 
        $a('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
        return false;
      });
    });
    
    

