var fadeOpacityChange = 10;
var fadeTimeInterval = 1;

function closeGreyOut(popupId){
	greyOutFadeIn(60,60, popupId,fadeTimeInterval);
}
function openGreyOut(obj, popupId){
	var r = getAbsolutePosition(obj);
	var ycoord = r.y;
	
	var popupObj = activateCenter(popupId);
	
	popupObj.style.top = (ycoord-250)+'px';
	
	var greyOut = document.getElementById('greyOut');
	greyOut.style.height = document.body.clientHeight+'px';
	greyOut.style.display = "block";
	fadeOut(60,60, 'greyOut',fadeTimeInterval);
}
  function getAbsolutePosition(element) {
    var r = { x: element.offsetLeft, y: element.offsetTop };
    if (element.offsetParent) {
      var tmp = getAbsolutePosition(element.offsetParent);
      r.x += tmp.x;
      r.y += tmp.y;
    }
    return r;
  };
function activateCenter(popupId){
	var popupObj = document.getElementById(popupId);
	popupObj.style.display = "block";
	popupObj.style.left = Math.floor((document.body.clientWidth-500)/2)+'px';
	return popupObj;
}
function greyOutFadeIn(next, limit, popupId, rate){
	var obj = document.getElementById("greyOut");
	next = eval(next);
	fadeObj(next, obj);
	if(next>limit){
		setTimeout("greyOutFadeIn("+(next-fadeOpacityChange)+", "+limit+", '"+popupId+"', "+rate+")",rate);
	}else{	
		obj.style.display="";
		var popupObj = document.getElementById(popupId);
		popupObj.style.display="";
	}
}




function fadeIn(next, limit, id, rate, doneFunc){
	var obj = document.getElementById(id);
	next = eval(next);
	fadeObj(next, obj);
	if(next>limit){
		setTimeout("fadeIn("+(next-fadeOpacityChange)+", "+limit+", '"+id+"', "+rate+", "+doneFunc+")",rate);
	}else if(doneFunc){
		doneFunc();	
	}
}
function fadeOut(next, limit, id, rate){
	var obj = document.getElementById(id);
	next = eval(next);
	fadeObj(next, obj);
	if(next<limit){
		setTimeout("fadeOut("+(next+fadeOpacityChange)+", "+limit+", '"+id+"', "+rate+")",rate);
	}
}
function fadeObj(next, obj){
	obj.style.filter="alpha(opacity="+next+")";
	obj.style.opacity=next/100;
	obj.style.background="#222222";
}