﻿function initVetrina() {
    var ctl;
    var appo;
    var idLink;
    if (widthScreen == null)
        widthScreen = $(window).width();
    if (heightScreen == null)
        heightScreen = $(window).height();
    widthScreen = widthScreen - 20;
    heightScreen = heightScreen - 116;
    $("img[name='imgV']").each(function(i) {
        ctl = $(this);
        appo = ctl.attr("src").split("filename=")[1];
        idLink = "hlV" + ctl.attr("id").split("imgV")[1];
        $("#" + idLink).attr("href", "resize.aspx?nof=fpd&type=ss" + "&w=" + widthScreen + "&h=" + heightScreen + "&filename=" + appo);
    });
    $("a[name='hlV']").lightBox();
}

function doRedirectV(idImmo) {
    var ok = false;
    var numTotImmo = 0;
    var pos;
    var imgAjaxLoader = $("#imgAjaxLoader");
    var position = $("#hlVetDett" + idImmo).position();
    $.ajax({
        type: "POST",
        dataType: "json",
        cache: false,
        url: "ajaxRequest.aspx?ts=" + new Date().getTime(),
        data: "action=cercaimmo_vetrina&id=" + idImmo,
        beforeSend: function() {
            imgAjaxLoader.css("left", position.left);
            imgAjaxLoader.css("top", position.top + 14);
            imgAjaxLoader.show();
        },
        success: function(ret) {
            if (ret.error != "") {
                divError.html(ret.error);
            } else {
                ok = true;
                numTotImmo = ret.numTotImmo;
                pos = ret.pos;
            }
        },
        complete: function() {
            imgAjaxLoader.hide();
            if (ok) {
                if (numTotImmo > 0) {
                    location.href = "dettaglio.aspx?id=" + idImmo + "&pos=" + pos;
                }
            }
        },
        error: function(XMLHttpRequest, textStatus) {
            divError.html(textStatus);
        }
    });
}
