//mapa
function mapa_imovel(l1,l2) {
	//if ($("#map").length>0) {
		if (GBrowserIsCompatible()) {
			
			var map = new GMap2(document.getElementById("map"));
			map.setCenter(new GLatLng(l1,l2), 15);
			var icone = new GIcon(G_DEFAULT_ICON);
			icone.image = "img/design/icon_gmap.png";
			icone.iconSize = new GSize(23, 33);
			markerOptions = { icon:icone };
			var latlng = new GLatLng(l1,l2);
			map.addOverlay(new GMarker(latlng, markerOptions));
			//if ($("#localizacao").length>0) {
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				map.addMapType(G_SATELLITE_3D_MAP);
				var mapControl = new GMapTypeControl();
				map.addControl(mapControl);
			//}
		}
		/*
		if ($("#localizacao").length>0) {
			$("#localizacao").dialog({
				autoOpen: false,
				bgiframe: true,
				minHeight: 140,
				modal: true,
				width: 934,
				resizable: false
			});
			$(".abre_mapa").click(function(){
				$("#localizacao").dialog('open');
				map.checkResize() 
				return false;
			});
		}
		*/
	//}
}

	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);
			})
	}


$(document).ready(function(){
	
    
	//animacao
	if ($(".cycle").length>0) {
		$('.cycle').cycle({ 
			fx:     'fade', // pode tentar também 'fade' que fica legal. Tem outros efeitos em http://malsup.com/jquery/cycle/begin.html
			timeout: 3000, // segundos x1000
			pause: true // true pra parar qdo o mouse ta em cima
		});
	}

	//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: "c21prime",
			numTweets: 3,
			loaderText: "Aguarde, carregando...",
			slideIn: false,
			showHeading: false,
			showProfileLink: false,
			showTimestamp: false,
			beforeEachTweet: "CENTURY 21 Prime"
		});
	}
	
	//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
		});
	}*/
	
	//fotos do imovel
	if ($("#imovel-fotos").length>0) {
		$('#imovel-fotos .items a').lightBox();
		$("div.scrollArea").scrollable({
			//next: 'div.btnRight', 
			//prev: 'div.btnLeft',
			loop: true, 
		    size: 4,
			speed: 1000
		});
	}

});
