// This function fades a layer in.
function fadeIn(x,final_opacity){
  document.getElementById(x).style.filter = 'alpha(opacity=0)';
  document.getElementById(x).style.visibility = 'visible';
  for(i=0;i<=final_opacity;i=(i+10)){
    var fade_cmd = "document.getElementById('" + x + "').style.filter = 'alpha(opacity=" + i + ")';";
    fade_cmd += "document.getElementById('" + x + "').style.MozOpacity = '0." + Math.round(i / 10) + "';";
    setTimeout(fade_cmd,(10 * i));
  }
}

// This function fades a layer out.
function fadeOut(x,starting_opacity){
  for(i=starting_opacity;i>=0;i=(i-10)){
    var fade_cmd = "document.getElementById('" + x + "').style.filter = 'alpha(opacity=" + i + ")';";
    fade_cmd += "document.getElementById('" + x + "').style.MozOpacity = '0." + Math.round(i / 10) + "';";
    setTimeout(fade_cmd,(100 - (i * 10)));
  }
  setTimeout("document.getElementById('" + x + "').style.visibility = 'hidden';",200);
}

// This function scrolls a layer in.
function scrollIn(x,obj_width){
  document.getElementById(x).style.visibility = 'visible';
  document.getElementById(x).style.width = '0px';
  document.getElementById(x).style.overflow = 'hidden';
  document.getElementById(x).style.display = 'block';
  for(i=0;i<=obj_width;i++){
    var scroll_cmd = "document.getElementById('" + x + "').style.width = '" + i + "px';";
    setTimeout(scroll_cmd,(2 * i));
  }
}

// This function scrolls a layer out.
function scrollOut(x,obj_width){
  document.getElementById(x).style.display = 'block';
  document.getElementById(x).style.overflow = 'hidden';
  for(i=obj_width;i>=0;i--){
    var scroll_cmd = "document.getElementById('" + x + "').style.width = '" + i + "px';";
    setTimeout(scroll_cmd,(200 - (i*20)));
  }
  scroll_cmd = "document.getElementById('" + x + "').style.display = 'none';";
  setTimeout(scroll_cmd,200);
}

var original_HTML = ''; // Store the original page HTML before executing the viewLarger function here.

// This function creates a 'view larger' overlay.
function viewLarger(width,height,url){

  var page = document.getElementById('body'); // Create a shortcut to the page HTML.
  original_HTML = page.innerHTML; // Store the original HTML of the page.  This is the contents of the <body> tag and does not include the contents of <head>.

  // Create and fade in a dark overlay first.  This will also serve as the container for the "view larger" content.
  // var main = "<div id=\"view_larger\" style=\"background-color: #000000; width: 100%; height: 100%; min-height: 100%; position: absolute; top: 0px; left: 0px; z-index:50; visibility: hidden; -moz-opacity: .0; filter: alpha(opacity=0);\"></div>\n";
  // page.innerHTML = page.innerHTML + main;
  // Create and scroll in the viewport area.
  var viewport = "<div style=\"width: 100%; height: 100%; text-align: center; position: absolute; left: 0px; top: 0px; z-index:65;\"><div id=\"view_larger_image\" style=\"width: " + parseInt(parseInt(width) + 20) + "px; height:" + parseInt(parseInt(height) + 20) + "px; background-repeat: no-repeat; background-color: #FFFFFF; background-image: url('" + url + "'); background-position: center center; border-color: #000000; border-style: solid; border-width: 10px; -moz-opacity: 1.0; filter: alpha(opacity=100); margin-left: auto; margin-right: auto; margin-top: 20%; margin-bottom: auto; z-index:65; visibility: hidden; cursor: pointer; max-height: 700px;\" onClick=\"closeViewLarger(); \" title=\"Click to close this view\"></div></div>\n";
  page.innerHTML = page.innerHTML + viewport;
  // fadeIn('view_larger',90);
  setTimeout("scrollIn('view_larger_image',"+(parseInt(width) + 20)+");",400);
  
}

// This function closes the 'view larger' display and removes its temporary HTML from the page.
function closeViewLarger(){
  // Remove all 'view larger' content from the HTML and clear the HTML temporary holder variable
  document.getElementById('body').innerHTML = original_HTML;
  original_HTML = '';  
}

function countChars(o){
  var char_count = o.value.length;
  document.getElementById('charcount').innerHTML = 1024 - char_count;
}


