// Javascript utilities for Flude Commercial
var slowLine = true;
var start;
var end;
var homepageURL;
var startpageURL;
var slowLineNo = 0;
var imgDir = 'images/';

  // ********************
  // Line Speed functions
  // ********************
  function determineLineSpeedStart() {
     start = new Date();
     var img = new Image();
     // Forces reload from server to get proper indication of line speed
     homepageURL = getImgDir() + 'homepage.jpg?' + start.getTime();       
     img.src= homepageURL;
  }
  
  function getHomepageURL() {
    return homepageURL;
  }
  
  function determineLineSpeedEnd() {
  // Giving ten seconds for the test image to load
      end = new Date();
      var diff = end.getTime() - start.getTime();
      if (diff > 10000) {
        slowLine = true;
      } 
     else {
       slowLine = false;
     }
  }
  
  // ****************************
  // General Navigation Utilities
  // ****************************
  function goToWelcome(target) {
    slowLineNo = 0;
    startpageURL = 'welcome.htm';
    if (!slowLine) {
      slowLineNo = 1;
    }
    if (location.search.length > 0) {
    	if (location.search.indexOf("portfolio") > 0) {
		startpageURL = "portfolio/" + location.search.substring(11);
   	}
    } 
    window.document.location = target + '?slowLineNo=' + slowLineNo + '&homepageURL=' + homepageURL + "&startpageURL=" + startpageURL;
  }

  function closeMe() {
     window.close();
  }
  
  function writeRandomTrans() {
    rand = Math.random();
    if (rand < (1/3)) {
      document.write('<META http-equiv="Page-Exit" content="revealTrans(Duration=3,Transition=3)">');
    }
    else if (rand < (2/3)) {
      document.write('<META http-equiv="Page-Exit" content="revealTrans(Duration=3,Transition=1)">');
    }
    else {
      document.write('<META http-equiv="Page-Exit" content="blendTrans(Duration=3)">');
    }
  }
  
  function setStatus(statusText) {
     status = statusText;
     return true;
  }
  
  function determineStyleSheet(sheet) {
    path = 'styles/specific/';
    if (sheet==' ') {
      sheet = 'contents';
    }
    if (sheet.indexOf('../')>-1) {
      path = '../' + path;
      sheet = sheet.substring(3, sheet.length);
    }
    if (is800x600()) {
      path = path + '800x600/';
    }
    else if (isHandHeld()) {
      path = path + 'handheld/';
    }
    document.write('<LINK rel="stylesheet" type="text/css" href="' + path + sheet + '.css">');
  }
        
  // ****************************
  // Image Utilities
  // ****************************
  function reloadImage(name, file) {
    document.images[name].src = file;
  }
  
  function getImgDir() {
    return imgDir;
  }
  
  // *****************
  // Browser utilities
  // *****************  
  function getScreenWidth() {
    return screen.width;
  }

  function getScreenHeight() {
    return screen.height;
  }
  
  function is800x600() {
    if ((getScreenWidth() == 800)&&(getScreenHeight()== 600)) {
      imgDir = 'images/800x600/';
      return true;
    }
    else {
      imgDir = 'images/';
      return false;
    }
  }

  function isHandHeld() {
    if ((getScreenWidth() < 300)&&(getScreenHeight() < 400)) {
      imgDir = 'images/handheld/';
      return true;
    }
    else {
      imgDir = 'images/';
      return false;
    }
  }

