﻿// JScript File
var map = null;
var pinInfobox1 = null;
var pinInfobox2 = null;

function ClickButton(e) {
    var bt = document.getElementById('SearchImage');
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Netscape") > (-1)) {
            if (e.keyCode == 13) {
                bt.click();
                return false;
            };
        };
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            };
        };
    };
};
function FocusSearchBox() {
    var SearchBox = document.getElementById('FilterTextBox');

    if (SearchBox.value == "Pesquisar...") {
        SearchBox.value = "";
    };

};
function BlurSearchBox() {
    var SearchBox = document.getElementById('FilterTextBox');

    if (SearchBox.value == "") {
        SearchBox.value = "Pesquisar...";
    };

};
function GetMap() {
    map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),
                           { credentials: "Ap2IiK697qcv3vfEfJgcroGlGCqz47DSm5XLO5umsvuUDi80IGMLqkPxf_GSp7cE",
                               center: new Microsoft.Maps.Location(39.43623761631492, -9.123108054680528),
                               mapTypeId: Microsoft.Maps.MapTypeId.road,
                               zoom: 6,
                               enableSearchLogo: false,
                               enableClickableLogo: false,
                               useInertia: true,
                               width: 690,
                               height: 460
                           });
    // Create the infobox for the pushpin
    pinInfobox1 = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(41.15689585571062, -8.624203205108642),
                { title: 'Loja do Porto',
                    description: 'Avenida da Boavista , 25 - Boavista - 4050-114 Porto',
                    visible: false,
                    showPointer: true,
                    offset: new Microsoft.Maps.Point(0, 15)
                });
    pinInfobox2 = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(39.73612914433726, -8.82611587833999),
                { title: 'Loja de Leiria',
                    description: 'Estrada dos Parceiros, 293 - 2400-441 Leiria',
                    visible: false,
                    showPointer: true,
                    offset: new Microsoft.Maps.Point(0, 15)

                });

    // Hide the infobox when the map is moved.
    Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);


    var loc1 = new Microsoft.Maps.Location(41.15689585571062, -8.624203205108642);
    var loc2 = new Microsoft.Maps.Location(39.73612914433726, -8.82611587833999);

    var pin1 = new Microsoft.Maps.Pushpin(loc1);
    var pin2 = new Microsoft.Maps.Pushpin(loc2);


    // Add handler for the pushpin click event.
    Microsoft.Maps.Events.addHandler(pin1, 'click', displayInfobox1);
    Microsoft.Maps.Events.addHandler(pin2, 'click', displayInfobox2);

    map.entities.push(pin1);
    map.entities.push(pinInfobox1);

    map.entities.push(pin2);
    map.entities.push(pinInfobox2);

}
function displayInfobox1(e) {
    pinInfobox1.setOptions({ visible: true });
    pinInfobox2.setOptions({ visible: false });
}
function displayInfobox2(e) {
    pinInfobox1.setOptions({ visible: false });
    pinInfobox2.setOptions({ visible: true });
}

function hideInfobox(e) {
    pinInfobox1.setOptions({ visible: false });
    pinInfobox2.setOptions({ visible: false });
}

function SetPortoStore() {
    map.setView({ center: new Microsoft.Maps.Location(41.15689585571062, -8.624203205108642), zoom: 15, mapTypeId: Microsoft.Maps.MapTypeId.road });
}
function SetLeiriaStore() {
    map.setView({ center: new Microsoft.Maps.Location(39.73612914433726, -8.82611587833999), zoom: 15, mapTypeId: Microsoft.Maps.MapTypeId.road });
}
function SetAutoComplete() {
    $('input[name*="Filter"]').autocomplete("../AutoComplete.ashx", {
        formatItem: function (data, i, n, value) {
            return "<div>" + "<div style='float:left'><img style='width:50px;height:50px' src='"
            + value.split("$")[3] + "'/> " + "</div><div style='float:left;margin-left:5px;width:300px;word-wrap:break-word;'>" + value.split("$")[1] + "</br>" + value.split("$")[0] + "</div></div>";
        },
        formatResult: function (data, value) {
            return value.split("$")[0];
        }
    }).setOptions({
        width: "442px",
        max: 1000,
        scroll: true,
        scrollHeight: 600,
        matchSubset: true,
        delay: 400,
        cacheLength: 200,
        minChars: 3
    }).result(function (event, item) {
        window.location.href = "../Detail.aspx?Id=" + item.toString().split("$")[2];
    });
}
function SetPrettyPhoto() {
    $("a[rel^='prettyPhoto']").prettyPhoto({
        overlay_gallery: false,
        allow_resize: false,
        slideshow: false,
        deeplinking: false
    });
}
function SetGallery() {
    $('#myGallery').galleryView({
        panel_width: 240,
        panel_height: 402,
        show_filmstrip: false,
        transition_interval: 8000,
        transition_speed: 600,
        panel_animation: 'crossfade',
        pause_on_hover: true
    });
}

function SetUrlDiapo() {
    if (window.location.href == "http://www.sinfonia-online.com/") {
        SetDiapo();
        $('#temp_top').removeClass('maintop').addClass('maintop_modified');
    }
    if (window.location.href == "http://sinfonia-online.com/") {
        SetDiapo();
        $('#temp_top').removeClass('maintop').addClass('maintop_modified');
    }
    if (window.location.href == "http://www.sinfonia-online.com/default.aspx") {
        SetDiapo();
        $('#temp_top').removeClass('maintop').addClass('maintop_modified');
    }
    if (window.location.href == "http://sinfonia-online.com/default.aspx") {
        SetDiapo();
        $('#temp_top').removeClass('maintop').addClass('maintop_modified');
    }
    if (window.location.href == "http://localhost:54061/") {
        SetDiapo();
        $('#temp_top').removeClass('maintop').addClass('maintop_modified');
    }
}
function SetDiapo() {
    $('#pix_diapo').diapo({
        pieDiameter: '30',
        thumbs: false,
        loaderColor: '#FF6600',
        time: '7500'
    });
}
function SetNivo() {
    $('#slider_1').nivoSlider({
        effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: true, // 1,2,3... navigation
        pauseTime: 10000 // How long each slide will show
    });
    $('#slider_2').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 13000 // How long each slide will show
    });
    $('#slider_3').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 16000 // How long each slide will show
    });
    $('#slider_4').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 19000 // How long each slide will show
    });
    $('#Bottom_slider_1').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 13000 // How long each slide will show
    });
    $('#Bottom_slider_2').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 13000 // How long each slide will show
    });
    $('#Midlle_slider_1').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 10000 // How long each slide will show
    });
    $('#Midlle_slider_2').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        controlNav: false, // 1,2,3... navigation
        pauseTime: 10000 // How long each slide will show
    });
}
function GetSeaDragon(TheId) {
    var thePath = null;
    $.ajax({
        type: "POST",
        url: "../Services/JqueryTest.asmx/GetZoomPath",
        data: '{TheId: "' + TheId + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            SetSeaDragon(data.d);
        }
    });
}
function SetSeaDragon(ThePath) {
    var viewer = null;
    Seadragon.Config.imagePath = "Images/img/";
    Seadragon.Config.minZoomImageRatio = 1;
    Seadragon.Config.maxZoomPixelRatio = 1.23;
    Seadragon.Strings.setString("Tooltips.Home", "RESET");
    Seadragon.Strings.setString("Tooltips.ZoomIn", "CLIQUE PARA AUMENTAR A IMAGEM (PODE TAMBEM USAR A RODA DO RATO)");
    Seadragon.Strings.setString("Tooltips.ZoomOut", "CLIQUE PARA DIMINUIR A IMAGEM (PODE TAMBEM USAR A RODA DO RATO)");
    viewer = new Seadragon.Viewer("container");
    var navControl = viewer.getNavControl();
    navControl.removeChild(navControl.lastChild);
    viewer.openDzi(ThePath);
}
function SetAll() {
    SetAutoComplete();
    SetPrettyPhoto();
    SetUrlDiapo();
}
