/* Author: 

*/

/* EQUAL HEIGHT */
(function($){
  $.fn.equalHeight=function(){
    tallest=0;
    this.each(function(){
      thisHeight=$(this).height();
      if(thisHeight>tallest)tallest=thisHeight
    });
    this.each(function(){
      $(this).height(tallest)
    })
  }
})(jQuery);
/*$("li.item").equalHeight();*/
/* BIG TARGET */
/*http://newism.com.au/blog/post/58/bigtarget-js-increasing-the-size-of-clickable-targets/*/

eval(function(p,a,c,k,e,r){
  e=function(c){
    return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))
    };
    
  if(!''.replace(/^/,String)){
    while(c--)r[e(c)]=k[c]||e(c);
    k=[function(e){
      return r[e]
      }];
    e=function(){
      return'\\w+'
      };
      
    c=1
    };
  while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);
  return p
  }('(3($){$.k.l=3(d){4 e=$.r({},$.k.l.u,d);5 g.K(3(){4 a=$(g);4 b=a.9(\'J\');4 c=a.9(\'1\');4 o=$.H?$.r({},e,a.F()):e;a.C(o.m).n(3(){$h=$(g);$h.y(o.j);2(s o.1!=\'q\'&&o.1===i&&c!=\'\'){$h.9(\'1\',c)}},3(){$h.w(o.j);2(s o.1!=\'q\'&&o.1===i&&c!=\'\'){$h.G(\'1\')}}).x(3(){2(p()==""){2(a.z(\'[A*=B]\')){8.D(b);5 E}f{8.v=b}}})})};3 p(){2(8.7){5 8.7().I()}f 2(6.7){5 6.7()}f 2(6.t){5 6.t.L().M}};$.k.l.u={j:\'n\',m:\'N:O(0)\',1:i}})(P);',52,52,'|title|if|function|var|return|document|getSelection|window|attr||||||else|this||true|hoverClass|fn|bigTarget|clickZone|hover||getSelectedText|undefined|extend|typeof|selection|defaults|location|removeClass|click|addClass|is|rel|external|parents|open|false|data|removeAttr|meta|toString|href|each|createRange|text|li|eq|jQuery'.split('|'),0,{}));

(function(a){
  a.fn.placeholderEnhanced=function(){
    var d="placeholder",b=d in document.createElement("input");
    if(!b){
      a("form").submit(function(){
        var c=a(this);
        c.find("input[placeholder],textarea[placeholder]").each(function(){
          var f=a(this);
          if(f.val()===f.attr("placeholder")){
            f.val("")
            }
          })
      })
    }
    return this.each(function(){
    var j=a(this),k=j.attr("placeholder"),l=j.attr("type")==="password";
    var h=function(){
      if(j.hasClass(d)){
        if(!b){
          j.val("")
          }
          j.removeClass(d)
        }
      };
    
  var c=function(e,n){
    if(!j.val()||n){
      if(!b){
        if(!l){
          j.addClass(d).val(k)
          }else{
          i(f);
          m(j)
          }
        }else{
      j.addClass(d)
      }
    }
  };

var m=function(n){
  n.css({
    position:"absolute",
    left:"-9999em"
  })
  };
  
var i=function(n){
  return n.removeAttr("style")
  };
  
if(!l||b){
  j.bind("focus.placeholder",h)
  }else{
  var g=(j[0].className)?" "+j[0].className:"";
  var f=a('<input type="text" class="'+d+g+'" value="'+k+'" />');
  j.before(f);
  f.bind("focus.placeholder",function(){
    i(j).focus();
    m(f)
    })
  }
  j.bind("blur.placeholder",c).trigger("blur.placeholder",[true])
  })
};

a(function(){
  var b=a("input[placeholder],textarea[placeholder]");
  if(b.length){
    b.placeholderEnhanced()
    }
  })
})(jQuery);


var Site = function () {

  return {

    initCommon: function () {
		
      $('select.selectbox').customStyle({
        spanClass: 'styleSelect1',
        spanClassInner: 'styleSelectInner1'
      });

      /* SOCIAL ANIMATE ICONS */
      $('#social a').hover(function () {
        $(this).css('position', 'relative');
        $(this).stop().animate({
          top: '-6px'
        }, 200)
      }, function () {
        $(this).animate({
          top: '0', 
          marginBottom: '0', 
          paddingBottom: '0'
        }, 100);
      });
         
      $(".box a").bigTarget({
        hoverClass: 'bigTarget',
        clickZone: 'li.box'
      });
      $(".item a").bigTarget({
        hoverClass: 'hover',
        clickZone: 'div:eq(0)' 
      });
		
    },
		
    initHome: function () {
      Site.initCommon();
      $('.html_carousel').attr("style", "display:block");
      $('#buscaLateral').attr('style','width:230px')
            
      $('.sombra-pesquisa').show()
            
      $("#homeCar").carouFredSel({
        items 		: 1,
        direction	: "up",
        scroll: {
          fx			: "crossfade"
        },
        auto : {
          pauseOnHover: true
        }
      }).find(".slide").hover(
        function() {
          $(this).find("div").slideDown()
        },
        function() {
          $(this).find("div").slideUp();
        }
        );

      $("#destaque").carouFredSel({
        visible: 4,
        prev: {
          button: "#destaque_prev",
          items: 3
        },
        next: {
          button: "#destaque_next",
          items: 3
        },
        auto: {
          play: false
        },
        height: 300,
        circular: false,
        infinite: false
      });
      $(".select").addClass("selectHome").removeClass("select")
      $(".styleSelect1").addClass("styleSelectHome").removeClass("styleSelect1");
      $(".selectbox").addClass("selectboxHome").removeClass("selectbox")
        
    //console.timeEnd('maoe');
		
    },
		
    initSearch: function () {
      Site.initCommon();
      
      /*$("a.video").click(function() {
        alert("51");
        $.fancybox({
          'padding'       : 0,
          'autoScale'     : false,
          'transitionIn'  : 'none',
          'transitionOut' : 'none',
          'title'         : this.title,
          'width'         : 640,
          'height'        : 385,
          'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
          'type'          : 'swf',
          'swf'           : {
            'wmode'             : 'transparent',
            'allowfullscreen'   : 'true'
          }
        });
        return false;
      });*/
		
    },
		
    initDetalhes: function () {
			
      /* this.initCommon();
		
            $("#galeriaDetalhes").carouFredSel({
				visible: 16,
				pagination: "#galeriaPagination",
				auto: {
					play: false
				},
				height: 'auto',
				circular: false,
				infinite: false
			});*/
$(".video").click(function() {
	        $.fancybox({
	            'padding'       : 0,
	            'autoScale'     : false,
	            'transitionIn'  : 'none',
	            'transitionOut' : 'none',
	            'title'         : this.title,
	            'width'         : 640,
	            'height'        : 385,
	            'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
	            'type'          : 'swf',
	            'swf'           : {
	            'wmode'             : 'transparent',
	            'allowfullscreen'   : 'true'
	            }
	        });
	        return false;
	    });
      $("#galeriaDetalhes").carouFredSel({
        scroll		: 5,
        auto: false,
        pagination: "#galeriaPagination"
      });
			
      $("#carac").carouFredSel({
        visible: 4,
        prev: {
          button: "#carac_prev",
          items: 3
        },
        next: {
          button: "#carac_next",
          items: 3
        },
        auto: {
          play: false
        },
        height: 'auto',
        circular: false,
        infinite: false
      });

      $("a[rel*=fancybox]").click(function () {
        return false;
      }).fancybox({
        centerOnScroll: true
      });
            
      Site.initCommon();
    }
	
  }

}();

function reloadCombo(combo,url,first_opt,second_opt)
{
    $(combo).prop("disabled", true).parent().find(".styleSelect").removeClass("disabled").find("span").text("Carregando..");
    $.getJSON(encodeURI(url),function(response){
    var options = '';
    options += '<option value="-1">' + first_opt + '</option>';
    options += '<option value="-1">' + second_opt + '</option>';
    for (var i = 0; i < response.length; i++)
    {
        options += '<option value="' + response[i].value + '">' + response[i].label + '</option>';
    }
    $(combo).html(options);
    $(combo).prop("disabled", false).parent().find(".styleSelect").removeClass("disabled").find("span").text(first_opt);
    });
}

function clearDisableCombo(combo,first_opt)
{
    $(combo).prop("disabled", true).parent().find(".styleSelect").removeClass("disabled").find("span").text(first_opt);
    $(combo).val(-1);
}
