/* general.js */

/*Global variables: */
var pos;
var timerId;
var topPos;
var lycosInc=0;
var memoTab;
var popupWin = null;

window.onload=checkLycos;
window.onfocus=closeChild;

function closeChild() {
	if (popupWin != null && popupWin.open) popupWin.close();
}

function openWin(url,w,h){
	w=screen.availWidth  - (screen.availWidth/100*20);
	h=screen.availHeight - (screen.availHeight/100*30);
	paras="width="+w+",height="+h+",status=1,scrollbars=1";
	popupWin = window.open(url,"Win",paras);
	window.name = 'opener';
}

function checkLycos() { 
	if(window.location.href.indexOf('lycos')!=-1) {
		document.getElementById("LycosDiv").style.height="115px";
		lycosInc=115;
	}
}

/* direction=left/right; memo=popout No.; cell=row No. popout is to appear on  */
function slide(direction,memo,cell) {
   clearInterval(timerId);
   for(i=1;i<35;i++) {
	  i<10 ? memoTab="memo0"+i : memoTab="memo"+i;
	  setMemostatus('hidden');
   }
   memo<10 ? memoTab="memo0"+memo : memoTab="memo"+memo; //alert(lycosInc);
   switch(cell) {
	  case 1: topPos=116; if(lycosInc!=0)topPos+=lycosInc;break;
	  case 2: topPos=380; if(lycosInc!=0)topPos+=lycosInc;break;
	  case 3: topPos=700; if(lycosInc!=0)topPos+=lycosInc;break;
	  case 4: topPos=1020; if(lycosInc!=0)topPos+=lycosInc;break;
	  case 5: topPos=1340; if(lycosInc!=0)topPos+=lycosInc;break;
		}
   
   setMemostatus('visible');
   if(direction=='left') {
	  pos=0;
	  timerId=setInterval("setPosn('left')",30)
   } else {
	  pos=-300;
	  timerId=setInterval("setPosn('right')",15	)
   }
}

function setMemostatus(state) {
		 document.getElementById(memoTab).style.visibility=state;}

function setPosn(direction) { 
   direction=='left' ? pos=pos-40 : pos=pos+40;
   moveMemo();
   if(direction=='left' && pos <= -300) {
	  clearInterval(timerId);
	  pos=-310;  //final resting point
	  moveMemo();
   }
	  if(direction=='right' && pos >= 0) {
	  clearInterval(timerId);
	  pos=0;
	  moveMemo();
   }
}

function moveMemo() {
	document.getElementById(memoTab).style.top=topPos+'px'; 
	document.getElementById(memoTab).style.left=pos+'px'; 
}


