/*

function mapa_imovel(l1,l2,tipo,controles,mapid) {
	if ( tipo === undefined ) tipo = 'ponto';
	if ( controles === undefined ) controles = true;
	if ( mapid === undefined ) mapid = "map";
	if ($("#"+mapid).length>0) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById(mapid));
			map.setCenter(new GLatLng(l1,l2), 15);
			var latlng = new GLatLng(l1,l2);
			if (controles) {
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
			}
			if (tipo=='circulo') {
				var marcador = GPolygon.Circle(latlng, 500,"#666",2,1,"#000",0.2)
				map.addOverlay(marcador);
			} else {
				var icone = new GIcon(G_DEFAULT_ICON);
				icone.image = "img/design/icon_gmap.png";
				icone.iconSize = new GSize(23, 33);
				markerOptions = { icon:icone };
				map.addOverlay(new GMarker(latlng, markerOptions));
				//map.addOverlay(new GMarker(latlng));
			}
		}
	}
}
*/


	function add_fav(imovel){
		 $.get("inc/lib/fnc_favoritos.php?act=add_imo", {addid: imovel},
			function(data){
				alert(data);
			})
	}

	function del_fav(imovel){
		 $.get("inc/lib/fnc_favoritos.php?act=del_imo", {delid: imovel},				
			function(data){
				alert(data);
				window.location='favoritos.php';
			})
		 //window.location='inc/lib/fnc_favoritos.php?act=del_imo&delid='+imovel;
	}

	function clear(){
		 $.get("inc/lib/fnc_favoritos.php?act=limpatudo", {delid: imovel},
			function(data){
				alert(data);
			})
	}

function carregaBairros() {
	var tipo = $('#tipo').val();
	$(".bairros").load("inc/lib/fnc_load-busca.php?act=bairros", {tipo: tipo})			
}	

$(document).ready(function(){
	
	//mais vistos
	var ir = 0;
	$(".roll").each(function(){
		ir++; var id = "roll-"+ir;
		$(this).attr("id",id);
		var lis = $(this).find(".mv-imoveis .imovel");
		for (var i = 0; i < lis.length; i+=5) { lis.slice(i, i+5).wrapAll('<div class="set"></div>'); }
		$(this).find(".mv-imoveis").after('<div class="abas-nav"><a href="#" class="btn p">P</a><a href="#" class="btn n">N</a></div>');
		$(this).find(".mv-imoveis").cycle({
			fx:		'scrollHorz',
			prev:	'#'+id+' a.p',
			next:	'#'+id+' a.n',
			pauseOnPagerHover: true,
			pause:	true
			//timeout: 0
		});
	});	
	
	carregaBairros();
	$("#tipo").change(function(){ carregaBairros(); });	
	
	//tooltips
	if ($(".tooltip").length>0) {
		$(".tooltip").tooltip({ 
			track: true, 
			delay: 0, 
			showURL: false, 
			showBody: " - ", 
			fade: 250 
		});
	}
	
	//enviar para
	if ($("#enviar-por-email").length>0) {
		$("#enviar-por-email").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 140,
			modal: true,
			width: 330,
			resizable: false
		});
		$(".abre_enviar").click(function(){
			$("#enviar-por-email").dialog('open');
			return false;
		});
	}
	
	//youtube
	if ($("#video").length>0) {
		$("#video").dialog({
			autoOpen: false,
			bgiframe: true,
			minHeight: 340,
			modal: true,
			width: 560,
			resizable: false
		});
		$(".abre_youtube").click(function(){
			$("#video").dialog('open');
			return false;
		});
	}
	
	//busca da esquerda
	$("#leftContent #encontre .pesquisar").focus(function(){
		if ($(this).val()=='Pesquisar...') $(this).val("");
	});
	$("#leftContent #encontre .pesquisar").blur(function(){
		if ($(this).val()=='') $(this).val("Pesquisar...");
	});
	$("#leftContent #encontre form").submit(function(){
		p = $(this).find(".pesquisar");
		if (p.val()=='Pesquisar...') p.val("");
		return true;
	});
	
	//home tabs
	$("#homeTab #homeTabMenu a:first").addClass("active");
	$("#homeTab #homeTabContent .content:first").show();
	$("#homeTab #homeTabMenu a").click(function(){
		if (!$(this).hasClass("active")) {
			$("#homeTab #homeTabMenu a.active").removeClass("active");
			$(this).addClass("active");
			id = $(this).attr("href");
			$("#homeTab #homeTabContent .content").hide();
			$(id).show();
		}
		return false;
	});
	$("#homeTab #homeTabContent .imovel-info p, #homeTab #homeTabContent .imovel-info h4").css("cursor","pointer");
	$("#homeTab #homeTabContent .imovel-info p, #homeTab #homeTabContent .imovel-info h4").click(function(){
		lnk = $(this).parents(".imovel").find(".imovel-foto a").attr("href");
		window.location = lnk;
	});
	$("#homeTab #homeTabContent .imovel-info a.info").hover(function(){
		$(this).parents(".imovel").find(".imovel-foto img").addClass("borda-amarela");
	},function(){
		$(this).parents(".imovel").find(".imovel-foto img").removeClass("borda-amarela");
	});
	
	//twitter
	if ($("#twitter").length>0) {
		$("#twitter").getTwitter({
			userName: "c21milanez",
			numTweets: 3,
			loaderText: "Aguarde, carregando...",
			slideIn: false,
			showHeading: false,
			showProfileLink: false,
			showTimestamp: false,
			beforeEachTweet: "CENTURY 21 Milanez"
		});
	}
	
	//simuladores
	$("#detalhes a#simuladores").click(function(){
		if ($(this).hasClass("open")) {
			$("#detalhes #simuladores-bancos").hide("slow",function(){
				$("#detalhes a#simuladores").removeClass("open");
			});
		} else {
			$("#detalhes #simuladores-bancos").slideDown("slow",function(){
				$("#detalhes a#simuladores").addClass("open");
			});
		}
		return false;
	});
	
	//icones do imovel
	$("#detalhes .icones li a").hover(function(){
		alt = $(this).find("img").attr("alt");
		$("#detalhes .icones li.legenda").html(alt);
	},function(){
		$("#detalhes .icones li.legenda").html("");
	});
	
	//fotos do imovel
	if ($("#imovel-fotos").length>0) {
		var lbsettings = { containerResizeSpeed: 350 };
		$('#imovel-fotos .items a').lightBox(lbsettings);
		//$("#imovel-fotos .items a").lightBox();
		$("div.scrollArea").scrollable({
			next: 'div.btnRight', 
			prev: 'div.btnLeft',
			loop: true, 
			keyboard: false,
			speed: 600
		});
	}
	
});
