	var ancho = 175-3;

	$(document).ready(function(){


	if($('.modelo_slide ul li').length > 1) {
		$('.modelo_slide').anythingSlider({
		    easing: "easeInOutExpo",                // Anything other than "linear" or "swing" requires the easing plugin
				autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
				startStopped: false,            // If autoPlay is on, this can force it to start stopped
				delay: 5000,                    // How long between slide transitions in AutoPlay mode
				animationTime: 700,             // How long the slide transition takes
				hashTags: false,                 // Should links change the hashtag in the URL?
				buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
				pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
				startText: ">",             // Start text
				stopText: "<",               // Stop text
				buildArrows: true
		});
	}



	if($('.contenedor_slide ul li').length > 1) {
		$('.contenedor_slide').anythingSlider({
		    easing: "easeInOutExpo",                // Anything other than "linear" or "swing" requires the easing plugin
				autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not
				startStopped: false,            // If autoPlay is on, this can force it to start stopped
				delay: 5000,                    // How long between slide transitions in AutoPlay mode
				animationTime: 700,             // How long the slide transition takes
				hashTags: false,                 // Should links change the hashtag in the URL?
				buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
				pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
				startText: "",             // Start text
				stopText: ""
		});
	}


	$('.proyecto_slider').jcarousel();


	$("#metraje_slider").slider({
			range: true,
			values: [glb_metros_min, glb_metros_max],
		//	values: [25,27,30,35,40,47,54,60,69,80,90,100,112,130,145,160,180,200,225,250,280,320,360,400,440,490,540,600,670,740, 800],
			//value:0,
			min: glb_metros_min,
			max: glb_metros_max,
		//	step: 1,
			slide: function(event, ui) {

				// Detectamos si cambio el minimo o el maximo
				if ( ui.values[0] != glb_current_metros_min   )
				{
					var orig_pos =  ui.values[0];
					//console.log("Cambio el minimo" +  ui.values[0] );
					var escala = (ui.values[0]-glb_metros_min)/(glb_metros_max-glb_metros_min);
					escala = escala*escala;
					ui.values[0] = Math.round(escala*(glb_metros_max-glb_metros_min) + glb_metros_min);
					glb_current_metros_min = ui.values[0];
					
					//offset en porcentaje
					prmin = (((ui.values[0] - glb_metros_min )*100)/(  glb_metros_max - glb_metros_min ) );
					//valor minimo
					pxmin = ( (  prmin * 1.70 ) - 85  );
					//escala = (ui.values[0]-glb_metros_min)/(glb_metros_max-glb_metros_min);
					var pos_baloon =  (orig_pos-glb_metros_min)*ancho/(glb_metros_max-glb_metros_min) -85;
					//alert(pos_baloon);
					$("#metros_tooltip_min").html(  ui.values[0] + " m2"   ).css("left",  Math.round( pos_baloon  )   );
					//$("#metros_tooltip_min").html(  ui.values[0] + " m2"   ).css("left",  Math.round( ui.values[0]  )   );
					$("#metros_min").val( ui.values[0]  );

				}
				if ( ui.values[1] != glb_current_metros_max   )
				{
					var orig_pos =  ui.values[1];
					var escala = (ui.values[1]-glb_metros_min)/(glb_metros_max-glb_metros_min);
					escala = escala*escala;
					ui.values[1] = Math.round(escala*(glb_metros_max-glb_metros_min) + glb_metros_min);
					//console.log("Cambio el maximo" + ui.values[1]);
					glb_current_metros_max = ui.values[1];

					//prmax = ((ui.values[1]*100)/(  glb_metros_max - glb_metros_min ) - 3.2 );
					prmax = (((ui.values[1] - glb_metros_min )*100)/(  glb_metros_max - glb_metros_min ) - 3.2 );
					prmax = Math.sqrt(prmax/100)*100;
					pxmax = (   prmax * 1.70    + 5  );
					var pos_baloon =  (orig_pos-glb_metros_min)*ancho/(glb_metros_max-glb_metros_min);

					$("#metros_tooltip_max").html(  ui.values[1] + " m2"   ).css("left",  Math.round( pos_baloon)   );
					$("#metros_max").val( ui.values[1]  );

				}

			}
		});
	
		$("#rango_precio").slider({
			range: true,
			values: [glb_precios_min, glb_precios_max ],
			value:0,
			min:glb_precios_min,
			max: glb_precios_max,
			step: 1,
			slide: function(event, ui) {
			

				// Detectamos si cambio el minimo o el maximo
				if ( ui.values[0] != glb_current_precios_min   )
				{
					var orig_pos =  ui.values[0];
					var escala = (ui.values[0]-glb_precios_min)/(glb_precios_max-glb_precios_min);
					escala = escala*escala;
					ui.values[0] = Math.round(escala*(glb_precios_max-glb_precios_min) + glb_precios_min);

					//console.log("Cambio el minimo" +  ui.values[0] );
					glb_current_precios_min = ui.values[0];
					
					//prmin = ((ui.values[0]*100)/(  glb_precios_max - glb_precios_min ) - 3.2 );
					prmin = (((ui.values[0]-glb_precios_min)*100)/(  glb_precios_max - glb_precios_min ) );

					pxmin = ( ( ( prmin * 170 ) / 100  ) - 85  );
					var pos_baloon =  (orig_pos-glb_precios_min)*ancho/(glb_precios_max-glb_precios_min) -85;

					$("#precios_tooltip_min").html(  ui.values[0] + " UF"   ).css("left",  Math.round( pos_baloon)   );
					$("#precios_min").val( ui.values[0]  );

				}
				if ( ui.values[1] != glb_current_precios_max   )
				{
					var orig_pos =  ui.values[1];
					var escala = (ui.values[1]-glb_precios_min)/(glb_precios_max-glb_precios_min);
					escala = escala*escala;
					ui.values[1] = Math.round(escala*(glb_precios_max-glb_precios_min) + glb_precios_min);

					//console.log("Cambio el maximo" + ui.values[1]);
					glb_current_precios_max = ui.values[1];

					//prmax = ((ui.values[1]*100)/(  glb_precios_max - glb_precios_min ) - 3.2 );
					prmax = (((ui.values[1] - glb_precios_min)*100)/(  glb_precios_max - glb_precios_min )  );

					//console.debug( prmax  );
					pxmax = ( ( ( prmax * 170 ) / 100  ) + 5  );
					var pos_baloon =  (orig_pos-glb_precios_min)*ancho/(glb_precios_max-glb_precios_min);

					$("#precios_tooltip_max").html(  ui.values[1] + " UF"   ).css("left",  Math.round( pos_baloon)   );
					$("#precios_max").val( ui.values[1]  );

				}



			}
		});

		// Metraje
		$("#metros_tooltip_min").html( glb_metros_min + " m2" ).css("left" , "-85px" );
		$("#metros_tooltip_max").html( glb_metros_max + " m2" ).css("left" , "175px" );

		// Precios
		$("#precios_tooltip_min").html( glb_precios_min + " UF" ).css("left" , "-85px" );
		$("#precios_tooltip_max").html( glb_precios_max + " UF" ).css("left" , "175px" );


		
		$(".mapa-city").tipsy({gravity: 'w'});	
		
		
	});



function newsletterRegister()
{
	if (  $("#newsletter_mail").val()   )
	{
		$.ajax(	{
		url: "/json.php" , 
		dataType: "json" ,
		data: { "email" :  $("#newsletter_mail").val() , "n" : Math.random() , "option" : "newsletterRegister"  } ,
		success: function( rsp )
		{
			if ( rsp.status  )
			{
				setCookieLT("newsletterRegister", "1" , (3600/6)   , "/" );
				$("#form-newsletter").fadeOut(200, function(){  $("#form-newsletter-thx").fadeIn(200)    }  );
			}
			else
			{
				alert( rsp.message );
			}
		}
		});		
	}
}

$(document).ready(function(){

if ( getCookie("newsletterRegister")  )
{
	$("#form-newsletter-thx").html("Ya estas registrado!");
	$("#form-newsletter").fadeOut(200, function(){  $("#form-newsletter-thx").fadeIn(200)    }  );
}

});

$(document).ready(function(){
		$(".video_galeria > ul").tabs({fx:{opacity: "toggle"}});
	});

$(document).ready(function(){
		$("#proyectoslistadohome > ul").tabs({fx:{opacity: "toggle"}});
	});


$(document).ready(function(){

	$("#thumbNav").click( function(){ return false;});
	$(".buscador_proyectos").click( function(){ return false; } );
	$(".galeria").click( function(){

		if (   $(".contenedor_slide").data('AnythingSlider')   )
		{
			var dest = "";
			try {
				dest = $(".contenedor_slide").data('AnythingSlider').$items[ $(".contenedor_slide").data('AnythingSlider').currentPage    ].children[0].href;
			} catch(e) {
				dest = "";
			}
			if(dest) {
				document.location.href = dest;
			}
		}
	
	});
	$("#search").click( function(){  $("#buscador-proyectos").submit() } );

	$(".precio-dividendo-precio").qtip(
	{
		content: 'Dividendo a ' + glb_plazo + ' años, tasa fija ' + glb_tasa + '%, pie 10% y UF al día',
		style:{name:'blue'}
	});

	$(".precio-dividendo-superior").qtip(
	{
		position:{ corner:{ tooltip:'bottomRight' , target:'topLeft'   }  },
		content: 'Dividendo a ' + glb_plazo + ' años, tasa fija ' + glb_tasa + '%, píe 10% y UF al día',
		style:{name:'blue'}
	});


	$(".precio-uf").each(function()
	{
		$(this).qtip(
		{
			content: $(this).attr('rel'),
			style:{name:'blue'}
		});

	});


	$(".precio-uf-superior").each(function()
	{
		$(this).qtip(
		{
		position:{ corner:{ tooltip:'bottomRight' , target:'topLeft'   }  },
		content: $(this).attr('rel'),
		style:{name:'blue'}
		});
	});


        $('.foto_grd a').lightBox();
        $('a.foto_lightbox').lightBox();


	
})

function sharetofacebook()
{
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent( location.href )+'&t='+encodeURIComponent( document.title ),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}


$(function() {
	$('.opiniones-lightbox').lightBox();
});

$(function() {
$('.mapa-proyectos-regiones div a').live('click', function() {
	
	$(".btn-region_XIII a").removeClass("active");
	
	var id = $(this).attr('class');
	var ciudad = $(this).attr('id');
	$(".btn-region_XIII ."+id).addClass("active");
	//alert(ciudad);
	$(".region").load("/ajax.php", {
	'ciudad': ciudad
	
	}, function(){
		//alert("Datos Guardados");	
		$("#proyectoslistadohome > ul").tabs({fx:{opacity: "toggle"}});		

	});
});
});

$(function() {

	$(".btn-region_XIII #Santiago").addClass("active");
	var ciudad = "Santiago";
	//alert(ciudad);
	$(".region").load("/ajax.php", {
	'ciudad': ciudad
	
	}, function(){
		//alert("Datos Guardados");	
		$("#proyectoslistadohome > ul").tabs({fx:{opacity: "toggle"}});		


});
});

$(function() {
$(".main_menu ul li:first").addClass('first');

});
