var TICM_=new Object();
TICM_.na = parseFloat(navigator.appVersion);	
TICM_.napN = navigator.appName.toLowerCase();
TICM_.nu = navigator.userAgent.toLowerCase();

TICM_.isIE=((TICM_.nu.indexOf("msie")!=-1)&&(TICM_.nu.indexOf("opera")==-1))?true:false;
TICM_.isOpera=(TICM_.nu.indexOf("opera")!=-1)?true:false;
TICM_.isGecko=(TICM_.nu.indexOf("gecko")!=-1)?true:false;
TICM_.isDom = document.getElementById?true:false;
TICM_.GeckoMinor=TICM_.isGecko?TICM_.nu.slice(TICM_.nu.indexOf("rv:")+3,TICM_.nu.indexOf("rv:")+8):0;
TICM_.ieMajor=TICM_.isIE?parseInt(TICM_.nu.slice(TICM_.nu.indexOf("msie")+4)):0;
TICM_.isFirefox=(TICM_.nu.indexOf("firefox/")!=-1);
TICM_.firefoxMajor=TICM_.isFirefox?parseInt(TICM_.nu.slice(TICM_.nu.indexOf("firefox/")+8)):0;
TICM_.isSafari=(TICM_.nu.indexOf("safari")!=-1);
TICM_.safariMajor=TICM_.isSafari?parseInt(TICM_.nu.slice(TICM_.nu.indexOf("version/")+8)):0;

TICM_.macX=(TICM_.nu.indexOf("mac os x")!=-1);
TICM_.isWin=(TICM_.nu.indexOf("win")!=-1)?true:false;
TICM_.isWin98=(TICM_.nu.indexOf("windows nt")!=-1)?true:false;
TICM_.isWinNT=(TICM_.nu.indexOf("windows 98")!=-1)?true:false;
TICM_.win2000=(TICM_.nu.indexOf("windows nt 5.0")!=-1)?true:false;
TICM_.winXP = (TICM_.nu.indexOf("windows nt 5.1")!=-1);
TICM_.winXPx64 = (TICM_.nu.indexOf("windows nt 5.2")!=-1);  // and also windows server 2003
TICM_.winVista = (TICM_.nu.indexOf("windows nt 6.0")!=-1);

TICM_.now = new Date();

TICM_.goodClient = ((TICM_.win2000||TICM_.winXP||TICM_.winXPx64||TICM_.winVista||TICM_.macX) && (TICM_.ieMajor>=6||TICM_.firefoxMajor>=3||TICM_.safariMajor>=3));

function TICM_setWidth(w){
	if(TICM_.winVista){
		return TICM_.isIE ? w+1 : w-3;
	}
	return TICM_.isIE ? w : w-4;
}

TICM_.pLeft = -478;
TICM_.pTop = 50;
TICM_.height = 305;
TICM_.width = TICM_setWidth(620);
TICM_.layerZindex = 10000;
TICM_.ofipURL = "http://subs.realsimple.com/subs2/prodhtml/SM/sm_ofip0309.html?"+TICM_.now.valueOf();
TICM_.frameBorderColor = "#f5a90b";

function closeFofie() {
	document.body.removeChild(TICM_.ofieDiv);		
 	window.clearInterval(TICM_.t1);
}



function TICM_makeFormLayer(argString,formURL){ 

  var argArray = argString.split(",");
  var xPos = argArray[0]; 
  var yPos = argArray[1];
  var lWidth = argArray[2]; 
  var lHeight = argArray[3]; 
  var lzIndex = argArray[4];

  TICM_.ofieDiv = document.createElement("div");
  TICM_.ofieDiv.setAttribute("id", "P_popupInLayer");
  TICM_.ofieDiv.style.position = "absolute";
  TICM_.ofieDiv.style.left = xPos + "px";
  TICM_.ofieDiv.style.top = yPos + "px";
  TICM_.ofieDiv.style.zIndex = lzIndex;		
  TICM_.ofieDiv.style.backgroundColor = TICM_.frameBorderColor;
  TICM_.ofieDiv.style.padding = "2px";
  TICM_.ofieDiv.style.textAlign = "right";
  TICM_.ofieDiv.style.display = "block";
  TICM_.ofieDiv.style.clip = "rect(0px 0px 0px 0px)";
		
  var topbarImg = document.createElement("img");
  topbarImg.src = "http://i.timeinc.net/subs2/images/shared/close_off.gif";
  topbarImg.style.width = "21px";
  topbarImg.style.height = "21px";
  topbarImg.style.border = "0px";
  topbarImg.style.float = "none";

  var anchor1 = document.createElement("a");
  anchor1.href = "javascript:closeFofie()";
  anchor1.appendChild(topbarImg);
  TICM_.ofieDiv.appendChild(anchor1);

  TICM_.iframe1 = document.createElement("iframe");	
  TICM_.iframe1.setAttribute("id", "ifP"+TICM_.now.valueOf());		
  TICM_.iframe1.src = formURL;
  TICM_.iframe1.style.width = lWidth+"px";
  TICM_.iframe1.style.height = lHeight+"px";
  TICM_.iframe1.style.marginTop = "2px";
  TICM_.iframe1.style.backgroundColor = "#ffffff";
  TICM_.iframe1.style.display = "block";
  TICM_.iframe1.style.visibility = "visible";
  TICM_.iframe1.scrolling = "auto";

  TICM_.ofieDiv.appendChild(TICM_.iframe1);
  window.document.body.appendChild(TICM_.ofieDiv);
  var CM_t2 = window.setTimeout('TICM_displayOFIP();',1000);
}


function TICM_displayOFIP(){
	if(TICM_.iframe1.style.visibility == "visible"){
		TICM_reveal(TICM_.ofieDiv,50,0,0);
	}

	else closeFofie();
}

function TICM_finishOpen(){
	
	try{if(/realsimple\.com$/.test(document.domain))document.domain = "realsimple.com";}catch(error){}
}

function TICM_reveal(o,speed,lgSh,smSh){
	var w = o.offsetWidth;
	var h = o.offsetHeight;
	var smD,lgD,lgStep;
	var aspect = "";
	if(h==w){
		aspect = "s";
		smD = lgD = h;	
	}
	else {
		aspect = h > w ? "v": "h"; 
		smD = Math.min(h,w);
		lgD = Math.max(h,w);
	}

	lgStep = lgD/(smD/2);

	var top, right, bottom, left;
	
	if(aspect == "h"){
		top = Math.round((smD/2)-smSh);
		right = Math.round((lgD/2)+lgSh);
		bottom = Math.round((smD/2)+smSh);
		left = Math.round((lgD/2)-lgSh);
	}else if(aspect == "v"){
		left = Math.round((smD/2)-smSh);
		bottom = Math.round((lgD/2)+lgSh);
		right = Math.round((smD/2)+smSh);
		top = Math.round((lgD/2)-lgSh);
	}else if(aspect == "s"){
		left = top = Math.round((smD/2)-smSh);
		bottom = right = Math.round((lgD/2)+lgSh);
	}

	o.style.clip = "rect("+top+"px "+right+"px "+bottom+"px "+left+"px)";
	if(top < 0){TICM_finishOpen();return;}
	
	lgSh+=(lgStep/2)*speed;
	smSh+=(1)*speed;
	setTimeout('TICM_reveal(TICM_.ofieDiv,'+speed+','+lgSh+','+smSh+');',25);
}


function TICM_init(){
	TICM_.positioning = Math.max(((TICM_.isIE ? document.documentElement.clientWidth || document.body.clientWidth : window.innerWidth)/2 + TICM_.pLeft),0) + "," + Math.max((((TICM_.isIE ? document.documentElement.clientHeight || document.body.clientHeight : window.innerHeight) - TICM_.height-25)*TICM_.pTop/100) + (document.documentElement.scrollTop || document.body.scrollTop),185);
	TICM_.formLayerArgs = TICM_.positioning+","+TICM_.width+","+TICM_.height+","+TICM_.layerZindex;
	TICM_makeFormLayer(TICM_.formLayerArgs,TICM_.ofipURL);
}

function TICM_addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

if (TICM_.goodClient){
	TICM_addEvent(window, 'load', TICM_init);
}




