var layers=[];
var content = null;

function layer(overlayID, contentID){ this.OverlayID = overlayID; this.ContentID = contentID; }

function showLayer(contentID) {
	if (content == null) 
		content = document.getElementById("content");
	var overlay = document.createElement('DIV');	
	overlay.id = "overlay" + (new Date()).getTime();
	overlay.style.display = "block";
	overlay.style.opacity = 0;
	//overlay.style.height = 100%; window.innerHeight + window.scrollMaxY;
	overlay.style.zIndex = (layers.length+1) * 1000 ;
	overlay.onmousedown  = closeLayer;
	overlay.className = "overlay";
	
	content.appendChild(overlay);

	layers.push(new layer(overlay.id, contentID)); 

	setTimeout("Blend('"+overlay.id+"', 0, 0.6, 0.15, 10, showLayerContent);", 0);
}

function showLayerContent() {
	var contentBox = document.getElementById(layers[layers.length-1].ContentID);
	var overlay = document.getElementById(layers[layers.length-1].OverlayID);	
	contentBox.style.display = 'block';
	contentBox.style.opacity = 0;
	contentBox.style.zIndex = overlay.style.zIndex + 10;

	setTimeout("Blend('"+contentBox.id+"', 0, 1, 0.2, 20, null);", 0);
}

function closeLayer() {
	var contentBox = document.getElementById(layers[layers.length-1].ContentID);
	contentBox.style.display = "none";
	var overlay = document.getElementById(layers[layers.length-1].OverlayID);
	setTimeout("Blend('"+overlay.id+"', 0.6, 0, -0.1, 30, closeLayerContent);", 0);
}

function closeLayerContent() { 
	var overlay = document.getElementById(layers[layers.length-1].OverlayID);
	layers.pop();	
	content.removeChild(overlay);
}



function Blend(id, opacity, end, step, wait, callback){
  var e = document.getElementById(id);
  e.style.opacity = Math.round((opacity)*100)/100;
  e.style.filter = "alpha(opacity=" + Math.round((opacity)*100) + ");";
  opacity = opacity + step;
  if (e.style.opacity != end){
    setTimeout( "Blend('"+id+"', "+opacity+", "+end+", "+step+", "+wait+", "+callback+");", wait);
  } else if (callback != null) {
      callback();
  }	
}	






/*var ranIntro = false;
var timeOuts = new Array();
var blendElements = new Array();

function Intro(){
  if (!ranIntro){
    ranIntro = true;

    FindBlendElements();
    timeOuts[0] = 'Blend(1, 0, -0.1, 50, 0)';
    timeOuts[1] = 'Blend(0, 1, 0.2, 75, 1)';
    timeOuts[2] = 'Blend(0, .66, 0.06, 50, 2)';            

    setTimeout(timeOuts[0], 0);
  }
}

function IntroSlow(){
  if (!ranIntro){
    ranIntro = true;
    FindBlendElements();
    blendElements[0].style.display = "none";
    blendElements[1].style.opacity = 1;
    blendElements[2].style.opacity = 0.66;

  }
}

function FindBlendElements(){
    blendElements[0] = document.getElementById("loading");
    blendElements[1] = document.getElementById("contentBox");
    blendElements[2] = document.getElementById("footer");
}
*/

