$(document).ready(function()
{
  //remove ouline (dotted border)
  $('input[type="radio"], input[type="checkbox"], input[type="button"]').focus(function(){
    $(this).blur();
  });
  
   //init jquery menu
  $(function(){
  	$('ul.sf-menu').superfish({
      speed:100,
      animation: {height:'show'},
  		delay:100,
  		multiColumn:5,
  		multiColumnWidth:150,
  		autoArrows: false
    });
  });

  //init jquery lightbox
  var $lightbox=$('a[rel*=lightbox]');
  if($lightbox.length>0)
    $lightbox.lightBox(); // Select all links that contains lightbox in the attribute rel

  //init jquery video
  var $vidbox=$('.vidbox');
  if($vidbox.length>0)
    $vidbox.jqvideobox();

  //slideshow
  var $slideshow=$('#slideshow');
  if($('#slideshow').length>0){

    //ROLHA: O CHROME NÃO DEVOLVE AS ALTURAS CORRETAS.......
    var slideshowHeight='385px'; //$slideshow.css('height');
    var slideTextHeight='100px'; //$('.slideText',$slideshow).css('height');

    $slideshow.cycle({
        containerResize:0, //as dimensões do plugin são fixas, não queremos que o cycle mexa nelas

        fx:     'fade',

        speed:  'fast',

        timeout: 5000,

        pager:  '#nav',

        pagerAnchorBuilder: function(idx, slide) {
          return '#nav li:eq(' + idx + ') a'; // return selector string for existing anchor
        },

        before: function(currSlideElement, nextSlideElement, options, forwardFlag){
          $('.slideText',$(this)).css('margin-top',slideshowHeight); //reset margin-top: set slideText margin to parent height so it becomes 'hidden'
        },

        after: function(currSlideElement, nextSlideElement, options, forwardFlag){
          $('.slideText',$(this)).animate({"margin-top": "-="+slideTextHeight}, function(){  }); //slide up effect: decreasing the margin-top to the slideText height
        }

    }).hover(function(e) {
        $slideshow.cycle('toggle');
    });
  }

  var $btnVoltar=$('#btBack');
  $('#btBack').click(function(){
    var tipo=$('#btBack').attr('tipo');
    var page=$('#btBack').attr('numpage');

    window.location.replace("/"+tipo+"/pagina/"+page+"/");
    
  });
  
  var $webviewer=$('#frameWebViewer');
  $webviewer.addClass('hidden');
  if($webviewer.length>0){
    $webviewer.load(function () {
      //$webviewer.contents().find("img[src='/DealerLogos/LOGO SISMASTER cinza.jpg']").hide();
      $webviewer.removeClass('hidden');
   });
  }
  
  //Solicitar contacto
  $('#btSolicitarContacto').click(function(){
    var tipo=$('#btSolicitarContacto').attr('tipo');
    var contentId=$('#btSolicitarContacto').attr('content_id');

    window.location.replace("/solicitarContacto/"+tipo+"/"+contentId+"/");

  });
  
  $('#formSolicitarContacto #limpar').click(function(){

    $('form#formSolicitarContacto input[type="text"]').each(function(index){
            $(this).val('');
    });
    
    $('form#formSolicitarContacto input[type="checkbox"]').each(function(index){
            $(this).attr('checked', false);
    });
    
  });
  
  //Pedido de proposta
  $('#btPedirProposta').click(function(){
    var tipo=$('#btPedirProposta').attr('tipo');
    var contentId=$('#btPedirProposta').attr('content_id');

    window.location.replace("/pedidoProposta/"+tipo+"/"+contentId+"/");

  });
  
  $('#formProposta #limpar').click(function(){

    $('form#formProposta input[type="text"], form#formProposta textarea').each(function(index){
            $(this).val('');
    });

    $('form#formProposta input[type="checkbox"]').each(function(index){
            $(this).attr('checked', false);
    });

    $('form#formProposta #tipoSol option[value=""]').attr('selected', true);

  });
  
  $('#btVoltarServicoParent').click(function(){
    var servico_id=$(this).attr('servico_id');
    var pagina=$(this).attr('pagina');

    window.location.replace("/servicos/"+servico_id+"/"+pagina+"/");
    
  });
  
});







