// Biblioteca Javascript/JQuery

$(document).ready(function(){

  themeFolder = '/wp-content/themes/cambequip'; //Pasta do Tema ativo
  imgFolder = '/imgs'; //Pasta das Imagens
  cssFolder = '/css'; //Pasta do CSS
  scriptFolder = '/scripts'; //Pasta com os Scripts
  
  urlSite = 'http://'+document.location.hostname;
  templatePath = urlSite+themeFolder;
  imgPath = templatePath+imgFolder;
	
	// MENU
	activePage = $('div#content').attr('class');
  $('#nav > li.'+activePage).addClass('current');
	
	
	// SLIDE DO TOPO
	
	liSlide = $('div.slides > ul > li');	
	
	function playSlideNext(){
		
		liCur = $('div.slides > ul > li.current');
		
		if (liSlide.last().hasClass('current')) {		
		liCur.removeClass('current').fadeOut('slow', function(){
															liSlide.first().fadeIn().addClass('current');
															});
		} else {		
		liCur.fadeOut('slow', function(){
									   liCur.removeClass('current').next().fadeIn().addClass('current');
										});
		}
	}
	
	function playSlidePrev(){
		
		liCur = $('div.slides > ul > li.current');
		
		if (liSlide.first().hasClass('current')) {		
		liCur.removeClass('current').fadeOut('slow', function(){
															liSlide.last().fadeIn().addClass('current');
															});
		} else {		
		liCur.fadeOut('slow', function(){
									   liCur.removeClass('current').prev().fadeIn().addClass('current');
										});
		}
	}

	$('.next').live('click', function(){ playSlideNext(); });
	$('.prev').live('click', function(){ playSlidePrev(); });
	
	liSlide.first().addClass('current').fadeIn();
	
	
	// SLIDEUP DOS PRODUTOS
	$('.header_produto').hover(function(){ $(this).find('.titulo_produto').slideToggle('fast'); });
	
	
	// GOOGLE MAPS
	function gMaps(mapW, mapH, mapDiv){
    $(mapDiv).html('<iframe width="'+mapW+'" height="'+mapH+'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;q=Rod.+Celso+Garcia,+381+-+Jardim+Santo+Amaro,+Camb%C3%A9+-+Paran%C3%A1,+86185-520,+Brasil&amp;aq=&amp;ie=UTF8&amp;geocode=FWqinP4drzfy_A&amp;split=0&amp;hq=&amp;hnear=Rod.+Celso+Garcia,+381+-+Camb%C3%A9+-+Paran%C3%A1,+86185-520,+Brasil&amp;t=m&amp;z=14&amp;vpsrc=0&amp;ll=-23.289238,-51.234897&amp;output=embed"></iframe>');
  }
	
	gMaps(330, 200, '.home .map');
	gMaps(870, 360, '.mapa .map');
	
	// FORM DE CONTATO
	    swapValue = [];
    $(".swap-value").each(function(i){
    swapValue[i] = $(this).val();
    $(this).focus(function(){
    if ($(this).val() == swapValue[i]) {
    $(this).val("");
	$(this).addClass('focus');
    }
    $(this).addClass('focus');
    }).blur(function(){
    if ($.trim($(this).val()) == "") {
    $(this).val(swapValue[i]);
    $(this).removeClass('focus');
    }
    });
    });
    $('#telefone').mask('(99) 9999-9999');
	
	// HOVER DE IMAGEM
	
    $('#facebook img.imgHover').mouseover(function() {$(this).attr('src', imgPath+'/facebook_icon_hover.png');}).mouseout(function() {$(this).attr('src', imgPath+'/facebook_icon.png');});
    $('#twitter img.imgHover').mouseover(function() {$(this).attr('src', imgPath+'/twitter_icon_hover.png');}).mouseout(function() {$(this).attr('src', imgPath+'/twitter_icon.png');});
    $('#youtube img.imgHover').mouseover(function() {$(this).attr('src', imgPath+'/youtube_icon_hover.png');}).mouseout(function() {$(this).attr('src', imgPath+'/youtube_icon.png');});
	
	// TOGGLE DO RESPONSABILIDADE SOCIAL
	function open(divO, hO, hC){
    if ($(divO).is('.closed')){
      $(divO).animate({
        height: hO+'px'
      }).removeClass('closed').addClass('opened');
    } else if ($(divO).is('.opened')){
      $(divO).animate({
        height: hC+'px'
      }, 1000, 'easeOutBounce').addClass('closed').removeClass('opened');   
  }
  }
  
  $('#resp_ambiente_titulo > h3').toggle(function(){
  hO = 250; //altura da div aberta
  hC = 40; //altura da div fechada
  divO = '#resp_ambiente'; //#id da div  
    open(divO, hO, hC);
    $(this).parent().css('background-image','url('+imgPath+'/resp_ambiente_titulo_opened.png)');
  }, function(){
    open(divO, hO, hC);
    $(this).parent().css('background-image','url('+imgPath+'/resp_ambiente_titulo.png)')
  });
  
  $('#resp_ambiente_titulo > h3').hover(function(){
    if ($('#resp_ambiente').is('.closed')){
      $('#resp_ambiente_titulo > h3').css('background-image','url('+imgPath+'/resp_ambiente_titulo_hover.png)');
    } else if ($('#resp_ambiente').is('.opened')){
      $('#resp_ambiente_titulo > h3').css('background-image','url('+imgPath+'/resp_ambiente_titulo_opened_hover.png)');
    }
  }, function(){
    if ($('#resp_ambiente').is('.closed')){
      $('#resp_ambiente_titulo > h3').css('background-image','url('+imgPath+'/resp_ambiente_titulo.png)');
    } else if ($('#resp_ambiente').is('.opened')){
      $('#resp_ambiente_titulo > h3').css('background-image','url('+imgPath+'/resp_ambiente_titulo_opened.png)');
    }  
  });
  
  // ROUND CORNERS
  $('.corner').corner();
  
  // BOOK SPIRAL
  spiralH = $('.book').height()+40;
  $('.book_spiral').css('height',spiralH);
  
	// AJAX DOS PRODUTOS - SERVIÇOS
  $.ajaxSetup({cache:false});
	$("div.book ul li a").click(function(){
		
    var post_id = $(this).attr('rel')
		$("#abre_post").html('<img class="loader" alt="loading" src="'+imgPath+'/loader.gif" />');
		$("#abre_post").load('/produtos-e-servicos/',{id:post_id});
		$("body").scrollTop(400);
    return false;
	});
  
  // AJAX DOS FORMULÁRIOS DE CONTATO
        $(".resposta").ajaxStart(function(){
            $(this).html("Mensagem sendo enviada, por favor aguarde..."); });
            $('#submit').click(function() {
                var assunto     = $('#assunto').val();
                var nome     = $('#nome').val();
                var email    = $('#email').val();
                var telefone    = $('#telefone').val();
                var msg = $('#msg').val();
                $.post(templatePath+'/contato1.php',
                    { assunto: assunto, nome: nome, email: email, telefone: telefone, msg: msg },
                    function(data, textStatus) {
                        $('.resposta').html(data);
                        $('#contato').each (function(){ this.reset(); });
                });
            return false;
        });
        
        
        //VALIDAÇÃO ANEXO
            

});
