// JavaScript Document
function sendRequest(request, url) {
  request.onreadystatechange = loadImage;
  request.open("GET", url, true);
  request.send(null);
}

function loadImage()
{
  if (ajaxRequest.readyState == 4) {
    if (ajaxRequest.status == 200) {
      var ajaxResponse = ajaxRequest.responseText;
      var contentDiv = document.getElementById("content");    
      contentDiv.innerHTML = ajaxResponse;
      contentDiv.style.position = 'absolute';
      contentDiv.style.top = 10;
      contentDiv.style.left = 10;
    }
    else {
      alert("Error! Request status is " + ajaxRequest.status);
    } 
    ajaxRequest = createRequest();
  }
}

function updateMessage()
{  
  if (ajaxRequest.readyState == 4) {
    var contentDiv = document.getElementById("content");
    contentDiv.innerHTML = '<p>' + ajaxRequest.responseText + '</p>';
  }
}

function ajaxGetImage( imageUrl, width, height )
{
  var url = "loadImage.php?image_url=" + imageUrl + "&image_width=" + width + "&image_height=" + height;
  ajaxRequest = createRequest();
  sendRequest(ajaxRequest, url);
}


function toggleVisibility( )
{      
  if ( cursor > UPPER_LIMIT ) {
    cursor = 1;
    return;
  }
  else {
    var name = "cell_" + cursor;
    var style = document.getElementById(name).style;
    style.visibility = (style.visibility == 'hidden') ? 'visible' : 'hidden';
    cursor += 1;
    setTimeout('toggleVisibility();', 80);
  }
}

function getGallery( pageIndex )
{
  if ( pageIndex == currentContentPage ) {
    return;
  }
  //var newStyleObj = document.getElementById("page_" + pageIndex);
  var newScrollerObj = document.getElementById("scroller_" + pageIndex);
  //var currentStyleObj = document.getElementById("page_" + currentContentPage);
  var currentScrollerObj = document.getElementById("scroller_" + currentContentPage);
  //currentStyleObj.style.visibility = 'hidden';
  //newStyleObj.style.visibility = 'visible';
  newScrollerObj.className = 'scrollerSelected';
  currentScrollerObj.className = 'scrollerUnselected';
  currentContentPage = pageIndex;
}

function showFullImage( imageSrc, imageWidth, imageHeight )
{
  var obj = document.getElementById(  "content-right" );
  
  var gallery = document.getElementById( "thumbnail-table" );
  var str1 = "<p>Gallery width: " + 
    gallery.clientWidth + 
    ", height: " + 
    gallery.clientHeight + 
    ", position: (" + gallery.style.xpos + "," + gallery.style.top + ")</p>";
	
  /*
  var styleStr = "style=\"position:absolute;left: " + Math.round(galleryLeft + gallery.clientWidth + galleryPadding) + "\";top: " + Math.round(galleryTop + (gallery.clientHeight - imageHeight)/2 ) + "\"";
  window.status = styleStr;
  */
  var str = "<img src=\"" + imageSrc + "\" width=\"" + imageWidth + "\" height=\"" + imageHeight + "\"/>";
  obj.innerHTML = str;
  obj.style.left = Math.round(galleryLeft + gallery.clientWidth + galleryPadding);
  obj.style.top = Math.round(galleryTop + (gallery.clientHeight - imageHeight)/2 ); 
}



