var Ajax;
window.onload = shutterInit;

function shutterInit () {
    ajax = getHTTPObject();
    //don't change links if ajax is off
    if (!ajax) {return false;}
    //crawl all links for the 'shutter' class
    //indexOf for possibility of multiple classes
    links = document.getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
        if (links[i].className.indexOf('shutter') != -1) {
            oldLink = links[i].href;
            // change the href to load the same page, but with ajax
            links[i].style.display="block";
        }
    }
}

function mkShutter(href) {
    // some strange instances where shutter could be duplicated
    // after clicking a link and pressing enter.
    if (document.getElementById('newShutter')) {return false;}
//    loadImage();

    // check the url for '?'
    op = (href.indexOf('?') != -1) ? '&' : '?';
    // get the data from link via AJAX
    // ajax=on so its possible to tell difference between loading methods
  	ajax.open("GET", href +op+ 'ajax=on', true);
	ajax.onreadystatechange = function () {

    // if its finished loading
	   if (ajax.readyState == 4) {
//	       closeloadImage();
            // make a new shutter
            shutter = document.createElement('div');
            shutter.setAttribute('id','newShutter');
            // add it to the page
            document.getElementsByTagName('body')[0].appendChild(shutter);
  	        // delete the shutter when clicked on
            shutter.onclick = function() {hideShutter(); Element.show('comment'); return false;};
            // make the info box
            newInfo = document.createElement('div');
            newInfo.setAttribute('id','newInfo');
            // append the ajax-returned html to newInfo
	        newInfo.innerHTML = ajax.responseText;
	        document.getElementsByTagName('body')[0].appendChild(newInfo);
	   }
    };
  	ajax.send(null);
}

// remove the shutter and the info box
function hideShutter() {
    shutter = document.getElementById('newShutter');
    shutter.parentNode.removeChild(shutter);
    newInfo = document.getElementById('newInfo');
    newInfo.parentNode.removeChild(newInfo);   
}

// THE ajax function, from webpasties
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}