function centerWindow(element) {
     if($(element) != null) {
          if(typeof window.innerHeight != 'undefined') {
               $(element).style.top = 
                    Math.round(document.viewport.getScrollOffsets().top + 
                    ((window.innerHeight - $(element).getHeight()))/2)+'px';
               $(element).style.left = 
                    Math.round(document.viewport.getScrollOffsets().left + 
                    ((window.innerWidth - $(element).getWidth()))/2)+'px';
          } else {
               $(element).style.top = 
                    Math.round(document.body.scrollTop + 
                    (($$('body')[0].clientHeight - $(element).getHeight()))/2)+'px';
               $(element).style.left = 
                    Math.round(document.body.scrollLeft + 
                    (($$('body')[0].clientWidth - $(element).getWidth()))/2)+'px';
          }
     }
}	

function makeVisible() {
	$('fade').style.display = "block"
}

function makeInvisible(){
	$('fade').style.display = "none";
}

function showLayer(id){
	$(id).style.display="block";
}

function hideLayer(id){
	$(id).style.display="none";
}

function fadeBg(userAction,whichDiv){
	if(userAction=='close'){
		new Effect.Opacity('fade',
				   {duration:.5,
				    from:0.2,
				    to:0,
				    afterFinish:makeInvisible(),
				    afterUpdate:hideLayer(whichDiv)});
	}else{
		new Effect.Opacity('fade',
				   {duration:.5,
				    from:0,
				    to:0.2,
				    beforeUpdate:makeVisible(),
				    afterFinish:showLayer(whichDiv)});
	}
}

function fadeBg(userAction, whichDiv) {
	if (userAction == 'close') {
		makeInvisible();
		hideLayer(whichDiv);
	} else {
		makeVisible();
		showLayer(whichDiv);
	}
}

function openPopup(id) {
	fadeBg('open', id);
}

function closePopup(id) {
	fadeBg('close', id);
}

