// esempio d'uso: preload('prima.gif', 'seconda.gif', 'terza.gif');

function preload() {
	if (!document.images) return;
	var wl = new Array();
	var arguments = preload.arguments;
	for (var i = 0; i < arguments.length; i++) {
		wl[i] = new Image();
		wl[i].src = arguments[i];
	}
}

function changeImage(id, src) {
	image = document.getElementById(id);
	image.src = src;
}


function getScroll() {
  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;
}

function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

var iFrame;
var popupShowed = false;

function showPopup() {
    if (!popupShowed) {
        popupShowed = true;
        popup = document.getElementById('popup_box');
        // ricreo
        popup.style.display = 'block';
        posY = getScroll() + ((getHeight() - 200)/2)
        popup.style.top = posY  + 'px';
        iFrame = document.createElement("iframe");
        iFrame.setAttribute("src", "");
        iFrame.setAttribute("frameborder", "0");
        //Match IFrame position with divPopup
        iFrame.style.position="absolute";
        iFrame.style.top = popup.offsetTop + 'px';
        iFrame.style.width = popup.offsetWidth + 'px';
        iFrame.style.height = popup.offsetHeight + 'px';
        iFrame.style.marginLeft = "-150px";
        document.body.appendChild(iFrame);
    }
}

function hidePopup() {
    if (popupShowed) {
        popup = document.getElementById('popup_box');    
        popup.style.display = 'none';
        if (iFrame) {
            document.body.removeChild(iFrame);
        }
        popupShowed = false;
    }
}