var blurImageIndex = 0;
var blurImageOpacity = 0;
function blurHotelImage(fotoCount) {
    var d = document.getElementById("fotob");
    var g = document.getElementById("fotoa");
    if (d && g) {
        blurImageOpacity -= 5
        if (blurImageOpacity <= 0) {
            blurImageOpacity = 300;
            blurImageIndex = (blurImageIndex + 1) % fotoCount;
            d.className = g.className;
            g.className = "fx" + blurImageIndex;
        }
        d.style.opacity = Math.min(1, blurImageOpacity / 100);
        d.style.filter = "alpha(opacity=" + blurImageOpacity + ")";
    }
}
var gdir = null, travelMode = null, gdirquery = "";
function initMappa(lat, lng, html) {
    if (GBrowserIsCompatible()) {
        var center = new GLatLng(lat, lng);
        gmap = new GMap2(document.getElementById("map"));
        gmap.addControl(new GLargeMapControl());
        gmap.addControl(new GMapTypeControl());
        gmap.addMapType(G_PHYSICAL_MAP);
        gmap.removeMapType(G_HYBRID_MAP);
        gdir = new GDirections(gmap, document.getElementById("percorso_map"));
        GEvent.addListener(gdir, "error", handleErrors);
        gmap.setCenter(center, 15);
        var marker = new GMarker(center);
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
        });
        gmap.addOverlay(marker);
        GEvent.trigger(marker, "click");
    }
}
function onClickTrovaIndirizzo() {
    var indirizzo = window.document.getElementById("indirizzo");
    if (indirizzo.value) {
        var from = ""
        var dest = "";
        var luogo = window.document.getElementById("luogo_indirizzo");
        if (luogo) {
            if (luogo.value == 'S') {
                from = "46.1705250,9.8679770";
                dest = indirizzo.value + ",Sondrio (SO),Italia";
            }
            else if (luogo.value == 'I') {
                dest = "46.1705250,9.8679770";
                from = indirizzo.value + ",Italia";
            }
        }
        else {
            from = "46.1705250,9.8679770";
            dest = indirizzo.value + ",Sondrio (SO),Italia";
        }
        gdir.clear();
        travelMode = G_TRAVEL_MODE_DRIVING;
        gdirquery = "from: " + from + " to: " + dest;
        gdir.load(gdirquery, {
            locale: myhlang
        });
    }
}
function handleErrors() {
    if (travelMode == G_TRAVEL_MODE_DRIVING) {
        gdir.clear();
        travelMode = G_TRAVEL_MODE_WALKING;
        gdir.load(gdirquery, {
            locale: "it",
            travelMode: G_TRAVEL_MODE_WALKING
        });
    } else {
        alert("Indirizzo non trovato");
    }
}
function onloadmap(lat, lng, html) {
    window.onload = function() {
        initMappa(lat, lng, html);
    }
    window.onunload = GUnload;
}
function loadPacchettiOfferhotel() {
    var ul = document.createElement("ul");
    for (var i=0; i<Math.min(3, ohpacchetti.length); i++) {
        var li = document.createElement("li");
        $(li)
            .mouseover(function() { $(this).addClass("offerup") })
            .mouseout(function() { $(this).removeClass("offerup") });
        var img = new Image();
        img.src = "http://www.offerhotel.com/data/pacchetti/" + ohpacchetti[i].id + "_1.jpg";
        img.onerror = function() {
            this.src = "/styles/pacchetti.jpg";
        }
        var a = document.createElement("a");
        a.href = "booking.html?ohpkg=" + ohpacchetti[i].id;
        a.appendChild(document.createTextNode(ohpacchetti[i].nome.substr(0, 60) + "..."));
        a.appendChild(img);
        li.appendChild(a);        
        ul.appendChild(li);
    }
    var d = document.getElementById("pacchetti");
    d.appendChild(ul);
}

$(document).ready(function(){
    $('#gallery a').lightBox();
    $('.slidephotos .bg').lightBox();
    $('.service li').mouseover(function(){
        $(this).css({'background':'#006699','color':'#fff'})
    });
    $('.service li').mouseout(function(){
        $(this).css({'background':'#ddd','color':'#000'})
    });
    $('.specialmenu ul li').mouseover(function(){
        $(this).addClass('menup')
    });
    $('.specialmenu ul li').mouseout(function(){
        $(this).removeClass('menup')
    });
    $(".buttonbook").hover(function(){
        $(".buttonbook img")
        .animate({
            top:"-10px"
        }, 200).animate({
            top:"-4px"
        }, 200) // first jump
        .animate({
            top:"-7px"
        }, 100).animate({
            top:"-4px"
        }, 100) // second jump
        .animate({
            top:"-6px"
        }, 100).animate({
            top:"-4px"
        }, 100); // the last jump
    });
    $('#basic-modal .basic').click(function (e) {
        $('#basic-modal-content').modal();

        return false;
    });
    $(function () {
        var tabContainers = $('div.tabs > div');
        $('div.tabs ul.tabNavigation a').click(function () {
            tabContainers.hide().filter(this.hash).show();
            $('div.tabs ul.tabNavigation a').removeClass('selected');
            $(this).addClass('selected');
            return false;
        }).filter(':first').click();
    });
    $('.button img').mouseover(function() {
        var src = this.alt;
        $('.button img').removeClass('clicked');
        $(this).addClass('clicked');
        $('a.bg').attr('href', src);
        $('#sectionAphotos').attr('src', src).fadeIn();
        $('.zoom').delay(300).fadeIn();
    });
    $('.button img').mouseout(function() {
        $('.zoom').delay(300).fadeOut();
    });
});
