
$(document).ready(function(){
    
//	$("body").queryLoader2({
//        barColor: "#fff",
//        backgroundColor: "#FDF21D",
//        percentage: true,
//        barHeight: 2,
//        completeAnimation: "grow"
//    });
	
	$.translate.load('8CF28FDCC5684217FB9FB9F46DE788F51BEC8345'); 
//scrolltop
	$(window).scroll(function(){
		if (window.pageYOffset >= 1000) {
			$('#scroll-up:not(:visible)').fadeIn();
		} else {
			$('#scroll-up:visible').fadeOut();
		}
	});
	
//	cambio de estilo alquileres 
    
        $("div.alquiler-tiny").mouseover(function(){
    	$(this).removeClass().addClass("cajaOver alquiler-tiny");
    }).mouseout(function(){
    	$(this).removeClass().addClass("cajaoff alquiler-tiny");		
    });
        
//    	cambio de estilo ventas
    $("div.viv-tiny").mouseover(function(){
    	$(this).removeClass().addClass("cajaOver viv-tiny");
    }).mouseout(function(){
    	$(this).removeClass().addClass("cajaoff viv-tiny");		
    });
    


	// menu-info
	$("#m_info").hover(
		function () {
//			$("#m_info_link").css('background-color','#004595');
//			$("#m_info_link").css('color','#fff');
			$('#menu-info').show('fast');
		}, 
		function () {
//			$("#m_info_link").css('background-color','transparent');
//			$("#m_info_link").css('color','#004595');
			$('#menu-info').hide('fast');
		}
	)
	

    /*$("a[rel]").prettyPhoto({*/
        $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook',
        gallery_markup: '<div class="pp_gallery"> \
								<a href="#" class="pp_arrow_previous">Anterior</a> \
								<a href="#" class="pp_arrow_next">Siguiente</a> \
							</div>',
    });



	//Poner el valor del día de entrada al día de salida
    $(".dentrada").change(function () {
        var value = $(this).val();
        $(".dsalida").val(value);
//      $('.dsalida').val('25-8-2012');
    });
	
    // calendario entrada
    $('.dsalida').datepicker({
        minDate: '+2',
        dateFormat: 'd-m-yy',
        numberOfMonths: 1,
        showButtonPanel: true,
        showAnim: 'drop',

        beforeShowDay: function(d)
        {
            fecha = new Date(d);
            var x = false;
            if (fecha.getDate() == '8' || fecha.getDate() == '15' || fecha.getDate() == '23' || fecha.getDate() == '30' || fecha.getDate() == '31')
            {
                x = true;
            }
            var result = [x, 'on']
            return result;
        }

    });
    // calendario salida
    
//    $('.dentrada').val(); 

//    
    $('.dentrada').datepicker({
        minDate: '+1',
        dateFormat: 'd-m-yy',
        numberOfMonths: 1,
        showButtonPanel: true,
        showAnim: 'drop',
        beforeShowDay: function(d)
        {
            fecha = new Date(d);
            var x = false;
            if (fecha.getDate() == '1' || fecha.getDate() == '8' || fecha.getDate() == '16' || fecha.getDate() == '23')
            {
                x = true;
            }
            var result = [x, 'on']
            return result;
        }
    });

    // login y toolltip
    $(".signin").click(function(e) {
		e.preventDefault();
        $("fieldset#signin_menu").toggle();
		$(".signin").toggleClass("menu-open");
    });

	$("fieldset#signin_menu").mouseup(function() {
		return false
	});
	$(document).mouseup(function(e) {
		if($(e.target).parent("a.signin").length==0) {
			$(".signin").removeClass("menu-open");
			$("fieldset#signin_menu").hide();
		}
	});

//tipsy

$(function() {
	  $('#resend_password_link').tipsy({gravity: 'w'});
      $('#fenomeno').tipsy({gravity: 's'});
      //$('a[title]').tipsy({gravity: 'w'});
      $('.tipsy_nw').tipsy({gravity: 'nw'});
      $('.tipsy_n').tipsy({gravity: 'n'});
      $('.tipsy_ne').tipsy({gravity: 'ne'});
      $('.tipsy_w').tipsy({gravity: 'w'});
      $('.tipsy_e').tipsy({gravity: 'e'});
      $('.tipsy_sw').tipsy({gravity: 'sw'});
      $('.tipsy_s').tipsy({gravity: 's'});
      $('.tipsy_se').tipsy({gravity: 'se'});
    });

    //tabs y botones
        // Crear botones
    $('.btn').button();

    // Crear Tabs
    $( ".tabs" ).tabs();
    
    $( ".accordion" ).accordion();

   function get_alquileres(form)
    {
        params = $(form).serialize();
        $.ajax({
            url: "/ajax/get_alquileres.php",
            async:true,
            beforeSend: function(objeto){
                $('#alquileres-list').html('<img src="/img/loading_big.gif" alt="Cargando..." id="loading-gif" />')
            },
            complete: function(objeto, exito){
                //alert('fin');
            },
            data : params + '&ajax=1',
            dataType: "json",
            error: function(objeto, quepaso, otroobj){
                if (quepaso == 'timeout')
                {

                }else if (quepaso)
                {

                }else
                {

                }
            },
            success: function(data){

                $('#alquileres-list').html(data.html);

            },
            timeout: 60000,
            type: "POST"
        });
    }

   
    $('#form-registro').submit(function(e){
        e.preventDefault();

        params = $(this).serialize();

        var no_compra = false;
        if ($('#no-compra').length)
        {
            no_compra = true;
        }

        $.ajax({
            url: "/ajax/registro.php",
            async:true,
            beforeSend: function(objeto){
                //$.prettyLoader.show();
            },
            complete: function(objeto, exito){
                //$.prettyLoader.hide();
            },
            data : params,
            dataType: "json",
            error: function(objeto, quepaso, otroobj){
                alert("Ha sucedido un error inesperado - 0001");
            },
            success: function(data){

                if (data.error == 'false')
                {
                    alert(data.exito);
                    if (data.go != '')
                    {
                        document.location.href = data.go;
                    }else
                    {
                        $('#form-registro').hide();
                        $('#registro-info').hide();
                        $('#registro-ok').show('fast');
                    }
                }else
                {
                    alert(data.error);
                    for (var ee in data.error_fields)
                    {
                        $('label[for='+data.error_fields[ee]+']').css('color','#f00')
                    }
                }
            },
            timeout: 3000,
            type: "POST"
        });

    });

    $("#form-registro").validationEngine({promptPosition : "centerRight"});
    $('#r_enviar').click(function(e){
        $('#login-form').validationEngine('hideAll');
        if (!$("#form-registro").validationEngine('validate'))
        {
            e.preventDefault();
        }
    });



    //fade in out de la red social
    $('.fade').hover(function() {$(this).children('span').fadeOut('250');},function() {$(this).children('span').fadeIn('250');})
    
    

	
	// maskcara para inputs
	$('.mask').focus(function(){
		var v = $(this).val();
		var d = $(this).attr('data');
		
		if (v == d) {
			$(this).val('');
		}
		
		$(this).addClass('maskOn');
	});
	
	$('.mask').focusout(function(){
		var v = $(this).val();
		var d = $(this).attr('data');
		if (v == d) {
			$(this).removeClass('maskOn');
		}else if(v == '') {
			$(this).val(d);
			$(this).removeClass('maskOn');
		}
	});
    
    
    
   //aviso legal
    //detectar que linka se activa
    $('#link-aviso').click(function(){
    $('#avisolegal').addClass('caja');
    //$('#test1').show('slow'); // para mostrar
    $('#avisolegal').toggle('fast'); // mostrar/ocultar
		
	});

    
    
    //fondo 100%
    function updateBackground() {
    	screenWidth = $(window).width();
    	screenHeight = $(window).height();
    	var bg = jQuery("#bg");

    	// Proporcion horizontal/vertical. En este caso la imagen es cuadrada
    	ratio = 1;

    	if (screenWidth/screenHeight > ratio) {
    	$(bg).height("auto");
    	$(bg).width("100%");
    	} else {
    	$(bg).width("auto");
    	$(bg).height("100%");
    	}

    	// Si a la imagen le sobra anchura, la centramos a mano
    	if ($(bg).width() > 0) {
    	$(bg).css('left', (screenWidth - $(bg).width()) / 2);
    	}
    	}
    	$(document).ready(function() {
    	// Actualizamos el fondo al cargar la pagina
    	updateBackground();
    	$(window).bind("resize", function() {
    	// Y tambien cada vez que se redimensione el navegador
    	updateBackground();
    	});
    	});

});

// Formulario desde hasta

/*
 $(function() {
 		var dates = $( "#ba_desde, #ba_hasta" ).datepicker({
 			defaultDate: "+1w",
 			changeMonth: true,
 			numberOfMonths: 3,
 			onSelect: function( selectedDate ) {
 				var option = this.id == "ba_desde" ? "minDate" : "maxDate",
 					instance = $( this ).data( "datepicker" ),
 					date = $.datepicker.parseDate(
 						instance.settings.dateFormat ||
 						$.datepicker._defaults.dateFormat,
 						selectedDate, instance.settings );
 				dates.not( this ).datepicker( "option", option, date );
 			}
 		});
 	});
 */



