var strLastQm = new String();
var strQIds = new Array();
var colQms = new Array();
var sQm = new Object();
var sNode = new Object();
var n = new Number(0);
var i = new Number(0);
var midWidthMin = new Number(5);
var midWidthMax = new Number(65); //same as in css
var midWidthCur = new Number(midWidthMin); // the mid.width set in Main()
var midHeightMin = new Number(5); 
var midHeightMax = new Number(98); //same as in css
var midHeightCur = new Number(midHeightMin); // the mid.height set in Main()
var midTopMin = new Number(0);  //same as in css
var midTopMax = new Number(46);// the mid.top set in Main()
var midTopCur = new Number(midTopMax); 
var midLeftMin = new Number(17);  //same as in css
var midLeftMax = new Number(46); // the mid.left set in Main()
var midLeftCur = new Number(midLeftMax); 

function isThere(what) {
 return ((typeof what!="undefined")&&(what!=null));
}

function swapStyle(id,prop,val) {
 sNode = document.getElementById(id);
  if (isThere(sNode)) {
  if (isThere(sNode.style)) {
   if (isThere(sNode.style[prop])) {
    sNode.style[prop] = val;
    return (sNode.style[prop]==val);
   }
  }
 }
 return true;
}

function swapQmStyle(which,prop,val) {
 sQm =colQms["qm"+which];
  if (isThere(sQm)) {
  if (isThere(sQm.style)) {
   if (isThere(sQm.style[prop])) {
    //alert(which + ", " + prop + " := " + val + " Hello!");
    sQm.style[prop] = val;
    //window.status = sQm.id + "." + prop + " := " + val + " = " + sQm.style[prop];
    return (sQm.style[prop]==val);
   }
  }
 }
 return true;
}

function showQm(which) {
 if (n>0) {
  if (strLastQm.toString()!=which.toLowerCase()) {
   strLastQm = which.toLowerCase();
   for(i=n;i>=0;i--) {
    if (which==strQIds[i]) {
     swapQmStyle(strQIds[i],'display','block');
     swapQmStyle(strQIds[i],'zIndex','100');
    } else {
     swapQmStyle(strQIds[i],'zIndex','1');
     swapQmStyle(strQIds[i],'display','none');
    }
   }
  }
  return true;
 } else {
  return false;
 }
}

function setMidCurSize() {
  swapStyle("mid","left",midLeftCur+"%"); 
  swapStyle("mid","top",midTopCur+"%");
  swapStyle("mid","width",midWidthCur+"%");
  swapStyle("mid","height",midHeightCur+"%");
  return true;
}


function fullyOpen() {
  midLeftCur=midLeftMin;
  midTopCur=midTopMin;
  midWidthCur=midWidthMax;
  midHeightCur=midHeightMax;
  return setMidCurSize();
}

function animateOpen() {
 if (isThere(document.getElementById)) {
  if (midWidthCur<midWidthMax) {
    midLeftCur=midLeftCur-(5);
    midTopCur=midTopCur-(7.5);
    midWidthCur=midWidthCur+(10);
    midHeightCur=midHeightCur+(15);
    window.setTimeout(setMidCurSize,2);
    return window.setTimeout(animateOpen,1);
  } else {
    return fullyOpen();
  }
 }
 return true;
}

function animateClose() {
 if (isThere(document.getElementById)) {
 if (midWidthCur>midWidthMin) {
    midLeftCur=midLeftCur+(10);
    midTopCur=midTopCur+(15);
    midWidthCur=midWidthCur-(20);
    midHeightCur=midHeightCur-(30);
    window.setTimeout(setMidCurSize,2);
    return window.setTimeout(animateClose,1);
  }}
  return true;
}

function Main() {
 if (isThere(document.getElementById)) {
  midLeftCur=midLeftMax;
  midTopCur=midTopMax;
  midWidthCur=midWidthMin;
  midHeightCur=midHeightMin;
  window.setTimeout(setMidCurSize,2);
  strQIds = Array("l","c","m","w");
  n = strQIds.length - 1;
  colQms.length=n;
  for (i=n;i>=0;i--) {
   colQms["qm"+strQIds[i]]=document.getElementById("qm"+strQIds[i]);
  }
 }
 return (n>0);
}