﻿var GBwin;
var map;
var gdir;
var geocoder = null;
var addressMarker;

function loading() {
    return "<div style='text-align:center'><img src='" + applicationPath + "/images/loading.gif'/></div>";
}
function formatFecha(fecha) {
    var year = fecha.getFullYear();
    var mes = fecha.getMonth() + 1;
    if (String(mes).length == 1) mes = "0" + mes;
    var dia = fecha.getDate();
    if (String(dia).length == 1) dia = "0" + dia;
    return dia + "/" + mes + "/" + year;
}
function GB_hide() {
    GB_CURRENT.hide(GBwin)
}

function redirigir(destino) {
    document.location = destino;
}
function abrirNewsLetter() {
    GBwin = GB_showCenter('Newsletter', '/costablanca/news.asp', 350, 569);
    return false;
}
// Carrusel fotos
var pos = 1;
var totalfotos;

$(document).ready(function() {
    aplicarCrop();
    totalfotos = $(".fotocarrusel").length / 2;
    if (totalfotos == 0) $('#pestFotos').hide();
    $('.izq_carrusel').click(function() {
        if (pos > 1) {
            $('.caja_carrusel_list').animate({ 'left': '+=75px' }, 500);
            pos--;
        }
        return false;
    });
    $('.dcha_carrusel').click(function() {
        if (pos < totalfotos - 7) {
            $('.caja_carrusel_list').animate({ 'left': '-=75px' }, 500);
            pos++;
        }
        return false;
    });
    $('.sig_foto').click(function() {
        var fotoactual = $('.muestra_foto img').attr('src');
        fotoactual = fotoactual.substring(fotoactual.indexOf("ruta=") + 5, fotoactual.length);
        var href = $(".fotocarrusel[href='" + fotoactual + "']").next().attr('href');
        if (href != undefined) {
            $('.muestra_foto img').attr('src', href);
            aplicarCrop();
        }
        return false;
    });
    $('.ant_foto').click(function() {
        var fotoactual = $('.muestra_foto img').attr('src');
        fotoactual = fotoactual.substring(fotoactual.indexOf("ruta=") + 5, fotoactual.length);
        var href = $(".fotocarrusel[href='" + fotoactual + "']").prev().attr('href');
        if (href != undefined) {
            $('.muestra_foto img').attr('src', href);
            aplicarCrop();
        }
        return false;
    });
    $(".muestra_foto").corners();
    $('.fotocarrusel').click(function() {
        activaPestana('pestFotos');
        var foto = $(this).attr('href');
        $('.muestra_foto img').attr('src', foto);
        $(".muestra_foto").corners();
        aplicarCrop();
        return false;
    });
});
function aplicarCrop() {
    $('.crop').each(function() {
        var ruta = $(this).attr('src');
        var width = $(this).attr('width');
        var height = $(this).attr('height');
        if (ruta != undefined && ruta.indexOf("http://217.116.24.167/ecms/files/thumb.aspx") == -1) {
            if (ruta.indexOf("http://") == -1) ruta = "http://" + dominio + ruta;
            var url = "http://217.116.24.167/ecms/files/thumb.aspx?enlace=1&accion=crop&w=" + width + "&h=" + height + "&ruta=" + ruta;
            $(this).attr('src', url);
        }
    });
}


