// fix the pesky pipes

addEvent(window, "load", rem_pipes);

function rem_pipes () {
      var objElement = document.getElementById("footer")
      if (objElement != null) 
      {
         var str_a = new String(objElement.innerHTML);
         str_a = str_a.replace(/\|/g, '')
         objElement.innerHTML = str_a;
      }

      var objElement = document.getElementById("allFeeds")
      if (objElement != null) 
      {
         var str_b = new String(objElement.innerHTML);
         str_b = str_b.replace(/\|/g, '')
         objElement.innerHTML = str_b;
      }
      var objElement = document.getElementById("feedHelp")
      if (objElement != null) 
      {
         var str_b = new String(objElement.innerHTML);
         str_b = str_b.replace(/\|/g, '')
         objElement.innerHTML = str_b;
      }
}

// Custom Right Click Message

rightClickWarning = "All photos are © Respective Owners.  All rights reserved. Unauthorized use is prohibited."

//filmStrip values you can override:
//rightMoves = 5;
//leftMoves = -5;

// how fast do you want the filmstrip to move?
// filmstripMove = 1;

// slideshow duration for each slide
// slideDuration = 2;

// show the next and previous image previews?
showImagePreview = true;

// don't want the lightbox? 
useLightbox = true;


// bigwebguy's magic smugloupe name changer
function loupeName(newName)
{
  var loupe = document.getElementById("smugLoupe");
  if (!loupe)
    return

  var loupeChilds = loupe.childNodes;

  for (var i = 0; i <= loupeChilds.length ; i++)
  {
    if (loupeChilds[i].nodeType == 3 && loupeChilds[i].nodeValue.indexOf("smugloupe") >= 0)
    {
      loupe.replaceChild(document.createTextNode(newName), loupeChilds[i]);    
      return;
    }
  }
}

// Removes the clickable link from my portrait services journal gallery

function doOnLoad()
{
if (window.AlbumID && (window.AlbumID == "830860" || window.AlbumID == "729391")) //
{
removeLinkFromImg();
}
}

function removeLinkFromImg()
{
var links = document.getElementsByTagName("A");
for (var i = 0; i < links.length; i++)
{
var link = links[i];
var divElm = link.parentNode;
if (!divElm) continue;
if (divElm.className.indexOf("photo")<0) continue;
link.href = "javascript:void(0);";
}
}

function delHover() {
	imgTags = document.getElementsByTagName("img");
	for (i=0; i<imgTags.length; i++) {
		imgTags[i].title = "";
		imgTags[i].alt = "";
	}
}

// Secure Email Code

function writeEMail(pLinkText, pSubject)
{
 var v2="C2FF8M2W5Q2W6FX32URMW";
 var v7=unescape("%22E/*T%24S%3AF%3FK%17O%270%5C%5D%7B1%22%3A");
 var v5=v2.length;var v1="";
 for(var v4=0;v4<v5;v4++)
 {
  v1+=String.fromCharCode(v2.charCodeAt(v4)^v7.charCodeAt(v4));
 }
 document.write('<a href="javascript:void(0)" onclick="window.location=\'mail\u0074o\u003a'+v1+'?subject=Photography%20inquiry'+'\'">'+'email me</a>');
}
 

// automatic smugmug referral code by linkage

function AddReferralCode()
  {
  	var footerDiv = document.getElementById("footer");
  	if (footerDiv)
  	{
  		var links = footerDiv.getElementsByTagName("A");
  		if (links && (links.length != 0))
  		{
  			var smugLink = links.item(0);
 			smugLink.href = "http://www.smugmug.com/?referrer=lKTcC0p8CkfRK";
  		}
  	}
  }
  
  function OnLoadHandler()
  {
  	AddReferralCode();
  }

// Do not show full screen slideshow button in the small slide show

function killFullscreen()
{
  if ((IsClass("slideshow")) && myform)
    myform.parentNode.removeChild(myform);
}

function IsClass(sClass) {
  sClassName = document.body.className;

  re = new RegExp(sClass + "( |$)") 

  if (!sClassName)
    return false;
  return re.test(sClassName);
}

// paypal hack
function setPaypalForm(form) {
 urlToImage = webServer + "/gallery/" + AlbumID + "/1/" + ImageID + "/Large";
 form.item_name.value = urlToImage;
}


/*===========================*/

/*== SLIDE SHOW            ==*/

/*== version 0.55          ==*/

/*== Updated 20 April 2006 ==*/

/*===========================*/

var SLIDE_SHOW = 0;

var RANDOM_PHOTO = 1;

var slideshowContainer;

var sSlide;

var sCaption;

var ssSlides;

var ssSlideTotal;

var ssSlideTimer;

var ssOldSlide;

var ssFadeTimer;

var ssFade;

var ssTimerId;

var blank;





function PrepSlideEnvironment()

{

  tmpCookie = getCookie("Template");



  blank = new Image();

  blank.src = "/img/spacer.gif";



  if (typeof(slideshowType) == "undefined" || (slideshowType != SLIDE_SHOW && slideshowType != RANDOM_PHOTO))

    slideshowType = SLIDE_SHOW;



  if (slideshowType == RANDOM_PHOTO)

    randomSlides = true;



  if (typeof(slideshowContainerId) == "undefined")

    return false

  else if (typeof(slideshowContainerId) == "string")

    slideshowContainer = document.getElementById(slideshowContainerId);



  if (!slideshowContainer)

    return false;



  if (typeof(slideshowUrl) == "undefined" || typeof(slideshowUrl) != "string")

    return false;

  else

    slideshowUrl =  /(http:\/\/\S+[^\/])\/?$/.exec(slideshowUrl)[1];



  if (/\/gallery\/[0-9]+/.test(slideshowUrl))

    slideSourceIsGallery = true;

  else

    slideSourceIsGallery = false;



  if (typeof(slideHeight) == "undefined" || isNaN(slideHeight))

    slideHeight = "200";



  if (typeof(slideWidth) == "undefined" || isNaN(slideWidth))

    slideWidth = "300";



  if (typeof(photoHeight) == "undefined" || isNaN(photoHeight))

    photoHeight = slideHeight;



  if (typeof(photoWidth) == "undefined" || isNaN(photoWidth))

    photoWidth = slideWidth;



  if (typeof(slideDuration) == "undefined" || isNaN(slideDuration))

    slideDuration = 3;



  if (typeof(firstSlideUrl) == "undefined" || typeof(firstSlideUrl) != "string")

    firstSlideUrl = blank.src;



  if (typeof(showSlideTransition) == "undefined" || typeof(showSlideTransition) != "boolean")

    showSlideTransition = true;

   

  if (typeof(resizeToPhoto) == "undefined" || typeof(resizeToPhoto) != "boolean")

    resizeToPhoto = true;



  if (typeof(quickStart) == "undefined" || typeof(quickStart) != "boolean")

    quickStart = true;



  if (typeof(randomSlides) == "undefined" || typeof(randomSlides) != "boolean")

    randomSlides = false;



  if (typeof(slideControls) == "undefined" || typeof(slideControls) != "boolean")

    slideControls = false;



  if (typeof(slideCaptions) == "undefined" || typeof(slideCaptions) != "boolean")

    slideCaptions = false;



  if (typeof(slidesClickable) == "undefined" || typeof(slidesClickable) != "boolean")

    slidesClickable = false;



  return true;

}





function loadSlideshow()

{

  if (!PrepSlideEnvironment())

    return false;



  slideshowContainer.innerHTML = '<img src="http://www.smugmug.com/img/spacer.gif" alt="" id="ssSlide" height="' + slideHeight + '" width="' + slideWidth + '" style="opacity: .99; background-image: url(' + firstSlideUrl + '); background-repeat: no-repeat; background-position: center;" />';


  if (slideCaptions)

    slideshowContainer.innerHTML += '<div id="ssCaption"></div>';


  if (slideControls)

    slideshowContainer.innerHTML += '<div id="ssControl"><a title="Previous Slide" id="ssPrev" class="ssBtn" href="javascript: void(0);" onclick="prevSlide();"><img src="/img/spacer.gif" border="0" /></a><a title="Pause Slideshow" id="ssPause" class="ssBtn" href="javascript: void(0);" onclick="pauseSlideshow();"><img src="/img/spacer.gif" border="0" /></a><a title="Resume Slideshow" id="ssPlay" class="ssBtn" href="javascript: void(0);" onclick="resumeSlideshow();"><img src="/img/spacer.gif" border="0" /></a><a title="Next Slide" id="ssNext" class="ssBtn" href="javascript: void(0);" onclick="nextSlide();"><img src="/img/spacer.gif" border="0" /></a></div>';



  sSlide = document.getElementById('ssSlide');

  sCaption = document.getElementById('ssCaption');



  if (slidesClickable) {

    sSlide.style.cursor = 'pointer';

  

    if (firstSlideUrl != blank.src)

      ssAddSlideClick(slideshowUrl);

  }



  ssSlides = new Array(null);

  ssSlideTotal = 0;

  ssSlideTimer = 0;

  ssOldSlide = 0;

  ssFadeTimer = 100;

  ssFade = "out";  



  if (slideSourceIsGallery)

    ajax_query(slideshowHandler, '/photos/sspopup.mg?AlbumID=' + /\/gallery\/([0-9]+)/.exec(slideshowUrl)[1], null, true);

  else {

    var postArray = new Array();

    postArray['TemplateID'] = '8';

    postArray['origin'] = slideshowUrl;

    ajax_query(slideshowHandler, '/homepage/templatechange.mg', postArray, true);

  }

}





function slideshowHandler(response)

{

  if (!slideSourceIsGallery) {

    if (tmpCookie && tmpCookie != "") {

      var postArray = new Array();

      postArray['TemplateID'] = tmpCookie;

      postArray['origin'] = slideshowUrl;

      ajax_query(function(){}, '/homepage/templatechange.mg', postArray, true);

    }

    else

      deleteCookie("Template", "/", "smugmug.com");

  }



  var re = /imageID\[\d+\] = "\d+";/g;

  var re2 = /width\[\d+\] = "\d+";/g;

  var re3 = /height\[\d+\] = "\d+";/g;



  //Thanks Mika Majakorpi for the Caption support!

  var re4 = /caption\[\d+\] = ".*";/g;



  s = response.match(re); 

  w = response.match(re2);

  h = response.match(re3);

  c = response.match(re4);



  var oSlide;



  for (i = 0; i < s.length; i++)

  {

    oSlide = new Object;



    temp = s[i].split(/"/);

    oSlide.ImageId = temp[1];

    oSlide.File = 'http://upload.smugmug.com/photos/toolthumbs.mg?ImageID=' + temp[1] + '&tool=slideshowXL&winHeight=' + photoHeight + '&winWidth=' + photoWidth;

    oSlide.Gallery = slideshowUrl + '/1/' + oSlide.ImageId;



    temp = h[i].split(/"/);

    oSlide.Height = temp[1];



    temp = w[i].split(/"/);

    oSlide.Width = temp[1];



    temp = c[i].split(/"/);

    oSlide.Caption = temp[1];



    oSlide.Loaded = false;

 

    if ((oSlide.Width > photoWidth) || (oSlide.Height > photoHeight))

    {

      if (oSlide.Width >= oSlide.Height)

      {

         oSlide.Height = Math.round((oSlide.Height / oSlide.Width) * photoWidth);

         oSlide.Width = photoWidth;

      }

      else

      {

        oSlide.Width = Math.round((oSlide.Width / oSlide.Height) * photoHeight);

        oSlide.Height = photoHeight;

      }

    }



    ssSlideTotal = ssSlides.push(oSlide);

  }



  ssSlideTotal -= 1;



  if (randomSlides)

  {

    ssSlides.shift();

    ssSlides.shuffle();

    ssSlides.unshift(0);

  }



  if (quickStart)

    ssSlideTimer = (slideDuration * 1000);



  ssPrepSlide(1);

  window.setTimeout("ssPrepSlide(2);", 0);

  window.setTimeout("ssPrepSlide(ssSlideTotal);", 0);



  if (slideshowType == SLIDE_SHOW)

    ssPlaySlideshow();

  else

    ssSlideSwap(1);

}





function ssPauseSlideshow()

{

  window.clearTimeout(ssTimerId);

  ssTimerId = null;

}





function ssResumeSlideshow()

{

  if (!ssTimerId)

    ssTimerId = window.setTimeout("ssPlaySlideshow()", 10);

}





function ssPrepSlide(prep)

{

  if (ssSlides[prep].Loaded == false)

  {

    ssSlides[prep].Image = new Image();

    ssSlides[prep].Image.src = ssSlides[prep].File;

    ssSlides[prep].Loaded = true;

  }   

}





function ssMoveSlide(i) {

  ssSlideTimer = 0;

  ssFadeTimer = 100;

  ssTransition(ssFadeTimer);

  ssFade = "out";

  ssSlideSwap(i);                       

}





function ssPlaySlideshow()

{

  if (ssSlideTimer >= (slideDuration * 1000))

  {                

    if (ssFade == 'out')

      ssTransition(ssFadeTimer -= 10);                   

 

    if (ssFadeTimer == 0)

    {

      ssSlideSwap(1);

      ssFade = 'in';

    }

 

    if (ssFade == 'in')

      ssTransition(ssFadeTimer += 10);

 

    if (ssFadeTimer == 100)

    {

      ssSlideTimer = 0;

      ssFade = 'out';

    }

  }

  else

    ssSlideTimer += 10;

 

  ssTimerId = window.setTimeout("ssPlaySlideshow()", 10);

}





function ssTransition(opacity)

{

  if (showSlideTransition)

  {

    if (opacity != 100)

      sSlide.style.opacity = (opacity / 100);   

 

    // one case where mozilla sucks: the image will flash if you turn opacity up to 1 suddenly

    else

      sSlide.style.opacity = (.99);

 

    // only affects Win IE

    sSlide.style.filter = 'alpha(opacity=' + opacity + ')';



    if (sCaption) {

      sCaption.style.opacity = sSlide.style.opacity;

      sCaption.style.filter = sSlide.style.filter;

    }

  }

}





function ssSlideSwap(i)

{

  var newSlide = ssOldSlide + i;

 

  if (newSlide > ssSlideTotal)

    newSlide = 1;

 

  if (newSlide < 1)

    newSlide = ssSlideTotal;

 

  if (ssSlides[newSlide].Loaded != false)

  {

    document.images['ssSlide'].src = blank.src;

    sSlide.style.backgroundImage = 'url(' + ssSlides[newSlide].File + ')';

    if (resizeToPhoto)

    {

      document.images['ssSlide'].height = ssSlides[newSlide].Height;

      document.images['ssSlide'].width = ssSlides[newSlide].Width;

    }



    if (slidesClickable)

      ssAddSlideClick(ssSlides[newSlide].Gallery);

    

    if (slideCaptions)

      document.getElementById('ssCaption').innerHTML = ssSlides[newSlide].Caption;



    ssPrepSlide(newSlide < ssSlideTotal ? newSlide + i : 1);

    ssOldSlide = newSlide;

  }

  else

  {

    ssPrepSlide(newSlide);

    ssSlideSwap(i);

  }

}





function ssAddSlideClick(sUrl) {

  addEvent(sSlide, 'click', function(){location.href=sUrl;});

}





Array.prototype.shuffle = function()

{

  var len = this.length;

  var rand, temp, i;



  for (i = 0; i < len; i++)

  {

    rand = Math.floor(Math.random()*len);

    temp = this[i];

    this[i] = this[rand];

    this[rand] = temp;

  }

}





function pauseSlideshow()

{

  document.getElementById('ssPause').style.display = "none";

  document.getElementById('ssPlay').style.display = "inline";

  ssPauseSlideshow();

}





function resumeSlideshow()

{

  document.getElementById('ssPause').style.display = "inline";

  document.getElementById('ssPlay').style.display = "none";

  ssResumeSlideshow();

}





function prevSlide()

{

  pauseSlideshow();

  ssMoveSlide(-1);

}





function nextSlide()

{

  pauseSlideshow();

  ssMoveSlide(1);

}





function getCookie(name) {

  var start = document.cookie.indexOf(name + "=");

  var len = start + name.length + 1;

  

  if ((!start) && (name != document.cookie.substring(0, name.length)))

    return null;



  if (start == -1)

    return null;



  var end = document.cookie.indexOf(";", len);



  if (end == -1)

    end = document.cookie.length;



  return unescape(document.cookie.substring(len, end));

}





function deleteCookie(name, path, domain) {

  if (getCookie(name))

    document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";

}





/*============================*/
/*== Bulk Zoom thumbnail v2.4 ==*/
/*============================*/
var thumbnailArray = new Array();
var thumbnailCount;
var thumbnailItem;
var thumbnailEXIFArray = new Array();
var reqIncrement = 0;

addEvent(window, "load", addBulkThumbnail);

function addBulkThumbnail()
{
  if (isClass("galleryPage"))
  {
    if ((isClass("traditional")) || (isClass("allthumbs")) ||  (isClass("smugmug_small")) ||  (isClass("smugmug")))
    {
      if (isClass("loggedIn"))
      {
        onStartBulk();

        divTag = document.getElementById("photoTools");

        document.getElementById("bulkSave").disabled = true;

        objSpan = document.createElement("span");
        objSpan.className = "foreground";
        divTag.appendChild(objSpan);

        objButton = document.createElement("input");
        objButton.type = "checkbox";
        objButton.id = "bulkzoom";
        objSpan.appendChild(objButton);
        addEvent(objButton, "click", toggleBulkZoom);

        objText = document.createTextNode(' bulk zoom thumbnail');
        objSpan.appendChild(objText);
      }
    }
  }
}

function toggleBulkZoom()
{
  if (document.getElementById('bulkzoom').checked)
    processThumbnails();
  else
    window.location = window.location;
}

function processThumbnails()
{
  document.getElementById("ajaxWorking").innerHTML = "<strong><strong>Loading...</strong></strong>"
  toggleDIV('ajaxWorking','','block');

  document.getElementById("bulkzoom_toolbox").style.display = "";
  thumbnailEXIFArray = imageIDs.slice(0);
  getThumbnailEXIF();
}

function maskThumbnails(objThumbnail, j)
{
  re1 = /\/gallery\/\d+\/\d+\/(\d+)/
  re2 = /javascript\:openLB\(([0-9]+),/;

  divTag = document.getElementById("thumbnails") ? document.getElementById("thumbnails") : document.getElementById("photos");

  if (divTag)
  {
    divTags = divTag.getElementsByTagName("div");

    for (i=0; i<divTags.length; i++)
    {
      if (divTags[i].className == "photo")
      {
        if (re1.test(divTags[i].innerHTML))
          re1.exec(divTags[i].innerHTML);
        else
        {
          if (re2.test(divTags[i].innerHTML))
            re2.exec(divTags[i].innerHTML);
          else
            continue;
        }

        thumbnailId = RegExp.$1;
        aTags = divTags[i].getElementsByTagName("a");
        imgTags = aTags[0].getElementsByTagName("img");

        if (objThumbnail.thumbnailId == thumbnailId)
        {
          maskedDiv = document.createElement("div");
          maskedDiv.id = thumbnailId + "_masked";
          maskedDiv.className = j;
          maskedDiv.style.cssText = "position: relative; background: transparent url('" + webServer+"/photos/toolthumbs.mg?tool=cropmask&Size=Small&ImageID="+ thumbnailId + "') no-repeat; width: " + objThumbnail.imgWidth + "px; height: " + objThumbnail.imgHeight + "px; z-index: 1; margin:0px auto; text-align:left;";

          clearedDiv = document.createElement("div");
          clearedDiv.id = thumbnailId + "_cleared";
          clearedDiv.className = j;
          clearedDiv.style.cssText = "position: absolute; background: url('" + webServer+"/photos/"+ thumbnailId + "-S" + objThumbnail.modifier + ".jpg') no-repeat; width: " + objThumbnail.imgWidth + "px; height: " + objThumbnail.imgHeight + "px; z-index: 2; clip:rect(0px," + objThumbnail.imgWidth + "px," + objThumbnail.imgHeight + "px,0px);";

          maskedDiv.appendChild(clearedDiv);

          cropboxDiv = document.createElement("div");
          cropboxDiv.id = thumbnailId + "_cropbox";
          cropboxDiv.className = j;
          cropboxDiv.style.cssText = "position: absolute; left: 0px; top: 0px; width: " + (objThumbnail.imgWidth-4) + "px; height: " + (objThumbnail.imgHeight-4) + "px; border: solid 2px blue; z-index: 3; cursor: move";
          addEvent(cropboxDiv, "mousedown", testMouseBulk);

          clearedDiv.appendChild(cropboxDiv);

          ratioboxDiv = document.createElement("div");
          ratioboxDiv.id = thumbnailId + "_ratiobox";
          ratioboxDiv.className = j;
          ratioboxDiv.style.cssText = "position: absolute; bottom: 0px; right: 0px; width: 25px; height: 25px; border-top: solid 2px blue; border-left: solid 2px blue;  cursor: pointer; cursor: hand; z-index: 4;";
          addEvent(ratioboxDiv, "mousedown", testZoomBulk); 
          cropboxDiv.appendChild(ratioboxDiv);
          
          divTags[i].replaceChild(maskedDiv, aTags[0]);
          divTags[i].style.width = objThumbnail.imgWidth + "px";
          divTags[i].style.height = objThumbnail.imgHeight + "px";
        }
      }
    }
  } 
}

function getThumbnailEXIF()
{
  var thumbnail = thumbnailEXIFArray.pop();

  if (thumbnail)
  {
    postArray = new Array();
    postArray['tool'] = 'lightBoxImage';
    postArray['ImageID'] = thumbnail;
    postArray['size'] = 'Original';
    postArray['pageType'] = pageType;
    postArray['pageTypeDetails'] = pageTypeDetails;
    postArray['siteUser'] = siteUser;
    ajax_query(processThumbnailEXIF, webServer+'/hack/RPC/gallery.mg', postArray, true);
    window.setTimeout(getThumbnailEXIF, 100);
  }
  else
  {
    toggleDIV('','ajaxWorking','block');

    if (isClass("loggedIn"))
      document.getElementById("bulkSave").disabled = false;
  }

}

function processThumbnailEXIF(response)
{
  re = /\/photos\/(\d+)\-(O|L|M|S)(\-\d+)?\.jpg[\s\S]+,(\d+),(\d+),(false|true)/;

  response = URLDecode(response);
  re.exec(response);

  if (RegExp.$2 != "O")
  {
    toggleDIV('','ajaxWorking','block');
    alert("Error: bulk zoom thumbnail requires access to originals.\n\"" + RegExp.$1 + "\" \"" + RegExp.$2 + "\" \"" + RegExp.$4 + "\" \"" + RegExp.$5 + "\"");
    return;
  }
  sThumbnailId = RegExp.$1;
  sThumbnailModifier = RegExp.$3;
  imgWidth = parseInt(RegExp.$4);
  imgHeight = parseInt(RegExp.$5);

  temp = new Array();
  thumbnailArray[thumbnailArray.length] = temp;
  thumbnailArray[thumbnailArray.length-1].thumbnailId = sThumbnailId;
  thumbnailArray[thumbnailArray.length-1].modifier = sThumbnailModifier;

  if (imgWidth < imgHeight)
  {
    thumbnailArray[thumbnailArray.length-1].imgHeight = 300;
    thumbnailArray[thumbnailArray.length-1].imgWidth = Math.round((imgWidth / imgHeight) * 300);
  }
  else
  {
    thumbnailArray[thumbnailArray.length-1].imgWidth = 400;
    thumbnailArray[thumbnailArray.length-1].imgHeight = Math.round((imgHeight / imgWidth) * 400);
  }

  thumbnailArray[thumbnailArray.length-1].ratio = 0;
  thumbnailArray[thumbnailArray.length-1].invRatio = 0;
  thumbnailArray[thumbnailArray.length-1].marginTop = 0;
  thumbnailArray[thumbnailArray.length-1].marginLeft = 0;
  thumbnailArray[thumbnailArray.length-1].cropHeight = thumbnailArray[thumbnailArray.length-1].imgHeight;
  thumbnailArray[thumbnailArray.length-1].cropWidth = thumbnailArray[thumbnailArray.length-1].imgWidth;
  thumbnailArray[thumbnailArray.length-1].oRatio = (imgWidth / thumbnailArray[thumbnailArray.length-1].imgWidth);
  thumbnailArray[thumbnailArray.length-1].cropDiff = 0;

  maskThumbnails(thumbnailArray[thumbnailArray.length-1], thumbnailArray.length-1);
  //getThumbnailEXIF();
}

function zoomThumbnails()
{
  if (!thumbnailItem)
  {
    thumbnailItem = 0;
    thumbnailCount = thumbnailArray.length;
  }

  var thumbnail = thumbnailArray.pop();
  
  if (thumbnail)
  {
    thumbnailItem++; 

    postArray = new Array();
    postArray['tool'] = 'newthumb';
    postArray['ImageID'] = thumbnail.thumbnailId;
    postArray['action'] = "doit";
    postArray['crop_h'] = Math.round(parseInt(thumbnail.cropHeight) * parseFloat(thumbnail.oRatio));
    postArray['crop_w'] = Math.round(parseInt(thumbnail.cropWidth) * parseFloat(thumbnail.oRatio));
    postArray['crop_x'] = Math.round(parseInt(thumbnail.marginLeft) * parseFloat(thumbnail.oRatio));
    postArray['crop_y'] = Math.round(parseInt(thumbnail.marginTop) * parseFloat(thumbnail.oRatio));

    reqIncrement ++;
    updateAjaxStatus();
    window.setTimeout('ajax_query(thumbReqHandler, webServer+\'\/photos\/tools.mg\', postArray, true, true);', 10);
    window.setTimeout(zoomThumbnails, 50);
  } 
}


function thumbReqHandler() {
  updateAjaxStatus();

  reqIncrement--;

  if (thumbnailArray.length == 0 && reqIncrement == 0) {
      window.location = window.location;
  }
}

function updateAjaxStatus(sStr) {
var ajx = document.getElementById("ajaxWorking");

  if (thumbnailArray.length == 0)
    ajx.innerHTML =  'Processing thumbnail ' + (thumbnailCount - reqIncrement + 1) + ' of ' + thumbnailCount;
  else
    ajx.innerHTML = 'Sending request ' + reqIncrement + ' of ' + thumbnailCount;


  if (sStr) {
    ajx.innerHTML = ajx.innerHTML + sStr;
  }

  toggleDIV('ajaxWorking','','block');
}

var smallestBulk = 75;   
var mouseXBulk = 0;
var mouseYBulk = 0;
var mouseToolBulk = "move";
var hideRatioBulk = false;    
var scaleBulk = 1;
var pageLoadedBulk = false;

function onStartBulk()
{
  pageLoadedBulk = true;
}        

function moveBulk(X,Y,e)
{
  if (pageLoadedBulk == true)
  {
    try
    {
      var objClass;

      if (e.srcElement)
        objClass = e.srcElement.className
      else
        objClass = e.target.className

      X = X*scaleBulk;
      Y = Y*scaleBulk;
      newLeft = thumbnailArray[objClass].marginLeft+X;
      newTop = thumbnailArray[objClass].marginTop+Y;                                
      stopX = thumbnailArray[objClass].imgWidth-thumbnailArray[objClass].cropWidth;
      stopY = thumbnailArray[objClass].imgHeight-thumbnailArray[objClass].cropHeight;

      if (newLeft < 0)
        newLeft = 0;

      if (newLeft > stopX)
        newLeft = stopX;

      if (newTop < 0)
        newTop = 0;

      if (newTop > stopY)
        newTop = stopY;

      thumbnailArray[objClass].marginLeft = newLeft;
      thumbnailArray[objClass].marginTop = newTop;
      if (e.srcElement)
        objNode = e.srcElement;
      else
        objNode = e.target;
      while (objNode.id != thumbnailArray[objClass].thumbnailId + "_cropbox")
        objNode = objNode.parentNode;

      updateCropBulk(objNode);
    }
    catch(e) {}
  }
  else
  {
    window.alert("Page loading, please wait.");
  }
}        

function zoomBulk(X,Y,e)
{
  if (pageLoadedBulk == true)
  {
    try
    {
      var objClass;

      if (e.srcElement)
        objClass = e.srcElement.className
      else
        objClass = e.target.className                

      if (thumbnailArray[objClass].ratio == 0)
      {
        Xadj = thumbnailArray[objClass].cropWidth+(X*scaleBulk);
        Yadj = thumbnailArray[objClass].cropHeight+(Y*scaleBulk);
      }
      else
      {
        Xadj = 0;
        Yadj = 0;
      }

      newWidth = thumbnailArray[objClass].cropWidth+(X*scaleBulk);
      newHeight = Math.round(newWidth*thumbnailArray[objClass].ratio)+Yadj;

      if (newWidth < smallestBulk)
      {
        newWidth = smallestBulk;
        newHeight = Math.round(newWidth*thumbnailArray[objClass].ratio)+Yadj;
      }

      if (newHeight < smallestBulk)
      {
        newHeight = smallestBulk;
        newWidth = Math.round(newHeight*thumbnailArray[objClass].invRatio)+Xadj;
      } 

      if (newWidth+thumbnailArray[objClass].marginLeft > thumbnailArray[objClass].imgWidth)
      {
        newWidth = thumbnailArray[objClass].imgWidth-thumbnailArray[objClass].marginLeft;
        newHeight = Math.round(newWidth*thumbnailArray[objClass].ratio)+Yadj;
      } 

      if (newHeight+thumbnailArray[objClass].marginTop > thumbnailArray[objClass].imgHeight)
      {
        newHeight = thumbnailArray[objClass].imgHeight-thumbnailArray[objClass].marginTop;
        newWidth = Math.round(newHeight*thumbnailArray[objClass].invRatio)+Xadj;
      }                

      thumbnailArray[objClass].cropWidth = newWidth;
      thumbnailArray[objClass].cropHeight = newHeight;
 
      if (e.srcElement)
        objNode = e.srcElement;
      else
        objNode = e.target;

      while (objNode.id != thumbnailArray[objClass].thumbnailId + "_cropbox")
        objNode = objNode.parentNode;


      updateCropBulk(objNode);
    }
    catch(e) {}
    
  }
  else
  {
    window.alert("Page loading, please wait.");
  }
}        

function changeRatioBulk(newRatios)
{
  if (pageLoadedBulk == true)
  {
    newRatio = newRatios.split(",");

    for (i=0; i<thumbnailArray.length; i++)
    {
      if (thumbnailArray[i].imgHeight > thumbnailArray[i].imgWidth)
      {
        thumbnailArray[i].ratio = newRatio[1];
        thumbnailArray[i].invRatio = newRatio[0];
      }
      else
      {
        thumbnailArray[i].ratio = newRatio[0];
        thumbnailArray[i].invRatio = newRatio[1];
      }

      if (thumbnailArray[i].ratio == 0)
      {
        document.getElementById('customRatio').style.display = "none";
        thumbnailArray[i].marginTop = 0;
        thumbnailArray[i].marginLeft = 0;
        thumbnailArray[i].cropHeight = thumbnailArray[i].imgHeight;
        thumbnailArray[i].cropWidth = thumbnailArray[i].imgWidth;
      }
      else
      {
        if (newRatios == "custom")
        {
          thumbnailArray[i].ratio = document.cropTool.ratioH.value/document.cropTool.ratioW.value;
          thumbnailArray[i].invRatio = document.cropTool.ratioW.value/document.cropTool.ratioH.value;
          document.getElementById('customRatio').style.display = "block";
        }
        else
          document.getElementById('customRatio').style.display = "none";

        thumbnailArray[i].cropWidth = Math.round(1*thumbnailArray[i].imgWidth);

        thumbnailArray[i].cropHeight = Math.round(thumbnailArray[i].cropWidth*thumbnailArray[i].ratio);        

        if ((thumbnailArray[i].cropHeight > thumbnailArray[i].imgHeight)||(thumbnailArray[i].cropWidth > thumbnailArray[i].imgWidth))
        {
          thumbnailArray[i].cropHeight = thumbnailArray[i].imgHeight;  
          thumbnailArray[i].cropWidth = Math.round(thumbnailArray[i].cropHeight*thumbnailArray[i].invRatio);
        }   

        thumbnailArray[i].marginTop = ((thumbnailArray[i].imgHeight-thumbnailArray[i].cropHeight)/2);
        thumbnailArray[i].marginLeft = ((thumbnailArray[i].imgWidth-thumbnailArray[i].cropWidth)/2);
      }

      updateCropBulk(document.getElementById(thumbnailArray[i].thumbnailId + "_cropbox"));
    }
  }
  else
  {
     window.alert("Page loading, please wait.");
  }
}        

function rotateBulk()
{
  if (pageLoadedBulk == true)
  {
    for (i=0; i<thumbnailArray.length; i++)
    {
      if (thumbnailArray[objClass].ratio == 0)
      {
        Xadj = thumbnailArray[i].cropHeight;
        Yadj = thumbnailArray[i].cropWidth;
      }
      else
      {
        Xadj = 0;
        Yadj = 0;
      }

      temp = thumbnailArray[objClass].invRatio;
      thumbnailArray[objClass].invRatio = thumbnailArray[objClass].ratio;
      thumbnailArray[objClass].ratio = temp;
      temp = thumbnailArray[i].cropWidth;
      thumbnailArray[i].cropWidth = thumbnailArray[i].cropHeight;
      thumbnailArray[i].cropHeight = temp;  

      if (thumbnailArray[i].cropWidth+thumbnailArray[i].marginLeft > thumbnailArray[i].imgWidth)
      {
        thumbnailArray[i].marginLeft = thumbnailArray[i].imgWidth-thumbnailArray[i].cropWidth;

        if (thumbnailArray[i].marginLeft < 0)
        {
          thumbnailArray[i].marginLeft = 0;
          thumbnailArray[i].cropWidth = thumbnailArray[i].imgWidth-thumbnailArray[i].marginLeft;
          thumbnailArray[i].cropHeight = Math.round(thumbnailArray[i].cropWidth*thumbnailArray[objClass].ratio)+Yadj;                        
        }
      } 

      if (thumbnailArray[i].cropHeight+thumbnailArray[i].marginTop > thumbnailArray[i].imgHeight)
      {
        thumbnailArray[i].marginTop = thumbnailArray[i].imgHeight-thumbnailArray[i].cropHeight;

        if (thumbnailArray[i].marginTop < 0)
        {
          thumbnailArray[i].marginTop = 0;
          thumbnailArray[i].cropHeight = thumbnailArray[i].imgHeight-thumbnailArray[i].marginTop;
          thumbnailArray[i].cropWidth = Math.round(thumbnailArray[i].cropHeight*thumbnailArray[objClass].invRatio)+Xadj;
        }
      }

      if (hideRatioBulk != true)
      {
        //temp = document.cropTool.ratioH.value
        //document.cropTool.ratioH.value = document.cropTool.ratioW.value;
        //document.cropTool.ratioW.value = temp;
      }

      updateCropBulk(document.getElementById(thumbnailArray[i].thumbnailId + "_cropbox"));
    }
  }
  else

    window.alert("Page loading, please wait.");
}        

function updateCropBulk(e)
{
  objClass = e.className;
  e.parentNode.style.clip = "rect("+thumbnailArray[objClass].marginTop+"px "+(thumbnailArray[objClass].marginLeft+thumbnailArray[objClass].cropWidth)+"px "+(thumbnailArray[objClass].marginTop+thumbnailArray[objClass].cropHeight)+"px "+thumbnailArray[objClass].marginLeft+"px)";
  e.style.top = thumbnailArray[objClass].marginTop+"px";
  e.style.left = thumbnailArray[objClass].marginLeft+"px";
  e.style.width = thumbnailArray[objClass].cropWidth-thumbnailArray[objClass].cropDiff+"px";
  e.style.height = thumbnailArray[objClass].cropHeight-thumbnailArray[objClass].cropDiff+"px";
}        

function mouseMoveBulk(e)
{
  if (!e) var e = window.event;

  var objClass

  if (e.srcElement)
      objClass = e.srcElement.className;
    else
      objClass = e.target.className;

  if (lookMouse)
  {
    tempX = mouseXBulk;
    tempY = mouseYBulk;
    mouseXBulk = e.clientX;
    mouseYBulk = e.clientY;
    x = mouseXBulk-tempX;
    y = mouseYBulk-tempY;

    if (mouseToolBulk == "zoom")
    {
      if (thumbnailArray[objClass].ratio == 0)
        zoomBulk(x,y,e);
      else
        zoomBulk(x,0,e);
    }
    else
      moveBulk(x,y,e)
  }
}

function testMouseBulk(e)
{
  state = true;
  if (!e) var e = window.event;

  if (mouseToolBulk != "zoom")
  {
    lookMouse = state;

    if (state == true)
    {
      mouseToolBulk = "move";
      mouseXBulk = e.clientX;
      mouseYBulk = e.clientY;
      document.onmousemove = mouseMoveBulk;
    }
  }
}

function testZoomBulk(e)
{
  state=true;
  if (!e) var e = window.event;

  lookMouse = state;
  if (state == true)
  {	            
    mouseToolBulk = "zoom"
    mouseXBulk = e.clientX;
    mouseYBulk = e.clientY;
    document.onmousemove = mouseMoveBulk;
  }
}

function cancelMouse()
{
  mouseToolBulk = "move";
  lookMouse = false;
}

document.onmouseup = cancelMouse;

function isClass(sClass) {
  sClassName = document.body.className;

  re = new RegExp(sClass + "( |$)") 

  if (!sClassName)
    return false;
  return re.test(sClassName);
}