/*

  OpenLayers.js -- OpenLayers Map Viewer Library

  Copyright 2005-2008 MetaCarta, Inc., released under the Clear BSD license.
  Please see http://svn.openlayers.org/trunk/openlayers/license.txt
  for the full text of the license.

  Includes compressed code under the following licenses:

  (For uncompressed versions of the code used please see the
  OpenLayers SVN repository: <http://openlayers.org/>)

*/

/* Contains portions of Prototype.js:
 *
 * Prototype JavaScript framework, version 1.4.0
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
 *--------------------------------------------------------------------------*/

/**  
*  
*  Contains portions of Rico <http://openrico.org/>
* 
*  Copyright 2005 Sabre Airline Solutions  
*  
*  Licensed under the Apache License, Version 2.0 (the "License"); you
*  may not use this file except in compliance with the License. You
*  may obtain a copy of the License at
*  
*         http://www.apache.org/licenses/LICENSE-2.0  
*  
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
*  implied. See the License for the specific language governing
*  permissions and limitations under the License. 
*
**/

var TARGET="";if(iframe)
{TARGET="target='_blank'";}
function checkMouseInMap(e){var elem=OpenLayers.Event.element(e);var mapDiv=document.getElementById('map');while(elem!=null){if(elem==mapDiv){return true;}
elem=elem.parentNode;}
return false;}
function panZoom(lon,lat,zoom)
{var location=new OpenLayers.LonLat(lon,lat);map.panTo(location);map.zoomTo(zoom);}
function secondsToDiff(s)
{if(s<60)
{var tdif=s;var tdesc='second';}
else if(s<60*60)
{var tdif=parseInt(s/60);var tdesc='minute';}
else if(s<60*60*24)
{var tdif=parseInt(s/(60*60));var tdesc='hour';}
else if(s<60*60*24*30.5)
{var tdif=parseInt(s/(60*60*24));var tdesc='day';}
else if(s<60*60*24*365)
{var tdif=parseInt(s/(60*60*24*30.5));var tdesc='month';}
else
{var tdif=parseInt(s/(60*60*24*365));var tdesc='year';}
if(tdif==1)
return''+tdif+' '+tdesc+' ago';else
return''+tdif+' '+tdesc+'s ago';}
var months=Array('xx','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');function sqlToPrettyDate(s)
{stuff=s.split('-');if(stuff[1].substring(0,1)=="0")
stuff[1]=stuff[1].substring(1);if(stuff[2].substring(0,1)=="0")
stuff[2]=stuff[2].substring(1);rval=months[parseInt(stuff[1])]+' '+parseInt(stuff[2])+', '+stuff[0];return rval;}
function setLoc(txt)
{if(txt&&txt.length>0)
{document.getElementById("loctext").innerHTML=txt;var locdiv=document.getElementById("rightlocation");locdiv.style.visibility="visible";locdiv.style.display="block";locdiv.style.position="static";}
else
{var locdiv=document.getElementById("rightlocation");locdiv.style.display="none";locdiv.style.position="absolute";}}
function showHints()
{var hintsDiv=document.getElementById("wallhintsdiv");hintsDiv.style.visibility="visible";hintsDiv.style.display="block";document.getElementById("hintslink").style.display="none";if(metaType=="site")
{var examplesDiv=document.getElementById("rightexamples");if(examplesDiv)
{examplesDiv.style.visibility="visible";examplesDiv.style.display="block";}}}
function hideHints()
{document.getElementById("wallhintsdiv").style.display="none";if(metaType=="site")
{var x=document.getElementById("rightexamples");if(x)
x.style.display="none";}}
function EmailWall()
{document.getElementById("emailtoerror").innerHTML="";document.getElementById("emailfromerror").innerHTML="";document.getElementById("emailbodyerror").innerHTML="";var url=TOPURL+'emailWall_submit.php';var to=document.getElementById("emailTo").value;if(!ValidateToAddresses(to))
{return;}
var from=document.getElementById("emailFrom").value;if(!ValidateFromAddress(from))
{return;}
var emailBody=document.getElementById("emailBody").value;if(!ValidateEmailBody(emailBody))
{return;}
var emailButton=document.getElementById("emailsendbutton");emailButton.disabled=true;emailButton.value="Sending...";var responseObj=new OpenLayers.Ajax.Request(url,{method:'post',postBody:'to='+encodeURIComponent(to)+'&from='+encodeURIComponent(from)+'&emailBody='+encodeURIComponent(emailBody)+'&wallVersionId='+encodeURIComponent(wallVersionId),onComplete:ShareWallSuccess,onFailure:ShareWallFailure,contentType:'application/x-www-form-urlencoded'});}
function DisplayEmailError(div,errorMessage)
{document.getElementById(div).innerHTML=errorMessage;}
function ValidateToAddresses(addresses)
{if(!addresses)
{DisplayEmailError("emailtoerror"," Required");return false;}
var splitAddresses=addresses.split(",");var length=splitAddresses.length;if(splitAddresses.length>50)
{DisplayEmailError("emailtoerror"," Max: 50");return false;}
for(var i=0;i<length;i++)
{if(!ValidateEmailAddress(splitAddresses[i]))
{DisplayEmailError("emailtoerror"," Invalid");return false;}}
return true;}
function ValidateFromAddress(address)
{if(!address)
{DisplayEmailError("emailfromerror"," Required");return false;}
if(!ValidateEmailAddress(address))
{DisplayEmailError("emailfromerror"," Invalid");return false;}
return true;}
function ValidateEmailBody(body)
{if(!body)
{DisplayEmailError("emailbodyerror"," Required");return false;}
if(body.length>1024)
{DisplayEmailError("emailbodyerror"," Max Length: 1024");return false;}
return true;}
function ValidateEmailAddress(address)
{var reg=new RegExp("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b","i");return reg.test(address);}
function ShareWallSuccess(ajaxResponse)
{if(ajaxResponse.responseText=="success")
{var emailButton=document.getElementById("emailsendbutton");emailButton.value="Sent";setTimeout("EmailSendClear()",3000);}
else
{EmailSendClear();alert("Error sending e-mail: check your e-mail to see if it was sent, and if not, try again.");}}
function EmailSendClear()
{var emailButton=document.getElementById("emailsendbutton");emailButton.value="Send";emailButton.disabled=false;}
function ShareWallFailure(ajaxResponse)
{EmailSendClear();alert("Error sending e-mail: check your e-mail to see if it was sent, and if not, try again.");}
function StopEvent(evt)
{OpenLayers.Event.stop(evt?evt:window.event,true);}
var isPanning=false;function MouseUpCheckDrag(evt)
{if(!isPanning)
StopEvent(evt);}
function StopAllEvents(divIds)
{for(var i=0;i<divIds.length;i++)
{var div=document.getElementById(divIds[i]);div.onmousedown=StopEvent;div.onmouseup=MouseUpCheckDrag;div.onclick=StopEvent;div.ondblclick=StopEvent;div.onmouseover=StopEvent;div.onmouseout=StopEvent;div.onkeydown=StopEvent;div.onkeyup=StopEvent;div.onkeypress=StopEvent;}}
function LoadMetaRightPanel()
{if(metaType=="site")
{document.getElementById("walltitle").innerHTML="The MetaWall";document.getElementById("wallauthor").innerHTML="Everyone";setLoc("Everywhere");document.getElementById("rightlink").innerHTML="<a href='/'"+TARGET+">Link to this wall</a>";}
else
{document.getElementById("walltitle").innerHTML=meta.user+"'s MetaWall";document.getElementById("wallauthor").innerHTML="<a href='/"+meta.user+"' "+TARGET+">"+meta.user+"</a>";setLoc(meta.location);document.getElementById("rightlink").innerHTML="<a href='/"+meta.user+"' "+TARGET+">Link to this wall</a>";}
document.getElementById("itemdescr").innerHTML=meta.description;document.getElementById("descrcontainer").style.display="block";showHints();}
function LoadWallRightPanel(ajaxResponse)
{var data=ajaxResponse.responseText.split("'");document.getElementById("walltitle").innerHTML=data[1];document.getElementById("itemdescr").innerHTML=data[2];if(data[2].length==0)
document.getElementById("descrcontainer").style.display="none";else
document.getElementById("descrcontainer").style.display="block";setLoc(data[3]);document.getElementById("datetxt").innerHTML="Updated";document.getElementById("itemdate").innerHTML=secondsToDiff(parseInt(data[4]));document.getElementById("rightlink").innerHTML="<p style=\"margin: 12px 0px\"><a href='/"+data[5]+"/"+data[0]+"' "+TARGET+">Link to this wall</a></p>";hideHints();}
function LoadPhotoRightPanel(ajaxResponse)
{var data=ajaxResponse.responseText.split("'");setLoc(data[0]);document.getElementById("walltitle").innerHTML=data[1];if(data[2].length>0)
{document.getElementById("rightdate").style.display="block";document.getElementById("datetxt").innerHTML="Taken";document.getElementById("itemdate").innerHTML=sqlToPrettyDate(data[2]);}
else
{document.getElementById("rightdate").style.display="none";document.getElementById("datetxt").innerHTML="";document.getElementById("itemdate").innerHTML="";}
document.getElementById("rightlink").innerHTML="";hideHints();}
function flashRight()
{document.getElementById("rightbar").style.borderWidth="4px";document.getElementById("rightbar").style.borderColor="rgb(72, 206, 0)";setTimeout("endFlashRight()",500);}
function endFlashRight()
{document.getElementById("rightbar").style.borderWidth="0px 0px 1px 1px";document.getElementById("rightbar").style.borderColor="rgb(170, 170, 170) rgb(170, 170, 170) rgb(255, 255, 255)";}
function JSONscriptRequest(fullUrl){this.fullUrl=fullUrl;this.noCacheIE='&noCacheIE='+(new Date()).getTime();this.headLoc=document.getElementsByTagName("head").item(0);this.scriptId='JscriptId'+JSONscriptRequest.scriptCounter++;}
JSONscriptRequest.scriptCounter=1;JSONscriptRequest.prototype.buildScriptTag=function(){this.scriptObj=document.createElement("script");this.scriptObj.setAttribute("type","text/javascript");this.scriptObj.setAttribute("charset","utf-8");this.scriptObj.setAttribute("src",this.fullUrl);this.scriptObj.setAttribute("id",this.scriptId);}
JSONscriptRequest.prototype.removeScriptTag=function(){this.headLoc.removeChild(this.scriptObj);}
JSONscriptRequest.prototype.addScriptTag=function(){this.headLoc.appendChild(this.scriptObj);}
var WallsArray;var selectedBox=null;var downX=0;var downY=0;var lastX=0;var lastY=0;var lastTime=0;var upEvent=null;var upCenter=null;var isMoving=false;var imagesToUpdate=new Array();var Walls=new Object();function WallInfo(id,size,title,host,author,t,r,b,l)
{this.id=id;this.size=size;this.title=title;this.host=host;this.author=author;this.top=t;this.right=r;this.bottom=b;this.left=l;}
var PhotoInfoTable=new Object();function PhotoInfo(t,r,b,l,z,id,captionText)
{this.top=t;this.right=r;this.bottom=b;this.left=l;this.z=z;this.id=id;this.captionText=captionText;}
var Meta=null;function MetaInfo(user,updated,description)
{this.user=user;this.updated=updated;this.description=description;}
function CreateWallBoxes(wallArray,wallSize,width)
{var x=0;var y=map.maxExtent.top;var FIELDSPERWALL=5;WallsArray=new Array(wallArray.length/FIELDSPERWALL);metaZooms=Math.ceil(Math.log(Math.sqrt(WallsArray.length))/Math.LN2)+1;Walls.width=width;wallSize=y/(Math.pow(2,metaZooms-1)*256);Walls.wallSize=wallSize;var counter=0;var bounds;var wallBox;var wallIndex;var top;var right;var bottom;var left;for(var i=0;i<wallArray.length/FIELDSPERWALL;i++){wallIndex=i*FIELDSPERWALL;WallsArray[i]=wallArray[wallIndex];if(!(i%width)&&i)
{x=0;y-=(wallSize*256);}
left=x;top=y;x+=wallSize*256;right=x;bottom=y-(wallSize*256);Walls[wallArray[i*FIELDSPERWALL]]=new WallInfo(wallArray[wallIndex],wallArray[wallIndex+1],wallArray[wallIndex+2],wallArray[wallIndex+3],wallArray[wallIndex+4],top,right,bottom,left);}}
function CreateCaptionBoxes(wallid,captions){var index=wallid;var DATAPERIMAGE=7;var currentCaptions=PhotoInfoTable[index]=new Array(captions.length/DATAPERIMAGE);var arrayIndex=0;var scaleFactor=2;if(metaType!="none")
{scaleFactor=Walls.wallSize/(Walls[wallid].size*4);}
for(var i=0;i<captions.length;i+=DATAPERIMAGE)
{if(metaType!="none"){var caption=currentCaptions[arrayIndex]=new PhotoInfo(Walls[wallid].top-scaleFactor*captions[i+1],Walls[wallid].left+scaleFactor*(captions[i]+captions[i+2]),Walls[wallid].top-scaleFactor*(captions[i+1]+captions[i+3]),Walls[wallid].left+scaleFactor*captions[i],captions[i+4],captions[i+5],captions[i+6]);}
else
{var caption=currentCaptions[arrayIndex]=new PhotoInfo(map.maxExtent.top-scaleFactor*captions[i+1],map.maxExtent.left+scaleFactor*(captions[i]+captions[i+2]),map.maxExtent.top-scaleFactor*(captions[i+1]+captions[i+3]),map.maxExtent.left+scaleFactor*captions[i],captions[i+4],captions[i+5],captions[i+6]);}
arrayIndex++;}}
function toggleNav()
{var mapDiv=document.getElementById('map');var nav=document.getElementById('mainLeft');var toggler=document.getElementById('leftToggler');if(navOpen==1)
{nav.style.display="none";navOpen=0;mapDiv.style.width=parseInt(mapDiv.style.width)+120;toggler.innerHTML='>';}
else
{nav.style.display="inline";navOpen=1;mapDiv.style.width=parseInt(mapDiv.style.width)-120;toggler.innerHTML="<";}}
function resizeMap()
{var mapDiv=document.getElementById('map');var h=document.body.clientHeight;try{var bottomOffset=parseInt(document.getElementById('viewFooter').style.height);}catch(ex){var bottomOffset=0;}
mapDiv.style.height=h-mapDiv.offsetTop-6-bottomOffset;var rbar=document.getElementById('rightbar');rbar.style.height=h-mapDiv.offsetTop-6;}
var map;var layer;var overView;function load()
{if(noWalls)
{var mapDiv=document.getElementById('map');mapDiv.innerHTML="<p>This user has not published any public walls</p>";return;}
var maxResolution=Math.pow(2,numZoomLevels);var size=maxResolution*256;if(layer)
{map.removeLayer(layer);}
if(map)
{map.destroy();document.getElementById('map').innerHTML='';}
var options={numZoomLevels:numZoomLevels,maxResolution:maxResolution,maxExtent:new OpenLayers.Bounds(0,0,size,size),panMethod:OpenLayers.Easing.Quad.easeInOut,panSteps:15,controls:[]};map=new OpenLayers.Map('map',options);var layerOptions={layername:wallVersionId,type:'jpg'};var urls=['http://'+servername1+'/tile.php/','http://'+servername2+'/tile.php/','http://'+servername3+'/tile.php/','http://'+servername4+'/tile.php/'];layer=new OpenLayers.Layer.TMS("Scrap Walls",urls,layerOptions);map.addControl(new OpenLayers.Control.PanZoomBar());map.addControl(new OpenLayers.Control.Permalink());map.addControl(new OpenLayers.Control.KeyboardDefaults());map.addControl(new OpenLayers.Control.MouseDefaults());map.addLayer(layer);if(!map.getCenter()){var squarew=Math.ceil(Math.sqrt(smarty_numWalls));var expsquarew=Math.pow(2,Math.ceil(Math.log(Math.sqrt(smarty_numWalls))/Math.LN2));var diffw=expsquarew-squarew;var lonlatw=map.maxExtent.right;var lonlath=map.maxExtent.top;var ll=new OpenLayers.LonLat(((expsquarew-diffw)/expsquarew)*lonlatw/2,lonlath-((expsquarew-diffw)/expsquarew)*lonlath/2)
map.setCenter(ll);map.zoomTo(zoomStart);map.pan(0,0);}
map.div.style.cursor="url(/script/view/img/openhand.cur), default";StopAllEvents(["sharediv","senddiv","linkMenu","emailMenu","rightbar","header","emailTo","emailFrom","emailBody","PermalinkShareUrl","iframeHtml"]);photoBoxes=new OpenLayers.Layer.Boxes("photoBoxes");photoBoxes.setVisibility(true);map.addLayer(photoBoxes);document.getElementById("itemdate").innerHTML=secondsToDiff(updated);if(metaType=="site")
{var scriptTag=new JSONscriptRequest(TOPURL+"getSiteMetaInfo.php");scriptTag.buildScriptTag();scriptTag.addScriptTag();meta=new MetaInfo("Everyone",secondsToDiff(updated),"This is a collection of ScrapWalls from our amazing users!");}
else if(metaType=="user")
{var scriptTag=new JSONscriptRequest(TOPURL+"getUserMetaInfo.php?id="+layer.layername);scriptTag.buildScriptTag();scriptTag.addScriptTag();meta=new MetaInfo(wallUserName,secondsToDiff(updated),"Here are all of "+wallUserName+"'s ScrapWalls");}
else
{Walls[layer.layername]=new WallInfo(layer.layername,null,null,null,wallUserName,map.maxExtent.top,map.maxExtent.right,map.maxExtent.bottom,map.maxExtent.left);var scriptTag=new JSONscriptRequest(TOPURL+"getCaptions.php?id="+layer.layername);scriptTag.buildScriptTag();scriptTag.addScriptTag();}
var popupSel=new OpenLayers.Popup.FramedCloud("selectionpopup",new OpenLayers.LonLat(0,0),new OpenLayers.Size(200,200),"initial text",null,false,null,"caption-dark-");popupSel.autoSize=true;var popup=new OpenLayers.Popup.FramedCloud("hoverpopup",new OpenLayers.LonLat(0,0),new OpenLayers.Size(200,200),"initial text",null,false,null,"caption-");popup.autoSize=true;map.addPopup(popupSel);popupSel.hide();map.addPopup(popup);popup.hide();selectionBox=new OpenLayers.Marker.Box(new OpenLayers.Bounds(),null,null,"",TOPURL+"img/");selectionBox.div.style.border="none";selectionBox.events.fallThrough=true;photoBoxes.addMarker(selectionBox);hoverBox=new OpenLayers.Marker.Box(new OpenLayers.Bounds(),null,null,"light-",TOPURL+"img/");hoverBox.div.style.border="none";hoverBox.events.fallThrough=true;photoBoxes.addMarker(hoverBox);map.events.fallThrough=true;var moveTimeout=null;var moveSetAt=0;function startMove()
{isMoving=true;};var doRecenter=false;function endMove(restart)
{isMoving=false;loadBackedUpImages();}
function loadBackedUpImages()
{for(var i=0;i<imagesToUpdate.length;i++)
{imagesToUpdate[i][0].src=imagesToUpdate[i][1];}
imagesToUpdate=new Array();};map.events.register("movestart",map,function(e){isPanning=true;startMove();moveSetAt=1;});map.events.register("moveend",map,function(e){isPanning=false;if(doRecenter)
doRecenter=false;else
doRecenter=true;endMove();doRecenter=false;doMouseMove(lastMouseCX,lastMouseCY);});map.events.register("zoomend",map,function(e){if(showingPopupSel)
{showPopup(popupSel,curPopupText,curPopupL,curPopupR,curPopupB);}});map.events.register("mousedown",map,function(e){if(!checkMouseInMap(e))
return;startMove();moveSetAt=3;downX=e.clientX;downY=e.clientY;if(document.all)
{downX-=2;downY-=2;}
map.div.style.cursor="url("+TOPURL+"script/view/img/closedhand.cur), default";});var currentCaptionId=null;var currentWallId=null;map.events.register("mouseup",map,function(e){if(!checkMouseInMap(e))
return;var cx=e.clientX;var cy=e.clientY;isMapDragging=false;curTime=new Date().getTime();map.div.style.cursor="url(/script/view/img/openhand.cur), default";if(upEvent&&(lastTime+500)>curTime&&Math.abs(lastX-cx)<8&&Math.abs(lastY-cy)<8)
{map.setCenter(upCenter,map.zoom+1);map.events.triggerEvent("mousemove",upEvent);lastTime=0;upEvent=null;}
else
{upEvent=e;lastTime=curTime;lastX=cx;lastY=cy;upCenter=map.getLonLatFromViewPortPx(upEvent.xy);doMouseUp(cx,cy,downX,downY,true);}});var curPopupText;var curPopupL;var curPopupR;var curPopupB;var showingPopupSel=false;function showPopup(p,text,l,r,b)
{curPopupText=text;curPopupL=l;curPopupR=r;curPopupB=b;p.setContentHTML('<div align="center">'+text+"<//div>");p.show();var lonlat=new OpenLayers.LonLat((l+r)/2,b);var px=p.map.getLayerPxFromLonLat(lonlat);px.x-=44;px.x+=p.size.w/2;px.y+=10;p.moveTo(px);}
function doMouseUp(cx,cy,evx,evy,realevent)
{if(document.all)
{cx-=2;cy-=2;}
if(Math.abs(evx-cx)<8&&Math.abs(evy-cy)<8)
{var lonLat=map.getLonLatFromViewPortPx(new OpenLayers.Pixel(cx-map.div.offsetLeft,cy-map.div.offsetTop));var panLonLat=map.getLonLatFromViewPortPx(new OpenLayers.Pixel(cx-map.div.offsetLeft,cy-map.div.offsetTop));var actualWallId=GetSelectedWallId(lonLat);var left,right,top,bottom;if(actualWallId==-1)
{selectionBox.display(false);popupSel.hide();showingPopupSel=false;LoadMetaRightPanel();return;}
var bounds=new OpenLayers.Bounds();var selectWall=true;if(metaType=="none"||map.zoom>=metaZooms)
{var selectedCaptionId=GetSelectedPhotoId(actualWallId,lonLat);if(selectedCaptionId!=-1)
{var wallCaptions=PhotoInfoTable[actualWallId];var currentCaption=wallCaptions[selectedCaptionId];currentCaptionId=selectedCaptionId;left=currentCaption.left;right=currentCaption.right;top=currentCaption.top;bottom=currentCaption.bottom;document.getElementById("itemdescr").innerHTML=currentCaption.captionText;if(currentCaption.captionText.length==0)
document.getElementById("descrcontainer").style.display="none";else
document.getElementById("descrcontainer").style.display="block";document.getElementById("wallauthor").innerHTML="<a href='/"+Walls[actualWallId].author+"' "+TARGET+">"+Walls[actualWallId].author+"</a>";OpenLayers.loadURL(TOPURL+"getSinglePhotoInfo?id="+currentCaption.id,'',this,LoadPhotoRightPanel);selectionBox.isWall=false;selectWall=false;if(currentCaption.captionText){showPopup(popupSel,currentCaption.captionText,left,right,bottom);showingPopupSel=true;}
else
{popupSel.hide();showingPopupSel=false;}
currentWallId=null;}
else
{selectionBox.display(false);popupSel.hide();showingPopupSel=false;selectWall=true;currentCaptionId=null;}}
if(selectWall)
{var width=Walls.width;var actualWall=Walls[actualWallId];left=actualWall.left;right=actualWall.right;top=actualWall.top;bottom=actualWall.bottom;document.getElementById("wallauthor").innerHTML="<a href='/"+Walls[actualWallId].author+"' "+TARGET+">"+Walls[actualWallId].author+"</a>";OpenLayers.loadURL(TOPURL+"getSingleWallInfo?id="+actualWallId,'',this,LoadWallRightPanel);selectionBox.isWall=true;if(actualWall.title)
{showPopup(popupSel,actualWall.title,left,right,bottom);showingPopupSel=true;}
else
{popupSel.hide();showingPopupSel=false;}
currentWallId=actualWallId;}
bounds.extend(new OpenLayers.LonLat(left,top));bounds.extend(new OpenLayers.LonLat(right,bottom));selectionBox.bounds=bounds;photoBoxes.drawMarker(selectionBox);selectionBox.display(true);if(realevent)
map.panTo(panLonLat);}
else
{if(realevent)
{if(moveTimeout!=null)
{clearTimeout(moveTimeout);endMove();}
else
isMoving=false;}}}
var lastMouseCX=0;var lastMouseCY=0;var lastMouseLonLat=null;function doMouseMove(cx,cy)
{lastMouseCX=cx;lastMouseCY=cy;var lonLat=map.getLonLatFromViewPortPx(new OpenLayers.Pixel(cx-map.div.offsetLeft,cy-map.div.offsetTop));lastMouseLonLat=lonLat;if(isMoving)
{if(moveTimeout!=null)
clearTimeout(moveTimeout);moveTimeout=setTimeout(function(){isMoving=false;loadBackedUpImages();moveTimeout=null;if(isPanning)
{isMoving=true;moveSetAt=4;}},20);return false;}
else
{if(document.all)
{cx-=2;cy-=2;}
var actualWallId=GetSelectedWallId(lonLat);if(actualWallId==-1)
{popup.hide();hoverBox.display(false);map.div.style.cursor="url(http://www.scrapwalls.com/script/view/img/openhand.cur), default";return;}
var selectedCaptionId;if((metaType=="none"||map.zoom>=metaZooms))
{var selectedCaptionId=GetSelectedPhotoId(actualWallId,lonLat);if(selectedCaptionId!=-1)
{var bounds=new OpenLayers.Bounds();var wallCaptions=PhotoInfoTable[actualWallId];var currentCaption=wallCaptions[selectedCaptionId];bounds.extend(new OpenLayers.LonLat(currentCaption.left,currentCaption.top));bounds.extend(new OpenLayers.LonLat(currentCaption.right,currentCaption.bottom));hoverBox.bounds=bounds;map.div.style.cursor="pointer";hoverBox.isWall=false;if(currentCaptionId==selectedCaptionId)
{hoverBox.display(false);popup.hide();}
else
{photoBoxes.drawMarker(hoverBox);hoverBox.display(true);}
if(currentCaption.captionText){popup.setContentHTML('<div align="center">'+currentCaption.captionText+"<//div>");popup.show();var lonlat=new OpenLayers.LonLat((currentCaption.left+currentCaption.right)/2,currentCaption.bottom);var px=popup.map.getLayerPxFromLonLat(lonlat);px.x-=44;px.x+=popup.size.w/2;px.y+=10;popup.moveTo(px);}}
else
{map.div.style.cursor="url(/script/view/img/openhand.cur), default";hoverBox.display(false);popup.hide();}}
else
{var width=Walls.width;var actualWall=Walls[actualWallId];var bounds=new OpenLayers.Bounds();var left=actualWall.left;var right=actualWall.right;var top=actualWall.top;var bottom=actualWall.bottom;bounds.extend(new OpenLayers.LonLat(left,top));bounds.extend(new OpenLayers.LonLat(right,bottom));hoverBox.bounds=bounds;map.div.style.cursor="pointer";hoverBox.isWall=true;if(actualWallId==currentWallId)
{hoverBox.display(false);popup.hide();}
else
{photoBoxes.drawMarker(hoverBox);hoverBox.display(true);if(actualWall.title)
{popup.setContentHTML('<div align="center">'+actualWall.title+"<//div>");popup.show();var lonlat=new OpenLayers.LonLat((left+right)/2,bottom);var px=popup.map.getLayerPxFromLonLat(lonlat);px.x-=44;px.x+=popup.size.w/2;px.y+=10;popup.moveTo(px);}}}}}
map.events.register("mousemove",map,function(e){if(!isPanning&&!checkMouseInMap(e))
return;var cx=e.clientX;var cy=e.clientY;doMouseMove(cx,cy);});function GetSelectedWallId(lonLat)
{if(metaType!="none")
{if(!WallsArray)
{return-1;}
var origwidth=Walls.width;var logw=Math.ceil(Math.log(origwidth)/Math.LN2);var width=Math.pow(2,logw);x=Math.floor((lonLat.lon/map.maxExtent.right)*width);var wallPositionX=x;y=Math.ceil((lonLat.lat/map.maxExtent.top)*width);var wallPositionY=width-y;if(wallPositionX<0||wallPositionY<0||wallPositionX>=origwidth||wallPositionY>=origwidth)
{return-1;}
var index=wallPositionY*origwidth+wallPositionX;if(index>=WallsArray.length)
{return-1;}
return WallsArray[index];}
else
{return layer.layername;}}
function GetSelectedPhotoId(actualWallId,lonLat)
{var wallCaptions=PhotoInfoTable[actualWallId];if(!wallCaptions)
{return-1;}
var captionsLength=wallCaptions.length;var selectedCaptionId=-1;var selectedZ=-1;var currentCaption;for(var i=0;i<captionsLength;i++)
{currentCaption=wallCaptions[i];if(currentCaption.left<lonLat.lon&&currentCaption.right>lonLat.lon&&currentCaption.bottom<lonLat.lat&&currentCaption.top>lonLat.lat&&currentCaption.z>selectedZ)
{selectedCaptionId=i;selectedZ=currentCaption.z;}}
return selectedCaptionId;}}
function showEmailBox()
{document.getElementById('emailMenu').style.display='';document.getElementById('emailTo').focus();var ebdiv=document.getElementById('emailBody');ebdiv.style.color='#000000';ebdiv.value="Hello, I would like to share a ScrapWalls.com photo collage with you. \r\n\r\nLink: <"+document.getElementById('PermalinkShareUrl').value+">";}
function hideEmailBox()
{document.getElementById('emailMenu').style.display='none';}
function showShareBox()
{document.getElementById('linkMenu').style.display='';document.getElementById('PermalinkShareUrl').focus();document.getElementById('PermalinkShareUrl').select();}
function hideShareBox()
{document.getElementById('linkMenu').style.display='none';}
function emailBodySelect(e)
{}