function checkSearchSubmit()
{
    var searchField = YD.get("searchWords");
    var searchVal = SM.util.trimString(searchField.value);
    if ((searchVal == "") || (searchVal == "Search"))
    {
        return(false);
    }
    checkInput('Search','searchWords',' ');
    return(true);
}


YE.onContentReady("searchBox", function() {this.setAttribute("onsubmit", "return checkSearchSubmit()");}
);

function hasPath(sPath)
{
re = new RegExp("\/" + sPath + "(\/|$)");
return re.test(window.location)
}

if (hasPath("featured"))
YD.addClass(document.body, "featured");


// On IE/FF set the title before the Document OnLoad takes place
document.title = "Free American flag images along with stock photos for sale and stock business card templates";
addEvent( window, "load", CustomizeTitle );
function CustomizeTitle()
{
    var baseTitle = "Stock photography by Mark Javer at 360photostock.com";
    var separator = " - ";
    var albumTitle = GetText( document.getElementById("albumTitle") );
    var galleryTitle = GetText( document.getElementById("galleryTitle") );
    var subCatTitle = GetText ( document.getElementById("subCatGalleryTitle") );
    var singleImage = document.body.className && document.body.className.indexOf("singleImage") > -1 ? true : false;
    var pageTypeDefined = typeof( pageType ) != "undefined";
    var pageTypeDetailsDefined = typeof( pageTypeDetails ) != "undefined";
// Don't change the title from the above document.title on the homepage
    if( document.body.className && document.body.className.indexOf("homepage") > -1 )
    {
        document.title = baseTitle + separator + "Home";
        return;
    }
 
// An album page (holds a bunch of photos, could be "zoomed in" on a specific photo)
    if( albumTitle )
    {
        var photoTitle = GetPhotoTitle();
        if( photoTitle )
            document.title = baseTitle + separator + albumTitle + separator + photoTitle;
        else
            document.title = baseTitle + separator + albumTitle;
        return;
    }
// A gallery page (holds a bunch of albums and/or a bunch of sub categories)
    if( galleryTitle )
    {
// Strip " sub-categories" off the end of the category text
        var finalPositionCategory = galleryTitle.indexOf(" sub-categories");
        if( finalPositionCategory > -1 )
            galleryTitle = galleryTitle.substr( 0, finalPositionCategory );
        else
            {
// Strip " galleries" off the end of the category/sub-category text
              var finalPositionSubCategory = galleryTitle.indexOf(" galleries");
              if( finalPositionSubCategory > -1 )
          galleryTitle = galleryTitle.substr( 0, finalPositionSubCategory );
             }
 
            document.title = baseTitle + separator + galleryTitle;
    return;
    }
// Pick up sub-category
    if( subCatTitle )
    {
// Strip " sub-categories" off the end of the category text
        var finalPositionCategory = subCatTitle.indexOf(" sub-categories");
        if( finalPositionCategory > -1 )
            galleryTitle = subCatTitle.substr( 0, finalPositionCategory );
        else
            {
// Strip " galleries" off the end of the category/sub-category text
              var finalPositionSubCategory = subCatTitle.indexOf(" galleries");
              if( finalPositionSubCategory > -1 )
          galleryTitle = subCatTitle.substr( 0, finalPositionSubCategory );
             }
 
            document.title = baseTitle + separator + galleryTitle;
    return;
    }
 
// A single image (like the kind you get when you click an image in a keyword page)
    if( singleImage )
        {
 var photoTitle = GetPhotoTitle();
 if( photoTitle )
            document.title = baseTitle + separator + photoTitle;
 else
     document.title = baseTitle + separator + "untitled photo";
 return;
 }
// A single keyword page
    if( pageTypeDefined && pageType == 'Keyword' && pageTypeDetailsDefined )
 {
// Keyword page
             document.title = baseTitle + separator + "Keyword: " + pageTypeDetails;
     return;
 }
// A multiple keyword page
    if( pageTypeDefined && pageType == 'Keywords' && pageTypeDetailsDefined )
 {
// Multiple keywords page
// Put " + " between each keyword instead of -
             var keywordList = pageTypeDetails;
     keywordList = keywordList.replace(/\-/g, " + ");
     document.title = baseTitle + separator + "Keywords: " + keywordList;
     return;
 }
// The main keywords page. Note: single image takes precedence over this type
    if( document.body.className && document.body.className.indexOf("keywordPage") > -1 )
        {
// Main Keywords Page
            document.title = baseTitle + separator + "Keywords";
            return;
 }
// None of the rules above set the title! Oh well, fall back on the base title.
    document.title = baseTitle;
} // CustomizeTitle
function Trim( text )
{
    text = text.replace(/(^\s+)|(\s+$)/g, ""); // trim leading and trailing white space
    return text;
} // Trim
function GetText( node )
{
    if( !node )
        return "";
    if( node.innerText )
        return Trim( node.innerText ); // For IE
    if( node.textContent )
        return Trim( node.textContent ); // For others
    return "";
} // GetText
function GetPhotoTitle()
{
// If the photo title is set, it starts with the breadcrumb.
    var breadCrumbStart = "360photostock.com > ";
    var mainPhoto = document.getElementById("mainPhoto");
    if( !mainPhoto || !mainPhoto.title || mainPhoto.title.indexOf( breadCrumbStart ) != 0 )
 return "";
    return Trim( mainPhoto.title.substr( breadCrumbStart.length ) );
} // GetPhotoTitle

function norobotmail(aUser, aDomain) { document.location = "mailto:" + aUser + "@" + aDomain; }



rightClickWarning = "Thank you for visiting, These are copyright protected designs. Enjoy the rest of your visit to 360photostock.com";


/*==============================*/
/*== Bulk Zoom thumbnail v3.1 ==*/
/*==============================*/
var thumbnailArray = new Array();
var thumbnailCount;
var thumbnailItem;
var thumbnailEXIFArray = new Array();
var reqIncrement = 0;

YE.on(window, "load", addBulkThumbnail);

function addBulkThumbnail() {
  if (YD.hasClass(document.body,"galleryPage") && YD.hasClass(document.body,"loggedIn")) {
    if (YD.hasClass(document.body,"traditional") || YD.hasClass(document.body,"allthumbs") ||  YD.hasClass(document.body,"smugmug")) {
      onStartBulk();

      var divTag = YD.get("photoTools");

      YD.get("bulkSave").disabled = true;

      var objSpan = document.createElement("span");
      objSpan.className = "foreground";
      divTag.appendChild(objSpan);

      var objButton = document.createElement("input");
      objButton.type = "checkbox";
      objButton.id = "bulkzoom";
      objSpan.appendChild(objButton);
      YE.on(objButton, "click", toggleBulkZoom);

      var objText = document.createTextNode(' bzt');
      objSpan.appendChild(objText);
    }
  }
}

function toggleBulkZoom() {
  if (YD.get('bulkzoom').checked)
    processThumbnails();
  else
    window.location.reload();
}

function processThumbnails() {
  var re = /\/photos\/(\d+)_(\w+)\-(Ti|Th)/;

  YD.get("ajaxWorking").innerHTML = "<strong><strong>Loading...</strong></strong>"
  toggleDIV('ajaxWorking','','block');

  YD.get("bulkzoom_toolbox").style.display = "";

  var divTag = YD.get("thumbnails") ? YD.get("thumbnails") : YD.get("photos");

  if (divTag) {
    var divTags = YD.getElementsByClassName("photo", "div", divTag);
    for (var i = 0, len = divTags.length; i < len; i++) {
      if (re.test(divTags[i].innerHTML)) {
        re.exec(divTags[i].innerHTML);
        thumbnailEXIFArray.push({"id": RegExp.$1, "key": RegExp.$2});
      }
    }
  }
  getThumbnailEXIF();
}

function maskThumbnails(objThumbnail, j) {
  var re1 = /\/gallery\/\d+_\w+\/\d+\/(\d+)_(\w+)/;
  var re2 = /javascript\:openLB\(([0-9]+),/;
  var re3 = /#(\d+)(_(\w+))?/;

  var divTag = YD.get("thumbnails") ? YD.get("thumbnails") : YD.get("photos");

  if (divTag) {
    divTags = YD.getElementsByClassName("photo", "div", divTag);

    for (var i = 0, len = divTags.length; i < len; i++) {
      if (re1.test(divTags[i].innerHTML))
        re1.exec(divTags[i].innerHTML);
      else
      {
        if (re2.test(divTags[i].innerHTML))
          re2.exec(divTags[i].innerHTML);
        else {
          if (re3.test(divTags[i].innerHTML))
            re3.exec(divTags[i].innerHTML);
          else
            continue;
        }
          
      }

      var thumbnailId = RegExp.$1;
      var thumbnailKey = RegExp.$2;

      var aTags = divTags[i].getElementsByTagName("a");
      var imgTags = aTags[0].getElementsByTagName("img");

      if (objThumbnail.id == thumbnailId) {
        var 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="+ objThumbnail.id + "&ImageKey="+ objThumbnail.key + "') no-repeat; width: " + objThumbnail.imgWidth + "px; height: " + objThumbnail.imgHeight + "px; z-index: 1; margin:0px auto; text-align:left;";

        var clearedDiv = document.createElement("div");
        clearedDiv.id = thumbnailId + "_cleared";
        clearedDiv.className = j;
        clearedDiv.style.cssText = "position: absolute; background: url('" + objThumbnail.url + "') 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);

        var 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";
        YE.on(cropboxDiv, "mousedown", testMouseBulk);
        clearedDiv.appendChild(cropboxDiv);

        var 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;";
        YE.on(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.shift();

  if (thumbnail) {
    var postArray = new Array();
    postArray['method'] = "getImageInfo";
    postArray['imageId'] = thumbnail.id;
    postArray['imageKey'] = thumbnail.key;
    ajax_query(processThumbnailEXIF, webServer+'/rpc/image.mg', postArray, true);
    window.setTimeout(getThumbnailEXIF, 100);
  }
  else
  {
    toggleDIV('','ajaxWorking','block');

    if (YD.hasClass(document.body,"loggedIn"))
      YD.get("bulkSave").disabled = false;
  }
}

function processThumbnailEXIF(response) {

  var json = eval('(' + response + ')');

  var imgWidth = parseInt(json.result.OriginalWidth);
  var imgHeight = parseInt(json.result.OriginalHeight);

  var obj = {"id": json.result.ImageID, "key": json.result.imageKey, "url": json.result.SmallURL};

  obj.imgHeight = (imgWidth < imgHeight) ? 300 : Math.round((imgHeight / imgWidth) * 400);
  obj.imgWidth = (imgWidth < imgHeight) ? Math.round((imgWidth / imgHeight) * 300) : 400;
  obj.ratio = 0;
  obj.invRatio = 0;
  obj.marginTop = 0;
  obj.marginLeft = 0;
  obj.cropHeight = obj.imgHeight;
  obj.cropWidth = obj.imgWidth;
  obj.oRatio = (imgWidth / obj.imgWidth);
  obj.cropDiff = 0;

  thumbnailArray.push(obj);

  maskThumbnails(thumbnailArray[thumbnailArray.length-1], "bzt_"+ (thumbnailArray.length-1));
}

function zoomThumbnails() {
  if (!thumbnailItem) {
    thumbnailItem = 0;
    thumbnailCount = thumbnailArray.length;
  }

  var thumbnail = thumbnailArray.shift();
  
  if (thumbnail) {
    thumbnailItem++; 
























    postArray = new Array();
    postArray['tool'] = 'newthumb';
    postArray['ImageID'] = thumbnail.id;
    postArray['ImageKey'] = thumbnail.key;
    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.reload();
  }
}

function updateAjaxStatus(sStr) {
  var ajx = YD.get("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 = (e.srcElement) ? e.srcElement.className : e.target.className;
      var obj = thumbnailArray[objClass.replace("bzt_", "")];

      X = X*scaleBulk;
      Y = Y*scaleBulk;
      var newLeft = obj.marginLeft+X;
      var newTop = obj.marginTop+Y;                                
      var stopX = obj.imgWidth - obj.cropWidth;
      var stopY = obj.imgHeight - obj.cropHeight;

      if (newLeft < 0)
        newLeft = 0;

      if (newLeft > stopX)
        newLeft = stopX;

      if (newTop < 0)
        newTop = 0;

      if (newTop > stopY)
        newTop = stopY;

      obj.marginLeft = newLeft;
      obj.marginTop = newTop;

      var objNode = (e.srcElement) ? e.srcElement : e.target;

      while (objNode.id != obj.id + "_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 = (e.srcElement) ? e.srcElement.className : e.target.className;
      var obj = thumbnailArray[objClass.replace("bzt_", "")];              

      var Xadj = (obj.ratio == 0) ? obj.cropWidth+(X*scaleBulk) : 0;
      var Yadj = (obj.ratio == 0) ? obj.cropHeight+(Y*scaleBulk) : 0;

      var newWidth = obj.cropWidth+(X*scaleBulk);
      var newHeight = Math.round(newWidth*obj.ratio)+Yadj;

      if (newWidth < smallestBulk) {
        newWidth = smallestBulk;
        newHeight = Math.round(newWidth*obj.ratio)+Yadj;
      }

      if (newHeight < smallestBulk) {
        newHeight = smallestBulk;
        newWidth = Math.round(newHeight*obj.invRatio)+Xadj;
      } 

      if (newWidth+obj.marginLeft > obj.imgWidth) {
        newWidth = obj.imgWidth-obj.marginLeft;
        newHeight = Math.round(newWidth*obj.ratio)+Yadj;
      } 

      if (newHeight+obj.marginTop > obj.imgHeight) {
        newHeight = obj.imgHeight-obj.marginTop;
        newWidth = Math.round(newHeight*obj.invRatio)+Xadj;
      }                

      obj.cropWidth = newWidth;
      obj.cropHeight = newHeight;

      var objNode = (e.srcElement) ? e.srcElement : e.target;

      while (objNode.id != obj.id + "_cropbox")
        objNode = objNode.parentNode;

      updateCropBulk(objNode);
    }
    catch(e) {}
    
  }
  else {
    window.alert("Page loading, please wait.");
  }
}        

function changeRatioBulk(newRatios) {
  if (pageLoadedBulk == true) {
    var newRatio = newRatios.split(",");

    for (i=0; i<thumbnailArray.length; i++) {
      var obj = thumbnailArray[i];

      if (obj.imgHeight > obj.imgWidth) {
        obj.ratio = newRatio[1];
        obj.invRatio = newRatio[0];
      }
      else {
        obj.ratio = newRatio[0];
        obj.invRatio = newRatio[1];
      }

      if (obj.ratio == 0) {
        YD.get('customRatio').style.display = "none";
        obj.marginTop = 0;
        obj.marginLeft = 0;
        obj.cropHeight = obj.imgHeight;
        obj.cropWidth = obj.imgWidth;
      }
      else {
        if (newRatios == "custom") {
          obj.ratio = document.cropTool.ratioH.value/document.cropTool.ratioW.value;
          obj.invRatio = document.cropTool.ratioW.value/document.cropTool.ratioH.value;
          YD.get('customRatio').style.display = "block";
        }
        else
          YD.get('customRatio').style.display = "none";

        obj.cropWidth = Math.round(1 * obj.imgWidth);

        obj.cropHeight = Math.round(obj.cropWidth * obj.ratio);        

        if ((obj.cropHeight > obj.imgHeight)||(obj.cropWidth > obj.imgWidth)) {
          obj.cropHeight = obj.imgHeight;  
          obj.cropWidth = Math.round(obj.cropHeight * obj.invRatio);
        }   

        obj.marginTop = ((obj.imgHeight - obj.cropHeight)/2);
        obj.marginLeft = ((obj.imgWidth - obj.cropWidth)/2);
      }

      updateCropBulk(YD.get(thumbnailArray[i].id + "_cropbox"));
    }
  }
  else {
     window.alert("Page loading, please wait.");
  }
}        

function rotateBulk() {
  if (pageLoadedBulk == true) {
    for (i=0; i<thumbnailArray.length; i++) {
      var obj = thumbnailArray[i];

      var Xadj = (obj.ratio == 0) ? obj.cropHeight : 0;
      var Yadj = (obj.ratio == 0) ? obj.cropWidth : 0;

      var temp = obj.invRatio;
      obj.invRatio = obj.ratio;
      obj.ratio = temp;
      temp = obj.cropWidth;
      obj.cropWidth = obj.cropHeight;
      obj.cropHeight = temp;  

      if (obj.cropWidth + obj.marginLeft > obj.imgWidth) {
        obj.marginLeft = obj.imgWidth - obj.cropWidth;

        if (obj.marginLeft < 0) {
          obj.marginLeft = 0;
          obj.cropWidth = obj.imgWidth - obj.marginLeft;
          obj.cropHeight = Math.round(obj.cropWidth * obj.ratio)+Yadj;                        
        }
      } 

      if (obj.cropHeight + obj.marginTop > obj.imgHeight) {
        obj.marginTop = obj.imgHeight - obj.cropHeight;

        if (obj.marginTop < 0) {
          obj.marginTop = 0;
          obj.cropHeight = obj.imgHeight - obj.marginTop;
          obj.cropWidth = Math.round(obj.cropHeight * obj.invRatio)+Xadj;
        }
      }

      updateCropBulk(YD.get(obj.id + "_cropbox"));
    }
  }
  else
    window.alert("Page loading, please wait.");
}        

function updateCropBulk(e) {
  var objClass = e.className;
  var obj = thumbnailArray[objClass.replace("bzt_", "")];

  e.parentNode.style.clip = "rect("+obj.marginTop+"px "+(obj.marginLeft+obj.cropWidth)+"px "+(obj.marginTop+obj.cropHeight)+"px "+obj.marginLeft+"px)";
  e.style.top = obj.marginTop+"px";
  e.style.left = obj.marginLeft+"px";
  e.style.width = obj.cropWidth-obj.cropDiff+"px";
  e.style.height = obj.cropHeight-obj.cropDiff+"px";
}        

function mouseMoveBulk(e) {
  if (!e) var e = window.event;

   var objClass = (e.srcElement) ? e.srcElement.className : e.target.className;

  if (lookMouse) {
    var tempX = mouseXBulk;
    var tempY = mouseYBulk;
    mouseXBulk = e.clientX;
    mouseYBulk = e.clientY;
    var x = mouseXBulk-tempX;
    var y = mouseYBulk-tempY;

    if (mouseToolBulk == "zoom") {
      if (thumbnailArray[objClass.replace("bzt_","")].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;




// On IE/FF set the title before the Document OnLoad takes place
addEvent( window, "load", CustomizeTitle );

function CustomizeTitle()
{
	var baseTitle = "360photostock.com";
	var separator = " - ";
	var albumTitle = GetText( document.getElementById("albumTitle") );
	var galleryTitle = GetText( document.getElementById("galleryTitle") );
	var singleImage = document.body.className && document.body.className.indexOf("singleImage") > -1 ? true : false;
	var pageTypeDefined = typeof( pageType ) != "undefined";
	var pageTypeDetailsDefined = typeof( pageTypeDetails ) != "undefined";

	// Don't change the title from the above document.title on the homepage
	if( document.body.className && document.body.className.indexOf("homepage") > -1 )
	{
		document.title = baseTitle + separator + "Home";
		return;
	}

	// The guestbook album gets a special title
	if( window.AlbumID && window.AlbumID == "1128948" )
	{
		// Guest Book
		document.title = "Mark Javer's guestbook";
		return;
	}

	// An album page (holds a bunch of photos, could be "zoomed in" on a specific photo)
	if( albumTitle )
	{
		var photoTitle = GetPhotoTitle();
		if( photoTitle )
			document.title = baseTitle + separator + albumTitle + separator + photoTitle;
		else
			document.title = baseTitle + separator + albumTitle;
		return;
	}

	// A gallery page (holds a bunch of albums and/or a bunch of sub categories)
	if( galleryTitle )
	{
		// Strip " sub-categories" off the end of the category text
		var finalPositionCategory = galleryTitle.indexOf(" sub-categories");
		if( finalPositionCategory > -1 )
			galleryTitle = galleryTitle.substr( 0, finalPositionCategory );
		else
		{
			// Strip " galleries" off the end of the category/sub-category text
			var finalPositionSubCategory = galleryTitle.indexOf(" galleries");
			if( finalPositionSubCategory > -1 )
				galleryTitle = galleryTitle.substr( 0, finalPositionSubCategory );
		}
		document.title = baseTitle + separator + galleryTitle;
		return;
	}

	// A single image (like the kind you get when you click an image in a keyword page)
	if( singleImage )
	{
		var photoTitle = GetPhotoTitle();
		if( photoTitle )
			document.title = baseTitle + separator + photoTitle;
		else
			document.title = baseTitle + separator + "untitled photo";
		return;
	}

	// A single keyword page
	if( pageTypeDefined && pageType == 'Keyword' && pageTypeDetailsDefined )
	{
		// Keyword page
		document.title = baseTitle + separator + "Keyword: " + pageTypeDetails;
		return;
	}

	// A multiple keyword page
	if( pageTypeDefined && pageType == 'Keywords' && pageTypeDetailsDefined )
	{
		// Multiple keywords page
		// Put " + " between each keyword instead of -
		var keywordList = pageTypeDetails;
		keywordList = keywordList.replace(/\-/g, " + ");
		document.title = baseTitle + separator + "Keywords: " + keywordList;
		return;
	}

	// The main keywords page. Note: single image takes precedence over this type
	if( document.body.className && document.body.className.indexOf("keywordPage") > -1 )
	{
		// Main Keywords Page
		document.title = baseTitle + separator + "Keywords";
		return;
	}

	// None of the rules above set the title! Oh well, fall back on the base title.
	document.title = baseTitle;
} // CustomizeTitle

function Trim( text )
{
	text = text.replace(/(^\s+)|(\s+$)/g, ""); // trim leading and trailing white space
	return text;
} // Trim

function GetText( node )
{
	if( !node )
		return "";
	if( node.innerText )
		return Trim( node.innerText ); // For IE
	if( node.textContent )
		return Trim( node.textContent ); // For others
	return "";
} // GetText

function GetPhotoTitle()
{
	// If the photo title is set, it starts with the breadcrumb.

	var breadCrumbStart = "360photostock > ";
	var mainPhoto = document.getElementById("mainPhoto");
	if( !mainPhoto || !mainPhoto.title || mainPhoto.title.indexOf( breadCrumbStart ) != 0 )
		return "";
	return Trim( mainPhoto.title.substr( breadCrumbStart.length ) );
} // GetPhotoTitle


 YE.onContentReady('buyButton', function() {YAHOO.widget.Button.getButton("buyButton").set("label", "Purchase Options");});




function photoHoverLeft(photoID,photoImageID,waited){var position=SM.PhotoBar.config.position||'right';var hoverPhoto=YD.get(photoID);if(SM.menus.menuOpen>0){return;}
if(photoInfo[photoImageID].Format!=="ARC"){if(!showPhotoBar||hoverPhoto.offsetWidth*hoverPhoto.offsetHeight<30000||photoInfo[photoImageID]===undefined||photoHovering||photoInfo[photoImageID].Format==="MPG"||(YD.inDocument('themeChoicesContainer')&&parseInt(YD.getStyle('themeChoicesContainer','height'),10)!==0)){return;}}
if(!waited){YE.addListener(document,'mousemove',watchPhotoBar,photoID);photoBarTimeout=setTimeout("photoHover('"+photoID+"', '"+photoImageID+"', true)",photoBarDelay*1000);return;}
if(YD.inDocument('photoBarBg')&&YD.inDocument('photoBarContent')&&!YD.hasClass('photoBarContent','photoId_'+photoImageID)){removeFromDOM('photoBarBg');removeFromDOM('photoBarContent');}
var hoverRegion=YAHOO.util.Region.getRegion(hoverPhoto);var photoBarBg=YD.get('photoBarBg');var photoBarContent=YD.get('photoBarContent');if(!photoBarBg){photoBarBg=document.createElement('div');photoBarBg.setAttribute('id','photoBarBg');photoBarBg.className=position;document.body.appendChild(photoBarBg);YD.setStyle(photoBarBg,'zIndex',getZindex(hoverPhoto)+1);photoBarBg.innerHTML='<div class="first"></div><div class="middle"></div><div class="last"></div>';YE.on(window,'resize',function(){if(photoBarBg&&photoBarBg.offsetWidth<=1){YD.setStyle(photoBarBg,'left',0);if(photoBarContent){YD.setStyle(photoBarContent,'left',0);}}});}
var photoImageKey=photoInfo[photoImageID].ImageKey;if(!photoBarContent){photoBarContent=document.createElement("div");photoBarContent.setAttribute('id','photoBarContent');YD.addClass(photoBarContent,position);YD.addClass(photoBarContent,'photoId_'+photoImageID);document.body.appendChild(photoBarContent);YD.setStyle(photoBarContent,'zIndex',getZindex(photoBarBg)+1);if(displaySmugPopular&&photoInfo[photoImageID].Format!=="ARC"){if(photoInfo[photoImageID].displayPopular){var photoRank=document.createElement('div');YD.addClass(photoRank,'photoRank');photoRank.id='photoRank';if(photoBarContent.childNodes.length===0){YD.addClass(photoRank,'first');}
photoBarContent.appendChild(photoRank);var postArray=[];postArray.tool='smugPopular';postArray.ImageID=photoImageID;postArray.ImageKey=photoImageKey;if(Yua.ie!==6){ajax_query(smugPopularResponse,'/rpc/gallery.mg',postArray,true);}}}
if(photoInfo[photoImageID].Format!=="MP4"&&photoInfo[photoImageID].Format!=="ARC"){if(YD.getStyle(YD.get('lightBoxStage'),'display')!=="block"){var photoSizes=document.createElement("div");YD.addClass(photoSizes,"photoSizes");photoSizes.setAttribute("id","photoSizes");if(photoBarContent.childNodes.length===0){YD.addClass(photoSizes,'first');}
photoBarContent.appendChild(photoSizes);photoSizes.innerHTML='<h4>Photo Sizes</h4>';var photoSizesContent=document.createElement("ul");photoSizes.appendChild(photoSizesContent);photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-S-LB">Small<\/a></li>';photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-M-LB">Medium<\/a></li>';if(photoInfo[photoImageID].albumLarges){photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-L-LB">Large<\/a></li>';if(photoInfo[photoImageID].hasXLarges){if(photoInfo[photoImageID].albumXLarges){photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-XL-LB">XLarge<\/a></li>';}
if(photoInfo[photoImageID].albumX2Larges){photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-X2-LB">X2Large<\/a></li>';}
if(photoInfo[photoImageID].albumX3Larges){photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-X3-LB">X3Large<\/a></li>';}}
if(photoInfo[photoImageID].albumOriginals){photoSizesContent.innerHTML+='<li><a href="#'+photoImageID+'_'+photoImageKey+'-O-LB">Original<\/a></li>';}}}}else if(photoInfo[photoImageID].Format!=="ARC"&&(photoInfo[photoImageID].canEdit||(!photoInfo[photoImageID].canEdit&&!photoInfo[photoImageID]['protected']))){var photoSizes=document.createElement("div");YD.addClass(photoSizes,"photoSizes");photoSizes.setAttribute("id","photoSizes");if(photoBarContent.childNodes.length===0){YD.addClass(photoSizes,'first');}
photoBarContent.appendChild(photoSizes);photoSizes.innerHTML='<h4>Save Movie</h4>';photoSizes.innerHTML+='<img id="savePhotoButton" src="/img/spacer.gif" width="28" height="31" border="0" style="cursor: pointer" />';YE.on('savePhotoButton','click',function(){if(YD.getStyle('photoSizesContent','display')!=='block'){YD.setStyle('photoSizesContent','display','block');}else{YD.setStyle('photoSizesContent','display','none');}
YD.setStyle(photoBarBg.childNodes[1],'height',photoBarContent.offsetHeight-photoBarBg.childNodes[0].offsetHeight+'px');YD.setStyle(photoBarBg,'height',YD.getStyle(photoBarBg.childNodes[1],'height'));});var photoSizesContent=document.createElement("ul");photoSizesContent.id='photoSizesContent';YD.setStyle(photoSizesContent,'display','none');YD.setStyle(photoSizesContent,'marginTop','3px');photoSizes.appendChild(photoSizesContent);photoSizesContent.innerHTML+='<li style="margin-bottom: 3px;"><strong style="text-decoration: underline;">Size:</strong></li>';photoSizesContent.innerHTML+='<li><a href="/photos/'+photoImageID+'_'+photoImageKey+'-320D.mp4">Web<\/a></li>';if(photoInfo[photoImageID]['640Movie']){photoSizesContent.innerHTML+='<li><a href="/photos/'+photoImageID+'_'+photoImageKey+'-640D.mp4">iPod/DVD<\/a></li>';}
if(photoInfo[photoImageID]['960Movie']){photoSizesContent.innerHTML+='<li><a href="/photos/'+photoImageID+'_'+photoImageKey+'-960D.mp4">Mid-Def<\/a></li>';}
if(photoInfo[photoImageID]['1280Movie']){photoSizesContent.innerHTML+='<li><a href="/photos/'+photoImageID+'_'+photoImageKey+'-1280D.mp4">HiDef<\/a></li>';}
if(photoInfo[photoImageID].Archive){photoSizesContent.innerHTML+='<li style="margin: 5px 0 3px 0;"><strong style="text-decoration: underline;">Archive:</strong></li>';for(var i in photoInfo[photoImageID].Archive){var obj=photoInfo[photoImageID].Archive[i];photoSizesContent.innerHTML+='<li><a href="'+obj.URL+'" title="'+obj.FileName+'" alt="'+obj.FileName+'">'+obj.FileName.split('.').pop().toUpperCase()+'<\/a></li>';}}}
if(photoInfo[photoImageID].displayEXIF&&photoInfo[photoImageID].Format!=="MP4"&&photoInfo[photoImageID].Format!=="ARC"){var photoExif=document.createElement("div");photoExif.setAttribute("id","photoExif");if(photoBarContent.childNodes.length===0){YD.addClass(photoExif,'first');}
photoBarContent.appendChild(photoExif);photoExif.innerHTML='<h4>Photo Info</h4>';photoExif.innerHTML+='<a href="javascript:exifDetails('+photoImageID+', \''+photoImageKey+'\');"><img id="photoInfoButton" src="/img/spacer.gif" width="27" height="27" border="0" /></a>';}
if((photoInfo[photoImageID].canEdit||(photoInfo[photoImageID].albumOriginals&&!photoInfo[photoImageID]['protected']))&&photoInfo[photoImageID].Format!=="MP4"){var photoSave=document.createElement("div");photoSave.setAttribute("id","photoSave");if(photoBarContent.childNodes.length===0){YD.addClass(photoSave,'first');}
photoBarContent.appendChild(photoSave);if(photoInfo[photoImageID].canEdit){photoSave.innerHTML='<h4>Owner Save</h4>';}
else if(photoInfo[photoImageID].Format==="ARC"){photoSave.innerHTML='<h4>Save File</h4>';}
else{photoSave.innerHTML='<h4>Save Photo</h4>';}
photoSave.innerHTML+='<img id="savePhotoButton" src="/img/spacer.gif" width="28" height="31" border="0" style="cursor:pointer" />';if(photoInfo[photoImageID].Archive&&((photoInfo[photoImageID].Format==="ARC"&&photoInfo[photoImageID].Archive.length>1)||photoInfo[photoImageID].Format!=="ARC")){YE.on('savePhotoButton','click',function(){if(YD.getStyle('photoSaveContent','display')!=='block'){YD.setStyle('photoSaveContent','display','block');}else{YD.setStyle('photoSaveContent','display','none');}
YD.setStyle(photoBarBg.childNodes[1],'height',photoBarContent.offsetHeight-photoBarBg.childNodes[0].offsetHeight+'px');YD.setStyle(photoBarBg,'height',YD.getStyle(photoBarBg.childNodes[1],'height'));});var photoSaveContent=document.createElement("ul");photoSaveContent.id='photoSaveContent';YD.setStyle(photoSaveContent,'display','none');YD.setStyle(photoSaveContent,'marginTop','3px');photoSave.appendChild(photoSaveContent);photoSaveContent.innerHTML+='<li style="margin-bottom: 3px;"><strong style="text-decoration: underline;">File:</strong></li>';if(photoInfo[photoImageID].Format!=="ARC"){photoSaveContent.innerHTML+='<li><a href="/photos/'+photoImageID+'_'+photoImageKey+'-D.jpg">Original<\/a></li>';}
for(var i in photoInfo[photoImageID].Archive){var obj=photoInfo[photoImageID].Archive[i];photoSaveContent.innerHTML+='<li><a href="'+obj.URL+'" title="'+obj.FileName+'" alt="'+obj.FileName+'">'+obj.FileName.split('.').pop().toUpperCase()+'<\/a></li>';}}
else{if(photoInfo[photoImageID].Format==="ARC"){var linkage=photoInfo[photoImageID].Archive[0].URL;}
else{var linkage='/photos/'+photoImageID+'_'+photoImageKey+'-D.jpg';}
YE.on('savePhotoButton','click',function(){location.href=linkage;});}}
if(Yua.ie===6&&hoverPhoto.offsetHeight<photoBarContent.offsetHeight+20){YD.setStyle('photoTools','visibility','hidden');}}
switch(position){case'right':YD.setStyle(photoBarBg.childNodes[1],'height',photoBarContent.offsetHeight-photoBarBg.childNodes[0].offsetHeight+'px');YD.setStyle(photoBarBg,'height',YD.getStyle(photoBarBg.childNodes[1],'height'));YD.setXY(photoBarBg,[hoverRegion.left,hoverRegion.top]);YD.setXY(photoBarContent,[hoverRegion.left-photoBarContent.offsetWidth,hoverRegion.top]);var attr={'left':{'by':-97},'width':{'to':96}};break;case'bottom':if(Yua.ie===6){YD.setStyle(photoBarBg.childNodes[1],'width',photoBarContent.offsetWidth+'px');}else{YD.setStyle(photoBarBg.childNodes[1],'width',photoBarContent.offsetWidth-photoBarBg.childNodes[0].offsetWidth+'px');}
YD.setStyle(photoBarBg,'width',YD.getStyle(photoBarBg.childNodes[1],'width'));YD.setXY(photoBarBg,[hoverRegion.left-(hoverPhoto.offsetWidth/2)-(photoBarBg.offsetWidth/2),hoverRegion.bottom]);if(Yua.ie===6){YD.setXY(photoBarContent,[hoverRegion.left-(hoverPhoto.offsetWidth/2)-(photoBarBg.offsetWidth/2)+photoBarBg.childNodes[0].offsetWidth,hoverRegion.bottom+7]);}else{YD.setXY(photoBarContent,[hoverRegion.left-(hoverPhoto.offsetWidth/2)-(photoBarBg.offsetWidth/2),hoverRegion.bottom]);}
var attr={'height':{'to':100}};if(Yua.ie===6){YD.setStyle('photoTools','visibility','hidden');}}
photoHovering=true;switch(position){case'right':if(parseInt(YD.getStyle(photoBarBg,'width'),10)>0){YD.setStyle(photoBarBg,'width',0);}
break;case'bottom':if(parseInt(YD.getStyle(photoBarBg,'height'),10)>0){YD.setStyle(photoBarBg,'height',0);}
break;}
photoHoveringAnimation=new YAHOO.util.Anim(photoBarBg,attr,.5,YAHOO.util.Easing.backOut);photoHoveringAnimation.onComplete.subscribe(function(e){if(Yua.ie===6){var postArray=[];postArray.tool='smugPopular';postArray.ImageID=photoImageID;postArray.ImageKey=photoImageKey;ajax_query(smugPopularResponse,'/rpc/gallery.mg',postArray,true);}
if(photoHovering){YD.setStyle('photoBarContent','visibility','visible');}});photoHoveringAnimation.animate();}

function photoHover(photoID, photoImageID, waited) {
   photoHoverLeft(photoID, photoImageID, waited);
};



// code to insert a download button for any gallery that has originals enabled

function IsSmugmugView()
{
    return(YD.hasClass(document.body, "smugmug"));
}

function IsGalleryPage()
{
	return(YD.hasClass(document.body, "galleryPage"));
}

onPhotoShow.subscribe(ProcessDownloadButton);

function ProcessDownloadButton()
{
	// set onlyInGalleries to true if you only want a download button in gallery views
	// set onlyInGalleries to false if you want a download button in other views too like (search, keywords, date, etc...)
	var onlyInGalleries = false;
	if (IsSmugmugView() && (IsGalleryPage() || !onlyInGalleries))
	{
		if (photoInfo[ImageID].albumOriginals && !photoInfo[ImageID]['protected'] && (photoInfo[ImageID].Format !== "MP4"))
		{
			var downloadParent = "cartButtonsWrapper";
			if (!document.getElementById("cartButtonsWrapper"))
			{
				downloadParent = "altViews";
			}
			InsertDownloadButton(downloadParent);
		}
		else
		{
			// disable the button
			var downloadButton = YAHOO.widget.Button.getButton("downloadButtonId");
			if (downloadButton)
			{
				downloadButton.set("disabled", true);
			}
		}
	}
}

function InsertDownloadButton(parentId)
{
	// now add the download button
	var parentDiv = document.getElementById(parentId);
	var downloadButton = document.getElementById("downloadButtonId");
	if (downloadButton)
	{
		// make sure it is enabled
	YAHOO.widget.Button.getButton("downloadButtonId").set("disabled", false);
	}
	else if (parentDiv)
	{
		var downloadButtonInfo =
		{
			id: "downloadButtonId",
			label: "Download Image...",
			container: parentDiv,
			type: "button",
			className: "sm-button sm-button-small themesButton glyphButton",
			onclick: { fn: InitiateDownloadImage }
		};
		
		var dButtonObj = new YAHOO.widget.Button(downloadButtonInfo);
	}
}

function InitiateDownloadImage()
{
	// construct the download URL
	window.location = "/photos/" + ImageID + "_" + ImageKey + "-D.jpg";
}

  
