var globals = { title_on: false, text_on: false };
var bgimages = new Array("camel-4.gif", "beach2.gif", "sotticon.gif",
                      "victoria.jpg", "hfly-0.jpg", "catlogo2.jpg",
                      "SelfPortrait.jpg","reading.jpg", 
                      "CycladicFig.jpg","bigq_code.jpg",
                       "globe-11a.jpg", "cs_logo.jpg", "" );

var imgSizes = new Array(
      {w:217, h:139},   {w:210, h: 216}, {w:250, h: 152}, {w: 384, h: 305},
      {w: 324, h: 260}, {w: 212, h: 174}, {w: 306, h: 400}, {w: 300, h: 226 },
      {w: 161, h: 215 },{w: 350, h: 259 }, {w: 220, h: 169 }, {w: 398, h: 312 },
      {}
        
 );


var ic = 0;
var imgArray = new Array();
var imagesLoaded = false;
function loadImages() {
    if(imagesLoaded) return;

    for(var i=0; i < bgimages.length; i++) {     
         setupImage(i);         
  }

}


var IMAGES_TO_LOAD_MIN = 15;
var NUMBER_OF_IMAGES = bgimages.length -1;

function setupImage(i) {
        
      imgArray[i] = new Image(imgSizes[i].w,imgSizes[i].h);
      imgArray[i].src = bgimages[i];
      imgArray[i].isloaded = false;
      imgArray[i].onload = function() {       
        imgArray[ic].isloaded = true;        
        ic++;               
        if(ic == NUMBER_OF_IMAGES -1) {
           imagesLoaded = true;
          }        
       };
}




function NS4Message() {
   if(document.layers) {
    var msgW = window.open("","msg","width=500,height=400");
    writeBasicCSS(msgW.document);
    writeBasicBodyTag(msgW.document);
    msgW.document.write('<div class="text">');
     msgW.document.write( "A note for users of Netscape 4.x.:\n" +  
      "While you should have no problems viewing this web site\n"+
      "its implementation of an image dissolve feature is not supported by Netscape 4.x. " +
      "For this you need either Netscape 6 (or later) or Internet Explorer 5 (or later).\n" +
      "<p>Click on Animation Controls for more details on how to set the image controls.\n"+
       "\n<p>My apologies for the inconvenience,<br>Myron Turner. </div>");
      msgW.document.close();
   }
}

function getText(num) {
   close_all_popups();
// arguments.length = 2 in TD and 1 in IMG-- see changeTitle for explanation
 if(arguments.length == 1 && document.getElementById) return;   
  
  if(num == ROOM535_ORG) return;   
  if(document.layers) setTableNS4(Texts[num])
    else setBody('level_1', Texts[num]);
  setTablePos();
  globals.text_on = true; 
  globals.title_on = false;
  show('options');   // window close button icon
//  if(num != ABOUT && num != ABOUT - 1)
  if(num != ABOUT && num != 13)
    animate('img', 35, 80, dissolve, whendone,  imgArray[num], imgSizes[num]);
}


function changeTitle(evt,num) {
 
  // arguments.length = 3 in TD and 2 in IMG -- prevents double responses
  // in DOM-based browsers: IMG boxed in a Table and both have event handlers
  // assocated with them--in DOM the event handlers are activitated for both IMG and TD
 if(arguments.length == 2 && document.getElementById) return;   

  var body = '<a href="javascript:getText(' + num + ',1)" class="titles">' +  Titles[num] + '</a>';  

  if(globals.text_on) {   // text is on the screen
     if(num == ROOM535_ORG)  {   // occurs when text window closed
       resetInnerTables(body);  
     }
     else {
       popup(evt, num);
       return;
     }
  }
  else {
   if(document.layers) {
     resetInnerTables(body);  // resetInnerTables() sets levels 2 and 3, and sends
                              //  result down to setTableNS4() which encloses it in
                              // level_1 and writes it to top_level
   }
   else setBody('level_3', body);
  }
  setTablePos()
  globals.title_on = true;
  globals.text_on = false;   

   hide('options');
 }



function resetInnerTables(link) {

 var InnerTables = Levels[2] + Levels[3] + link + close_table + close_table;

 if(document.layers)
      setTableNS4(InnerTables);
 else
   setBody('level_1', InnerTables);   

}

function setTableNS4(body) {
var Tables = Levels[1] + body + close_table;

setBody('top_level', Tables);   
}

var TextTop, TextLeft;
	function setTablePos() {
  var divWidth = 540;
  var top = 100;
  var buttonsTableWidth = 292;  
  var w = browserWidth();
  if (browserHeight() < 500) {
     top = 50;
  }
  
  if(!document.layers)   
      divWidth = objectWidth('top_level');
  
  var pos = (w - divWidth)/2;
  setStyle("left", pos, 'top_level');
  setStyle("top", top, 'top_level');    
  show('top_level');
  TextTop = top; TextLeft = pos;

  setStyle("left", pos+3, 'options');
  setStyle("top", top+3, 'options');    
  
  var h = objectHeight('top_level');
  top += h;  
  setStyle("top", top, 'menu');

 
  divWidth = objectWidth('menu');   
  if(divWidth < buttonsTableWidth) divWidth = buttonsTableWidth;
  pos = (w - divWidth)/2;
  setStyle("left", pos, 'menu');
 
}


// if a new button is added to the end of this list, it has to come before
// "cltxt", which must always come last
var popups = new Array("al", "auto",  "sc", "ext", "news", "wcuts", "mt","reading","timeline","bigq","bstat","citysc", "arsrss", "about", "cltxt");

function popup(evt, num) { 
   close_all_popups();
   var x = mouseX(evt) - 25;
   var y = mouseY(evt)-50;  

   setStyle('left',x, popups[num]);
   setStyle('top', y, popups[num]); 
   show(popups[num]);  
}

//used for NS4 which would not recognize event passed from mouseover, as in popup(evt,num) above
function popupCloseTextInf(num) {
   setStyle('left',TextLeft, popups[num]);
   setStyle('top', TextTop - 32, popups[num]); 
   show(popups[num]);  
}

function close_popup(num) {
  hide(popups[num]);

}

function close_all_popups() {
   for(var i=0; i < popups.length; i++) {
         close_popup(i);
   }
}

function popupCV(cv) {
    openSite(cv);
}

function animationControls() {

  if(document.layers)
   window.open("animControl.html", "animctrl", "resizable=yes,width=500,height=450");
 else
   window.open("animControl.html", "animctrl", "resizable=yes,width=500,height=350");
  
}

function openSite(url) {
 var w = window.open(url, "site", "resizable=yes,scrollbars=yes");
 w.focus();
}

function writeBasicCSS(d) {
   d.writeln('<style type="text/css"> ',
	' #controls { width: 450 }  body { background-color: #ffffdd; }',
	 ' .text, .titles, li  {  font-family: sans-serif;  }',
	 ' .titles { text-align: center; font-size: 10pt;  font-weight:bold;} ',
	 ' .text{   font-size: 9pt;   color: #cc0033; line-height: 140%; } </style>'
	  );
  }
function writeBasicBodyTag(d) {
   d.writeln('<BODY alink="#cc3366;" vlink="#cc0033;" link="#cc0033;">');
}

function writeScript(d, script) {
   d.writeln('<script language="javascript">');
   d.writeln(script);
   d.writeln('</script>');
}

