// Versione: 1.0

function MFWModalPopUpManager() {
    this.popUps = new Array();
}

MFWModalPopUpManager.prototype.add = function(popUp) {
    this.popUps[this.popUps.length] = popUp;
}


function addEventMFWModalPopUp() {
    if (typeof window.addEventListener != 'undefined') {
        window.addEventListener("resize", resizeAllMFWModalPopUp, false);
        window.addEventListener("scroll", resizeAllMFWModalPopUp, false);
    } else if (typeof document.addEventListener != 'undefined') {
        document.addEventListener("resize", resizeAllMFWModalPopUp, false);
        document.addEventListener("scroll", resizeAllMFWModalPopUp, false);
    } else if (typeof window.attachEvent != 'undefined') {
        window.attachEvent("onresize", resizeAllMFWModalPopUp);
        window.attachEvent("onscroll", resizeAllMFWModalPopUp);
    }
}

function resizeAllMFWModalPopUp() {
    for(var index = 0; index < MFWModalPopUpManagerObj.popUps.length; index++) {
        MFWModalPopUpManagerObj.popUps[index].resize();
    }
}

var MFWModalPopUpManagerObj = new MFWModalPopUpManager();
addEventMFWModalPopUp();


function MFWModalPopUp(objectId) {
    this.overlayObject = document.getElementById(objectId);
    this.caseObject = document.getElementById(objectId + "-case");
    MFWModalPopUpManagerObj.add(this);
}


MFWModalPopUp.prototype.resize = function() {
    var arrayPageSize = getPageSize();
    var scroll = getPageScroll();
    this.overlayObject.style.height = ((arrayPageSize[1] + scroll[1] )+ 'px');
    this.overlayObject.style.width = ((arrayPageSize[0] + scroll[0] )+ 'px');

    this.caseObject.style.marginTop = (scroll[1] + 10) + "px";

}

MFWModalPopUp.prototype.show = function() {
    this.resize(this);
	this.overlayObject.style.display = '';
	this.caseObject.style.display = '';
}

MFWModalPopUp.prototype.hide = function() {
    this.overlayObject.style.display = "none";
}

function getPageScroll() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getPageSize() {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    arrayPageSize = new Array(myWidth,myHeight);
    return arrayPageSize;
}


