var FS_BGMaskID = 'BackgroundMask';
var FS_FlashID  = '';
var FS_OldResizeEvent = null;
var FS_OldScrollEvent = null;

function FS_CreateBackgroundMask(){
	
}

function FS_ResizeEvent(){
	FS_ResizeMask();
	if (FS_OldResizeEvent != null){
		FS_OldResizeEvent();
	}
}

function FS_ScrollEvent(){
	FS_ResizeMask();
	if (FS_OldScrollEvent != null){
		FS_OldScrollEvent();
	}
}

function FS_ResizeMask(){
	var el = document.getElementById(FS_BGMaskID);
	if (el){
		el.style.width = Math.round(document.body.clientWidth) + Math.round(document.body.scrollLeft);
		el.style.height = Math.round(document.body.clientHeight) + Math.round(document.body.scrollTop);
	}
	
	if (FS_FlashID != ''){
		el = document.getElementById(FS_FlashID);
		if (el){
			FS_CenterElement(el);
		}
	}
}

function FS_CenterElement(el){
	var left = Math.round((document.body.clientWidth - el.offsetWidth) / 2) + Math.round(document.body.scrollLeft);
	var top = Math.round((document.body.clientHeight - el.offsetHeight) / 2) + Math.round(document.body.scrollTop);
	if (left < 0) left = 0;
	if (top < 0) top = 0;

	el.style.left = left;
	el.style.top = top;
}

function FS_ShowMask(){
	var el = document.getElementById(FS_BGMaskID);
	if (!el){
		el = document.createElement('div');
		el.style.cssText = "background-color:#000000; top:0; left:0; position:absolute; filter:Alpha(Opacity=40);";
		el.innerHTML = "";
		el.id = FS_BGMaskID;
		document.body.insertAdjacentElement('afterBegin', el);
		el.onclick = function(){ FlashHide(FS_FlashID); };
	}

	if (el){
		FS_ResizeMask();
		el.style.display = "block";
		el.style.zIndex = 500;
		
		if (document.body.onresize != FS_ResizeEvent){
			FS_OldResizeEvent = document.body.onresize;
			document.body.onresize = FS_ResizeEvent;
		}
		
		if (document.body.onscroll != FS_ScrollEvent){
			FS_OldScrollEvent = document.body.onscroll;
			document.body.onscroll = FS_ScrollEvent;
		}
	}
}

function FS_HideMask(){
	var el = document.getElementById(FS_BGMaskID);
	if (el){
		el.style.display = "none";
		if (FS_OldResizeEvent)
			document.body.onresize = FS_OldResizeEvent;
		if (FS_OldScrollEvent)
			document.body.onscroll = FS_OldScrollEvent;
		FS_OldResizeEvent = null;
		FS_OldScrollEvent = null;
	}
}




function FlashShow(id){
	var el = document.getElementById(id);
	if (el){
		var el = el.removeNode(true);
		document.body.insertAdjacentElement('afterBegin', el);
		FS_FlashID = id;
		el.style.position = "absolute";
		el.style.visibility = "hidden";
		el.style.display = "block";
		el.style.zIndex = 1000;
		FS_CenterElement(el);
		FS_ShowMask();
		el.style.visibility = "visible";
		el.onclick = function(){ FlashHide(FS_FlashID); };
	}
}

function FlashHide(id){
	var el = document.getElementById(id);
	if (el){
		FS_FlashID = '';
		el.style.display = "none";
		FS_HideMask();
	}
}