/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
   Style switcher
*/
function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
      if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
         a.disabled = true;
         if(a.getAttribute("title") == title) a.disabled = false;
      }
   }
   if (title == "Morning")   { $("#Drinks").attr("src", "images/Coffee-64.png"); }
   if (title == "Afternoon") { $("#Drinks").attr("src", "images/Coke-64.png"); }
   if (title == "Evening")   { $("#Drinks").attr("src", "images/Beer-64.png"); }
   $("#Drinks").supersleight();
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
   Compute time of day
*/
function TimeOfDayStyle() {
   now = new Date
   sNowSheet = 'Evening';
   sDrinkImage = "images/Beer-64.png";
   if (now.getHours() < 22) { sNowSheet = 'Evening';    sDrinkImage = "images/Beer-64.png";    } 
   if (now.getHours() < 17) { sNowSheet = 'Afternoon';  sDrinkImage = "images/Coke-64.png";    } 
   if (now.getHours() < 11) { sNowSheet = 'Morning';    sDrinkImage = "images/Coffee-64.png";  } 
   if (now.getHours() <  5) { sNowSheet = 'Evening';    sDrinkImage = "images/Coffee-64.png";  }
   setActiveStyleSheet(sNowSheet);
   $("#Drinks").attr("src", sDrinkImage);
   $("#Drinks").supersleight();
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
   Include one javascript file inside another script
   http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_include/ 
*/
function include (filename) {
    // http://kevin.vanzonneveld.net
    // +   original by: mdsjack (http://www.mdsjack.bo.it)
    // +   improved by: Legaev Andrey
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Michael White (http://getsprink.com)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: Force Javascript execution to pause until the file is loaded. Usually causes failure if the file never loads. ( Use sparingly! )
    // %        note 2: The included file does not come available until a second script block, so typically use this in the header.
    // %        note 3: Uses global: php_js to keep track of included files
    // *     example 1: include('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js');
    // *     returns 1: 1
 
    var d = this.window.document;
    var js = d.createElementNS ? d.createElementNS('http://www.w3.org/1999/xhtml', 'script') : d.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', filename);
    js.setAttribute('defer', 'defer');
    d.getElementsByTagNameNS ?
        (d.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'head')[0] ?
            d.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'head')[0].appendChild(js) :
            d.documentElement.insertBefore(js, d.documentElement.firstChild) // in case of XUL
        ):
        d.getElementsByTagName('head')[0].appendChild(js);
    // save include state for reference by include_once
    var cur_file = {};
    cur_file[this.window.location.href] = 1;
 
    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};
    // END REDUNDANT
    if (!this.php_js.includes) {
        this.php_js.includes = cur_file;
    }
    if (!this.php_js.includes[filename]) {
        this.php_js.includes[filename] = 1;
    } else {
        this.php_js.includes[filename]++;
    }
 
    return this.php_js.includes[filename];
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
   Changing the table/map display 
*/
function ResizeTableAndMap(size) {
    // adjust map, table dimensions to make it all fit nice
    if (size=='smallmap') {
        // Map Height = Win Height - Header - searchform - Table Hdr - Table - bit o space for the bottom
        $("#map").css('height', $(window).height() - 80 - 32 - 90 - 200 - 41);
        $("#searchtable").css("display", "block");
        $("#switchme").text("Hide Table");
    }
    if (size=='bigmap') {
//      $("#map").css('height', $(window).height() - 80 - 32 - 33 );
      $("#map").css('height', $(window).height() - 80 - 34 );
        $("#searchtable").css("display", "none");
        $("#switchme").text("Show Table");
    }    
    return(false);
}


