﻿function GrayOut(vis, options) 
{
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

function ShowSplash(name, absmiddle)
{
    GrayOut(true, {'zindex':'50', 'bgcolor':'#000000', 'opacity':'70'});
 
    var el = document.getElementById(name);
    var pageWidth;
    var pageHeight;
    var dialogWidth;
    var dialogHeight;
    
    el.style.display = 'block';
    el.style.zIndex = 51;
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
    {
    
        pageWidth = document.body.scrollWidth;
        pageHeight = document.body.scrollHeight;
        dialogWidth = el.scrollWidth;
        dialogHeight = el.scrollHeight;
    } 
    else if( document.body.offsetWidth ) 
    {
      pageWidth = document.body.offsetWidth;
      pageHeight = document.body.offsetHeight;
      dialogWidth = el.offsetWidth;
      dialogHeight = el.offsetHeight;
    } 
     
    el.style.left = ((pageWidth/2.0) - (dialogWidth/2.0))+'px';
    el.style.top = '100px';    
    
    if (absmiddle)
    {

        var winH = (document.documentElement)? document.documentElement.clientHeight : window.innerHeight;
        var scrollY =GetScrollTop();
        el.style.top =  (scrollY+((winH/2.0) - (dialogHeight/2.0)))+'px';
       // alert('winH: '+winH+', document.body.clientHeight:'+document.body.clientHeight+', window.innerHeight:'+window.innerHeight+' scrollY: '+scrollY);
    }
}
function CloseSplash(name)
{
    GrayOut(false, null);
    var el = document.getElementById(name);
    el.style.display = 'none';
}

/*Faces-  Remember faces and names better- a bilateral task using both left and right hemispheres

 

·         News -  Increase your verbal memory- for the majority of people a left temporal lobe task

·         Attention - Improve your select attention- exercise your frontal systems

·         Dominos- Challenge your new learning capacity and work your hippocampus

·         Shopping-  Mental arithmetic for a maximum brain work out using maximum brain energy

·         Attention- Sustain your concentration  frontal lobe

·         Sequencing - Workout your working memory utilising temporal and frontal lobe systems*/

var previews = [
"nautical", 
"newsreader", 
"sustained_focus", 
"facerecog",
"shopping",
"sequencing"
];
var descriptions = [
/* nautical */
"Attention - Improve your select attention - exercise your frontal systems",
/* newsreader */
"News - Increase your verbal memory - for the majority of people a left temporal lobe task",
/* sustained_focus */
"Attention - Sustain your concentration  frontal lobe",
/* facerecog */
"Faces - Remember faces and names better - a bilateral task using both left and right hemispheres",
/* shopping */
"Shopping - Mental arithmetic for a maximum brain work out using maximum brain energy",
/* sequencing */
"Sequencing - Workout your working memory utilising temporal and frontal lobe systems"
]

function ShowPreview(name)
{
    var holder = document.getElementById('previewHolder');
    var idx = -1;
    for(var i=0;i<previews.length;i++)
    {
        if (previews[i]==name)
        {
            idx = i;
            break;
        }
    }

    var prev = (idx-1);
    if (prev == -1)
        prev = previews.length-1;
        
    var next = (idx+1);
    if (next == previews.length)
        next = 0;
        
    var s = "";
    s += "<div style=\"background: #FFFFFF; border: 2px solid #cccccc; width: 500px; height: 400px; padding: 15px;\">";
    s += "<table>";
    s += "<tr><td colspan=\"3\" style=\"text-align: right; color: #000000; font-weight: bold; font-size: 10pt;\"><a href=\"javascript:CloseSplash('previewHolder');\">close window</a></td></tr>";
    s += "<tr><td align=\"center\"><a href=\"javascript:ShowPreview('"+previews[prev]+"');\" style=\"text-decoration: none;\"><img src=\"/images/new/preview_prev.gif\" border=\"0\" /><br/>previous</a></td><td align=\"center\"><img src=\"/images/"+name+"_large.jpg\" /></td><td align=\"center\"><a href=\"javascript:ShowPreview('"+previews[next]+"');\" style=\"text-decoration: none;\"><img src=\"/images/new/preview_next.gif\" border=\"0\" /><br/>next</a></td></tr>";
    s += "<tr><td colspan=\"3\" style=\"text-align: center; color: #000000; font-weight: bold; font-size: 10pt;\">"+descriptions[idx]+"</td></tr>";
    s += "</table></div>";
    holder.innerHTML = s;
    holder.style.display = 'block';
    ShowSplash("previewHolder", true);
     holder.style.zIndex = 1000;
}