﻿/*********************************************************************************************************
    ARCHIE OVERLAY
**********************************************************************************************************/

var archie_contenutoOverlay = "";
var archie_idPagina = "";

function setContenutoOverlay(m_strContenuto){
    archie_contenutoOverlay = m_strContenuto;
    $('#archie-contenuto-overlay').html(archie_contenutoOverlay + "");
}

function archieOverlayUrl(m_strUrl){
    $.get(m_strUrl, function(data) {
        archie_contenutoOverlay = data;
        archieOverlay(data);
    });
}

function archieOverlay(){
    inserisciElementiOverlay();
    setContenutoOverlay(archie_contenutoOverlay);
    centraOggetto($('#archie-centratore-overlay'));
    mostraOverlay();
}

function archieOverlay(contenuto){
    inserisciElementiOverlay();
    setContenutoOverlay(contenuto);
    centraOggetto($('#archie-centratore-overlay'));
    mostraOverlay();
}

function inserisciElementiOverlay(){
    if($('#archie-overlay').size() < 1){
        $("body").append("<div style=\"display:none;z-index:10001;\" onclick=\"$('#archie-overlay, #archie-centratore-overlay').fadeOut();\" id=\"archie-overlay\"><!-- --></div>");
        $("body").append("<div style=\"display:none;z-index:10011;\" onclick=\"$('#archie-overlay, #archie-centratore-overlay').fadeOut();\" id=\"archie-centratore-overlay\"><div id=\"archie-chiudi-overlay\">X</div><div id=\"archie-contenuto-overlay\"></div></div>");
    }
    $('#archie-overlay').css("height", getPageMaxHeight());
}

function mostraOverlay(){
    $('#archie-overlay, #archie-centratore-overlay').fadeIn();
}

function nascondiOverlay(){
    $('#archie-overlay, #archie-centratore-overlay').fadeOut();
}

/*
    centra oggetto al body
*/
function centraOggetto(el) {
    var el_jQuery = $(el);
    el_jQuery.css("top", getPageScrollY() + ((getPageHeight() - $(el_jQuery).height())/2));
    el_jQuery.css("left", (getPageWidth() - $(el_jQuery).width())/2);
};

/*
    restituisce lunghrzza dello scoll della pagina lungo l'asse X
*/
function getPageScrollX() {
    var xScroll;
    if (self.pageYOffset) {
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
        xScroll = document.body.scrollLeft;
    }
    
    return xScroll;
};

/*
    restituisce l'altezza dello scoll della pagina lungo l'asse Y
*/
function getPageScrollY() {
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }
    
    return yScroll;
};


/*
    page max Height (altezza più scroll)
*/
function getPageMaxHeight(){
    var yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
    }
    
	if(yScroll<getPageHeight()){
        yScroll = getPageHeight();
    }
	
    return yScroll;
}

/*
    page Height
*/
function getPageHeight(){
    var windowHeight;
    if (self.innerHeight) {	// all except Explorer
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}

/*
    page Width
*/
function getPageWidth(){
    var windowWidth;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
    }
    return windowWidth;
}
