/* Author: Eliseu M

*/

var Site = function () {
	
	/* EQUAL HEIGHT */
	(function($){$.fn.equalHeight=function(step){tallest=0;this.each(function(){thisHeight=$(this).height();if(thisHeight>tallest)tallest=thisHeight});this.each(function(){$(this).height(tallest)})}})(jQuery);
	
	/* 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,{}));
	
	return {
		
		initCommon: function () {
			 $("input[placeholder], textarea[placeholder]").trigger("blur.placeholder");

			/* Quirks Mode Msg */
		    if (document.compatMode != 'CSS1Compat') {
		        $("body").prepend("<div style='position:absolute;width:100%;text-align:center;background:red;color: white;z-index: 999'>Seu navegador est&aacute; operando de modo diferente do padr&atilde;o. Desative o <em>Quirks Mode</em>.</div>");
		    }
			
			$('form').find('select.selectbox').customStyle({
				spanClass		: 'selectbox1',
				spanClassInner	: 'selectboxInner1'
			}).end()
			.find('input:radio, input:checkbox').ezMark().end()
			.find('input:text').setMask().end();
			
			/* Accordion Menu */
			$('ul.accordion a').click(function () {
				var checkElement = $(this).next();
				if ((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					checkElement.slideUp('normal');
					return false;
				}
				if ((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('ul.accordion').find('ul:visible').slideUp('slow');
					checkElement.slideDown('normal');
					return false;
				}
			});
			 /* 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)
      });
			
		},
		
		initHome: function () {
      Site.initCommon();
      
			$("#searchbox").hide();
      $(".select").removeClass("select").addClass("selectHome");
      $(".selectbox").removeClass("selectbox").addClass("selectboxHome")
      $(".styleSelect").removeClass("selectbox1").addClass("selectboxHome");
      
			
			/* Mais Imoveis Faux Columns */
			$("div.fullContent div.box").equalHeight();
			$("div.box a").bigTarget({
				hoverClass: 'bigTarget',
				clickZone: 'div.box'
			});
			
			$("#destaque").carouFredSel({
				visible: 2,
				prev: {
					button: "#destaque_prev",
					items: 2
				},
				next: {
					button: "#destaque_next",
					items: 1
				},
				auto: {
					play: false
				},
				height: 410,
				circular: false,
				infinite: false
			});
     
      $("#slider-home").carouFredSel({
				items 		: 1,
				direction	: "up",
				scroll: {
				fx			: "crossfade"
				},
				auto : {
					pauseOnHover: true
				}
			}).find(".slide").hover(
				function() { $(this).find("div").slideDown() },
				function() { $(this).find("div").slideUp();	}
			);
			
			
		},
		
		initDetails: function () {
			
			Site.initCommon();


			$("#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
			});
		}
		
	}
	
}();


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);
}
