ihmbox_open = false;
function ihm_box(url,onfinish) {
	if (!document.getElementById('ihmbox_overlay')) {return;}
	ihmbox = document.getElementById('ihmbox_overlay');
	box_content = document.getElementById('ihmbox_content');
	if (!ihmbox_open) {
		ihmbox.style.zIndex = 9998;
		box_content.style.zIndex = 9999;
		ihmbox.style.left = "0px";
		ihmbox.style.top = "0px";
		overlaySize();
		ihmbox.style.display = '';
		box_content.style.display = '';
		new Effect.Opacity('ihmbox_overlay',{duration:0.1,from:0.01,to:0.65});
		if (onfinish > '') {
			req(url,'ihmbox_content','ihmbox_loading','ihmbox',onfinish);
		} else {
			req(url,'ihmbox_content','ihmbox_loading','ihmbox','');
		}
	} else {
		req(url,'ihmbox_content','ihmbox_loading','ihmbox','');
	}
	ihmbox_open = true;
	window.onscroll = maintPos;
	window.onresize = maintPos;
}
function screenSize(what) {
	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;
	}
	if (what == "width") {
		return myWidth;
	} else {
		return myHeight;
	}
}
getScrollPos = function() {
	var docElem = document.documentElement;
	this.scrollX = self.pageXOffset || (docElem&&docElem.scrollLeft) || document.body.scrollLeft;
	this.scrollY = self.pageYOffset || (docElem&&docElem.scrollTop) || document.body.scrollTop;
}

getPageSize = function() {
	var docElem = document.documentElement
	this.width = self.innerWidth || (docElem&&docElem.clientWidth) || document.body.clientWidth;
	this.height = self.innerHeight || (docElem&&docElem.clientHeight) || document.body.clientHeight;
}

getElementSize = function(elem) {
	this.width = elem.offsetWidth ||  elem.style.pixelWidth;
	this.height = elem.offsetHeight || elem.style.pixelHeight;
}
getScrollHeight = function() {
   var h = window.pageYOffset ||
		   document.body.scrollTop ||
		   document.documentElement.scrollTop;
		   
   return h ? h : 0;
}
getScrollWidth = function() {
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 
maintPos = function() {
	scrollYoffset = getScrollHeight();
	scrollXoffset = getScrollWidth();
	w = screenSize('width')+scrollXoffset;
	h = screenSize('height')+scrollYoffset;
	ihmbox.style.width = w+"px";
	ihmbox.style.height = h+"px";
	posToCenter(box_content);
}
function overlaySize() {
	elem = document.getElementById('ihmbox_overlay');
	scrollYoffset = getScrollHeight();
	scrollXoffset = getScrollWidth();
	w = screenSize('width')+scrollXoffset;
	h = screenSize('height')+scrollYoffset;
	elem.style.width = w+"px";
	elem.style.height = h+"px";
}
posToCenter = function(elem) {
	var scrollPos = new getScrollPos();
	var pageSize = new getPageSize();
	var emSize = new getElementSize(elem);
	var x = Math.round(pageSize.width/2) - (emSize.width /2) + scrollPos.scrollX;
	var y = Math.round(pageSize.height/2) - (emSize.height /2) + scrollPos.scrollY;	
	elem.style.left = x+'px';
	elem.style.top = y+'px';	
}

function hideIhmbox() {
	ihmbox = document.getElementById('ihmbox_overlay');
	box_content = document.getElementById('ihmbox_content');
	new Effect.Opacity('ihmbox_content',{duration:0.1,from:0.65,to:0.01});
	//new Effect.Opacity('ihmbox_overlay',{duration:0.2,from:0.6,to:0.01});
	setTimeout("ihmbox.style.display = 'none';",220);
	setTimeout("box_content.style.display = 'none';",320);
	ihmbox_open = false;
	window.onscroll = null;
}
