﻿function open_win(path) {
    var w = 600;
    var h = 500;
    var l = Math.floor((screen.width - w) / 2);
    var t = Math.floor((screen.height - h) / 2);
    window.open(path, "", "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",scrollbars=yes");
}
function gallery(tipo, lang) {
    document.getElementById("popup_overlay_gallery").style.height = (getPageSize()[1]).toString() + "px"
    document.getElementById("popup_content_gallery").style.top = (244 + getScrollY()).toString() + "px"
    document.getElementById("popup_content_gallery").style.display = "block"
    $('#popup_overlay_gallery').fadeIn('slow',fade_fix);
    document.getElementById("popup_wait").style.display = "block";
    
    window.frames["photogallery"].document.location = "photogallery.aspx?lang=" + lang + "&tipo=" + tipo
}
function fade_fix() {
    document.getElementById('popup_overlay_gallery').style.filter = "alpha(opacity=80)";    /* bug su fade per exploirer, reimposto l'opacità   */
}
function close_gallery() {
    $('#popup_overlay_gallery').fadeOut('slow');
    $('#popup_content_gallery').fadeOut('slow', close_gallery_frame);
}
function close_gallery_frame() {
    document.getElementById("frame_photogallery").style.visibility = "hidden";
}
/*$(document).ready(function() {
    //id is the ID for the DIV you want to display it as modal window
    open_win("boxes");
});*/
function gallery_load() {
    document.getElementById("popup_wait").style.display = "none";
    $('#popup_content_gallery').fadeIn('slow');
    document.getElementById("frame_photogallery").style.visibility="visible";
}

function map() {
    document.getElementById("popup_overlay_gallery").style.height = (getPageSize()[1]).toString() + "px"
    document.getElementById("popup_content_map").style.top = (244 + getScrollY()).toString() + "px"
    document.getElementById("popup_content_map").style.display = "block"
    //document.getElementById("popup_overlay_map").style.display = "block"
    $('#popup_overlay_gallery').fadeIn('slow');
    document.getElementById("popup_wait").style.display = "block";
    try {
        window.frames["mappa"].document.location = "http://maps.google.it/maps?f=q&source=s_q&hl=it&geocode=&q=capo+ceraso+resort+Via+Fontana+Umbrina,+41+-+Olbia+(SS)+%E2%80%93+Italia&;sll=40.909621,9.553986&sspn=0.091461,0.153637&ie=UTF8&hq=&hnear=&cid=7916052945755885475&ll=40.903328,9.603767&spn=1.451078,2.334595&z=8&output=embed"
    }
    catch (e) {
    }

    document.getElementById("popup_wait_map").style.display = "none";
    $('#popup_content_map').fadeIn('slow');
    document.getElementById("frame_map").style.visibility = "visible";
    document.getElementById("frame_offerta").style.display = "none";
    document.getElementById("frame_map").style.display = "block";

}
function close_map() {
    $('#popup_overlay_gallery').fadeOut('slow');
    $('#popup_content_map').fadeOut('slow', close_gallery_frame);
}
function close_map_frame() {
    document.getElementById("frame_map").style.visibility = "hidden";
}


function offerta(id,lang) {
    document.getElementById("popup_overlay_gallery").style.height = (getPageSize()[1]).toString() + "px"
    document.getElementById("popup_content_map").style.top = (244 + getScrollY()).toString() + "px"
    document.getElementById("popup_content_map").style.display = "block"
    //document.getElementById("popup_overlay_map").style.display = "block"
    $('#popup_overlay_gallery').fadeIn('slow');
    document.getElementById("popup_wait").style.display = "block";
    try {
        window.frames["offerta_frame"].document.location = "dettaglio-offerta.aspx?lang="+lang+"&id="+id
    }
    catch (e) {
    }

    document.getElementById("popup_wait_map").style.display = "none";
    $('#popup_content_map').fadeIn('slow');
    document.getElementById("frame_offerta").style.visibility = "visible";
    document.getElementById("frame_offerta").style.display = "block";
    document.getElementById("frame_map").style.display = "none";
}


function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}
function getScrollY() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
}


var gallery_prima_transazione = true;
function gallery_onBefore() {
    //$('#gallery_title').fadeOut('slow');
    if (!gallery_prima_transazione)
        $('#gallery_title').slideUp('slow');
    gallery_prima_transazione = false;
}
function gallery_onAfter() {
    document.getElementById("gallery_title").style.visibility = "visible"
    $('#gallery_title').html(this.alt);
    //$('#gallery_title').fadeIn("slow");
    $('#gallery_title').slideDown("slow");
}
/* slide testata    */
function start_slide() {
    //document.getElementById("ctl00_imgSlide").src = path_testata[0]
    for (var i = 0; i < path_testata.length; i++) {
        var objImage = document.createElement("img");
        objImage.setAttribute('src', path_testata[i]);
        objImage.setAttribute('title', dida_testata[i]);
        objImage.setAttribute('alt', dida_testata[i]);
        document.getElementById("gallery").appendChild(objImage);
    }
    if (dida_testata.length == 1) {
        document.getElementById("gallery_title").style.visibility = "visible"
        $('#gallery_title').html(dida_testata[0]);
        $('#gallery_title').slideDown('slow');
    }
    else {
        $('.slideshow').cycle({
            fx: 'fade',
            speed: 2000,
            timeout: 6000,
            before: gallery_onBefore,
            after: gallery_onAfter
        });
    }
}
$(document).ready(function() {
    $('.slideshow').cycle({
        fx: 'fade',
        speed: 2000,
        timeout: 6000,
        before: gallery_onBefore,
        after: gallery_onAfter
    });
    var imgArray = $('.slideshow img')
    for (var i = 0; i < imgArray.length; i++) {
        imgArray[i].style.visibility = "visible";
    }
});