function switchSubmenu(n,elt) {
  var div = document.getElementById('submenu');
  div.innerHTML=submenus[n];
  div.style.padding="0px 0px 0px "+menuwidths[n]+"px";

  if (window.SMobj) { SMobj.className = ""; }

  if (elt != null) { 
    SMobj=elt; 
    SMobj.className = "highlight";
  } else {
    SMobj=null;
  }
  str="";
  for (var p in SMobj) { 
    if (typeof(SMobj[p])!="function") {
      //if (typeof(SMobj[p])!="object") { str+=SMobj[p]; } 
      //if (p=="href"||p=="style"||p=="className") { 
      str += p+"=";
	str+=SMobj[p]; 
      str += ",  "; 
      //str += "\n"; 
      //} 
      //else { str+=typeof(SMobj[p]); }
    }
  }
  //alert(elt+"\n"+SMobj+"\n"+typeof(SMobj)+"\n"+str);
  //alert(SMobj.className);
}

function resetSubmenu(imgobj, src, count) {
  // Initialize count to the number of seconds to wait
  // This is the default timeout for the timer, measured in seconds:
  if (count==null) { count = 30; }
  if (imgobj!=null && src!="") {
    imgFix();
    img=imgobj;
    imgsrc=src;
  }
  if (stopped=='sub' && src=='div') { return false; }
  if (src!="") { cmd = "imgFix(); switchSubmenu(0);"; }
  else { cmd = "switchSubmenu(0);"; }
  timer = setTimeout(cmd,count*1000);
}

function imgFix() {
  if (imgsrc!="") {
    img.src=imgsrc;
    //alert("fixing "+imgsrc);
    img=null;
    imgsrc="";
  }
}

function stopTime(name) { clearTimeout(timer); stopped=name; }

function preloadMenuImages() {
  document.preloaded=new Array();
  for (var n=0; n < preload.length; n++) {
    document.preloaded[n] = new Image;
    document.preloaded[n].src = preload[n];
  }
}

function showPortImg(id,n) {
  width=400;
  height=400;
  str="";
  if (n>1) { str="&n="+n; }
  return window.open("popup.php?port="+id+str,'port',
		     "width="+(width+20)+",height="+(height+100));
}
function showInstImg(id) {
  width=300;
  height=300;
  return window.open("popup.php?inst="+id,'inst',
		     "width="+(width+20)+",height="+(height+100));
}
function showContImg(id, yr) {
  width=500;
  height=500;
  return window.open("popup.php?cont="+id+"&contyr="+yr,'cont',
		     "width="+(width+20)+",height="+(height+100));
}
function showFiniImg(id) {
  width=400;
  height=400;
  return window.open("popup.php?fini=1&n="+id,'fini',
		     "width="+(width+20)+",height="+(height+100));
}
function showFurnImg(id,n) {
  width=350;
  height=350;
  str="";
  if (n>1) { str="&n="+n; }
  return window.open("popup.php?furn="+id+str,'furn',
		     "width="+(width+20)+",height="+(height+100));
}
function showDigImg(id,n) {
  width=400;
  height=400;
  str="";
  if (n>1) { str="&n="+n; }
  return window.open("popup.php?dig="+id+str,'dig',
		     "width="+(width+20)+",height="+(height+100));
}
function showGlassImg(id,n) {
  width=650;
  height=650;
  str="";
  if (n>1) { str="&n="+n; }
  window.open("popup.php?glass="+id+str,'glass',
	      "width="+(width+20)+",height="+(height+100));
  // Used as an href in flash - don't return anything
  return;
}
function showHwImg(id) {
  width=300;
  height=300;
  return window.open("popup.php?hw="+id,'inst',
		     "width="+(width+20)+",height="+(height+150));
}
function showArchImg(id,phase) {
  width=300;
  height=300;
  return window.open("popup.php?arch="+id+'_'+phase,'arch',
		     "width="+(width+20)+",height="+(height+100));
}
function showImg(src,winname,width,height,other) {
  return window.open("popup.php?src="+src,winname,
		     "width="+(width+20)+",height="+(height+40)+","+other);
}

function showVideo(src,winname,width,height,other) {
  return window.open("popup2.php?src="+src,winname,
		     "width="+(width+20)+",height="+(height+60)+","+other);
}

function showFlash(fla,winname,width,height,other) {
  return window.open("popup2.php?fla="+fla+"&width="+width+"&height="+height,winname,
	             "width="+(width+20)+",height="+(height+60)+","+other);
}

function showCapiz(capiz_id,order_id,size) {
  return window.open("popup2.php?capiz_id="+capiz_id+"&order_id="+order_id+
		     "&size="+size,'capizwin',"width="+(size+20)+
		     ",height="+(size+60));
}

function popup(num) {
  // used by the portolio page
  // Don't return, because it's in an href, not onclick
  showImg("portfolio/pics/p_lg/p_lg_"+num+".jpg","popup",500,500);
}

function toggleDisplay(elmt) {
  if (elmt.style.display!="none") { elmt.style.display="none"; }
  else { elmt.style.display="block"; }
  return false;
}

function getDivHeight(div) {
  var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
  if(rslt != null) {
    return div.offsetHeight;
  } else {
    return div.clientHeight;
  }
}

function getElementsByStyleClass(className) {
  var all = document.all ? document.all :
    document.getElementsByTagName('*');
  var elements = new Array();
  for (var e = 0; e < all.length; e++)
    if (all[e].className == className)
      elements[elements.length] = all[e];
  return elements;
}

function blockWinElm() {
  var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
  if(rslt != null) {
    var hide = getElementsByStyleClass('hide');
    for(var i = 0; i < hide.length; i++) {
      var d = hide[i];
      if(d != null) {
	d.style.visibility = 'hidden';
      }
    }
  }
}

function unblockWinElm() {
  var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
  if(rslt != null) {
    var hide = getElementsByStyleClass('hide');
    for(var i = 0; i < hide.length; i++) {
      var d = hide[i];
      if(d != null) {
	d.style.visibility = 'visible';
      }
    }
  }
}

function setStarVote(vote, idbase) {
  for(var i = 1; i <= vote; i++) {
    var theid = idbase + '_' + i;
    document.getElementById(theid).src = "images/contest06/red_star.gif";
  }
  if(i == 0) { i = 1; }
  for(; i <= 5; i++) {
    var theid = idbase + '_' + i;
    document.getElementById(theid).src = "images/contest06/gray_star.gif";
  }
}
