$(function(){
      $('.Telefone').mask('(99)9999-9999').each(function(){
            $(this).val($(this).attr('title'));
      });

      /**
       * Serviços
       */
      $('p.texto-destaque').each(function(){
            var altura = $(this).height();
            $(this).css({
                  height: altura
            });
      });
      $('.texto-destaque:not(:first)').hide();
      $('p.destaque').click(function(){
            var icone = $('span', this);

            if( icone.attr('class').indexOf('minus') != -1 )
            {
                  icone.attr('class', 'ui-icon ui-icon-plusthick');
                  $(this).next('.texto-destaque').slideUp(600);
//                  icone.attr('id', 'ui-plus');
//                  $(this).css({backgroundColor: '#fff', color: '#B51721'})
            }
            else
            {
                  icone.attr('class', 'ui-icon ui-icon-minusthick');
                  $(this).next('.texto-destaque').slideDown(600);
//                  icone.attr('id', 'ui-minus');
//                  $(this).css({backgroundColor: '#b51721', color: '#fff'})
            }

      });
      /**
       * Seta Menu
       */
      var page = window.location.href.split('/').reverse()[0];
      var array = new Array();
      array[''] = 40;
      array['index'] = 40;
      array['multclick'] = 157;
      array['servicos'] = 300;
      array['clientes'] = 430;
      array['contato'] = 565;
      
      $('#seta').css({
            left: array[page]
      });

      $('#main-menu a').mouseover(function(){
            var id = $(this).attr('href').split('/').reverse()[0];

            $('#seta').stop(true, false).animate({
                  left: array[id]
            }, 600);
      });
      $('#main-menu a').mouseout(function(){
            $('#seta').delay(1500).animate({
                  left: array[page]
            }, 1500);
      });

      /**
       * Textarea, Inputs
       */
      $('input,textarea').focus(function(){
            var valor = $(this).val();
            var title = $(this).attr('title');

            if(valor == title)
                  $(this).val('');

      });
      $('input,textarea').blur(function(){
            var valor = $(this).val();
            var title = $(this).attr('title');

            if ( valor == '' )
                  $(this).val(title);
      });

      /**
       * Index
       */
      if ( $('body#front').length )
      {
            $("#slideshow").easySlider({
                  pause: 4000,
                  speed: 1500,
                  auto: true,
                  continuous: true,
                  prevId: 'prev',
                  nextId: 'next',
                  controlsFade: true,
                  prevText: '',
                  nextText: ''
            });

            $.Juitter.start({
                  searchType:"searchWord", // needed, you can use "searchWord", "fromUser", "toUser"
                  searchObject:"multclick", // needed, you can insert a username here or a word to be searched for, if you wish multiple search, separate the words by comma.

                  // The values below will overwrite the ones on the Juitter default configuration.
                  // They are optional here.
                  // I'm changing here as a example only
                  lang:"pt-br", // restricts the search by the given language
                  live:"live-120", // the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates.
                  placeHolder:"twitter", // Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
                  loadMSG: "Carregando...", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on
                  imgName: "loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
                  total: 10, // number of tweets to be show - max 100
                  readMore: "Leia no Twitter", // read more message to be show after the tweet content
                  nameUser:"image", // insert "image" to show avatar of "text" to show the name of the user that sent the tweet
                  openExternalLinks:"newWindow", // here you can choose how to open link to external websites, "newWindow" or "sameWindow"
                  filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"  // insert the words you want to hide from the tweets followed by what you want to show instead example: "sex->censured" or "porn->BLOCKED WORD" you can define as many as you want, if you don't want to replace the word, simply remove it, just add the words you want separated like this "porn,sex,fuck"... Be aware that the tweets will still be showed, only the bad words will be removed
            });
      }

      /**
       * Cases Footer
       */
      $('#cases .left li:not(:first)').hide();
      $('#cases .right .descricao:not(:first)').hide();
      
      $('#cases .passa .next').click(function() {
            var visible = $('#cases .left li:visible');
            var next = visible.next('li');
            var first = $('#cases .left li:first');
            var texto = $('#'+visible.attr('class'));
            var t_next = texto.next('.descricao');
            var t_first = $('#cases .descricao:first');

            visible.stop(true,true).fadeOut(800);
            texto.stop(true,true).fadeOut(800,function(){
                  if(next.length)
                  {
                        next.stop(true,true).fadeIn(800);
                        t_next.stop(true,true).fadeIn(800);
                  }
                  else
                  {
                        first.stop(true,true).fadeIn(800);
                        t_first.stop(true,true).fadeIn(800);
                  }
            });

            return false;
      });

      $('#cases .passa .prev').click(function() {
            var visible = $('#cases .left li:visible');
            var prev = visible.prev('li');
            var last = $('#cases .left li:last');
            var texto = $('#'+visible.attr('class'));
            var t_prev = texto.prev('.descricao');
            var t_last = $('#cases .descricao:last');

            visible.stop(true,true).fadeOut(800);
            texto.stop(true,true).fadeOut(800,function(){
                  if(prev.length)
                  {
                        prev.stop(true,true).fadeIn(800);
                        t_prev.stop(true,true).fadeIn(800);
                  }
                  else
                  {
                        last.stop(true,true).fadeIn(800);
                        t_last.stop(true,true).fadeIn(800);
                  }
            });

            return false;
      });
      
  	$("a[rel=case_group]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic'
	});
    
    /* BUSCA */
      
  	$('#pesquisar-input').keyup(function(e) {
		if(e.keyCode == 13)
			busca();
	});
		
	$("#pesquisar-bt").click(function () {
		busca();
	});
	
});


/* BUSCA */
google.load("search", "1", {language: 'pt-br'});

function busca(){
	$("#google_search").dialog('open');
	
	var customSearchControl = new google.search.SearchControl();
	
    var webSearch = new google.search.WebSearch();
    customSearchControl.addSearcher(webSearch);
    customSearchControl.addSearcher(new google.search.NewsSearch());
	
	var drawOptions = new google.search.DrawOptions();
	drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
	customSearchControl.draw(document.getElementById("google_search"), drawOptions);
	customSearchControl.execute(document.getElementById("pesquisar-input").value);
	
	  $("#google_search").dialog({
		  	autoOpen: true,
		  	bgiframe: true,
			resizable: false,
			height:500,
			width: 400,
			modal: true,
			overlay: {
				backgroundColor: '#fff',
				opacity: 0.5
			}

		});
}
