function ShowLetter(letter,cover) {		
    document.getElementById(cover).style.visibility = "visible";
	document.getElementById(letter).style.visibility = "visible";
}

function CloseLetter(letter,cover) {		
    document.getElementById(cover).style.visibility = "hidden";
	document.getElementById(letter).style.visibility = "hidden";
}

function getWindowHeight() {
  var height = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    height = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    height = document.documentElement.clientHeight;
  } 
  return height;
}

function getWindowWidth() {
  var width = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    width = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    width = document.documentElement.clientWidth;
  } 
  return width;
}

function SizeImage() {
   document.getElementById('ImagePlace').style.height = "auto";  
   document.getElementById('ImagePlace').style.width = "auto";
    var height = document.getElementById('ImagePlace').height;
	var width = document.getElementById('ImagePlace').width;	
	var maxWidth = getWindowWidth() - 28;
	if(width > maxWidth) {
	   height = (maxWidth/width)*height;
	   width = maxWidth; 
	   document.getElementById('ImagePlace').style.height = height + "px";  
	   document.getElementById('ImagePlace').style.width = width + "px";
	}
	
	var maxHeight = getWindowHeight() - 49;
	if(height > maxHeight) {
	   width = (maxHeight/height)*width;
	   height = maxHeight;   
	   document.getElementById('ImagePlace').style.height = height + "px"; 
	   document.getElementById('ImagePlace').style.width = width + "px";	   
	}

    positionDialog(width,height);
}

function positionDialog(width,height)
{
    height = height + 36;
    width = width + 16;
	document.getElementById('photoDiv').style.width = width + "px";
	document.getElementById('photoDiv').style.height = height + "px";
	document.getElementById('photoDiv').style.marginTop = "-" + height/2 - 3 + "px";
	document.getElementById('photoDiv').style.marginLeft = "-" + width/2 - 3 + "px";	
	document.getElementById('photoDiv').style.border = "outset 3px #F3F3F3";
	document.getElementById('ImagePlace').style.marginTop = "6px";
	document.getElementById('ImagePlace').style.border = "inset 3px #AAAAAA";
	document.getElementById('ImagePlace').style.marginLeft = "5px";
	document.getElementById('ImageClose').style.marginLeft = (width - 52) + "px";
	document.getElementById('photoDiv').style.visibility = "visible";
	document.getElementById('waitDiv').style.visibility = "hidden";
}

function ShowImage(image) {		
   createCoverDiv();
   createProgressDialog();
   createPhotoDiv();
   
   document.getElementById('ImagePlace').src = image; 
}

function ShowVideo(object) {		
   createCoverDiv();
   createProgressDialog();   
   createVideoDiv();
   
   document.getElementById('ImagePlace').innerHTML = object;
}

function ImageFailed() {		
	CloseImage();
	alert("That image could not be found.");
}

function CloseImage() {		
	removeChild('cDiv');
	removeChild('waitDiv');
	removeChild('photoDiv');
}

function removeChild(element) {   
   if (document.getElementById(element)) {
      document.getElementsByTagName("BODY")[0].removeChild(document.getElementById(element));
   }
}

function CloseDescription(description,cover) {
    document.getElementById(cover).style.visibility = "hidden";
	document.getElementById(description).style.visibility = "hidden";
}

function OpenDescription(description,cover) {
    document.getElementById(cover).style.visibility = "visible";
	document.getElementById(description).style.visibility = "visible";
}
  
function createCoverDiv() {  
   var cDiv = document.createElement("DIV"); 
   cDiv.className = "CoverDiv";
   cDiv.id = "cDiv";  
   document.getElementsByTagName("BODY")[0].appendChild(cDiv);
}

function createProgressDialog() {
   var waitDiv = document.createElement("IMG"); 
   waitDiv.id = "waitDiv";  
   waitDiv.className = "WaitBox";  
   document.getElementsByTagName("BODY")[0].appendChild(waitDiv); 
   document.getElementById('waitDiv').src = "/images/paws.gif";
}

function createPhotoDiv() {
   var photoDiv = document.createElement("DIV"); 
   photoDiv.className = "PhotoBox";
   photoDiv.id = "photoDiv"; 
   
   var imgClose = document.createElement("IMG"); 
   imgClose.id = "ImageClose";
   imgClose.className = "ImageClose";
   imgClose.src = "/images/transparent.gif";
   photoDiv.appendChild(imgClose);  
         
   var imgPlace = document.createElement("IMG"); 
   imgPlace.id = "ImagePlace"; 
   photoDiv.appendChild(imgPlace);  
   document.getElementsByTagName("BODY")[0].appendChild(photoDiv); 

   document.getElementById('ImageClose').onclick = CloseImage;
   document.getElementById('ImagePlace').onload = SizeImage;
   document.getElementById('ImagePlace').onerror = ImageFailed;  
}


function createVideoDiv() {
   var photoDiv = document.createElement("DIV"); 
   photoDiv.className = "PhotoBox";
   photoDiv.id = "photoDiv"; 
   
   var imgClose = document.createElement("IMG"); 
   imgClose.id = "ImageClose";
   imgClose.className = "ImageClose";
   imgClose.src = "/images/transparent.gif";
   photoDiv.appendChild(imgClose);  
         
   var videoEmbed = document.createElement("DIV"); 
   videoEmbed.id = "ImagePlace"; 
   photoDiv.appendChild(videoEmbed);  
   document.getElementsByTagName("BODY")[0].appendChild(photoDiv); 

   document.getElementById('ImageClose').onclick = CloseImage;
   
   document.getElementById('ImagePlace').style.height = "500px";  
   document.getElementById('ImagePlace').style.width = "500px";
   
   positionDialog(500,500);   
}