function closeMyPopup() {
  document.getElementById("mypopup").style.display = "none";
}

////////////////////////////////////////////////
// Browser safe opacity handling function
////////////////////////////////////////////////
function setOpacity( value ) {
	document.getElementById("mypopup").style.opacity = value / 10;
	document.getElementById("mypopup").style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup() {
	for( var i = 0 ; i <= 100 ; i++ )
		setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );
}

function fadeOutMyPopup() {
	for( var i = 0 ; i <= 100 ; i++ ) {
		setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
	}

	setTimeout('closeMyPopup()', 800 );
}
////////////////////////////////////////////////

////////////////////////////////////////////////
// Relocate popup function
////////////////////////////////////////////////
function myPopupRelocate() {
 var scrolledX, scrolledY;
 if( self.pageYOffset ) {
   scrolledX = self.pageXOffset;
   scrolledY = self.pageYOffset;
 } else if( document.documentElement && document.documentElement.scrollTop ) {
   scrolledX = document.documentElement.scrollLeft;
   scrolledY = document.documentElement.scrollTop;
 } else if( document.body ) {
   scrolledX = document.body.scrollLeft;
   scrolledY = document.body.scrollTop;
 }

 // We just add the scrolled amount to 5 (the desired padding)
 // to find the new coordinates

 var leftOffset = scrolledX + 5;
 var topOffset = scrolledY + 5;

 document.getElementById("mypopup").style.top = topOffset + "px";
 document.getElementById("mypopup").style.left = leftOffset + "px";
}
////////////////////////////////////////////////

////////////////////////////////////////////////
// Show popup : here opacity is used, relocate is not
////////////////////////////////////////////////
function fireMyPopup() {
/*  myPopupRelocate();*/
	setOpacity( 0 );
  	document.getElementById("mypopup").style.display = "block";
 	fadeInMyPopup(); 
/*    document.body.onscroll = myPopupRelocate; */
/*  window.onscroll = myPopupRelocate; */
/*  window.setTimeout("closeMyPopup()", 10000); */
}

////////////////////////////////////////////////
// Show popup with delay. Call this onLoad
////////////////////////////////////////////////
function delay() {
	window.setTimeout("fireMyPopup()", 2500);
}

